Re: [PATCH net-next v12 12/13] net: ethtool: tsinfo: Add support for hwtstamp provider and get/set hwtstamp config

From: Kory Maincent
Date: Fri May 17 2024 - 11:21:35 EST


On Sat, 4 May 2024 11:33:05 +0100
Simon Horman <horms@xxxxxxxxxx> wrote:

> Hi Kory,
>
> A few lines beyond this hunk, within the "if (hwtstamp)" block,
> is the following:
>
> cfg->qualifier = dev->hwtstamp->qualifier;
>
> Now that dev->hwtstamp is managed using RCU, I don't think it is correct
> to dereference it directly like this. Rather, the hwtstamp local variable,
> which has rcu_dereference'd this pointer should be used:
>
> cfg->qualifier = hwtstamp->qualifier;
>
> Flagged by Sparse.

Yes indeed, thanks for the report.

>
> ...
>
> > diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
>
> ...
>
> > +static int ethnl_tsinfo_dump_one_dev(struct sk_buff *skb, struct
> > net_device *dev,
> > + struct netlink_callback *cb)
> > +{
> > + struct ethnl_tsinfo_dump_ctx *ctx = (void *)cb->ctx;
> > + struct ptp_clock *ptp;
> > + int ret;
> > +
> > + netdev_for_each_ptp_clock_start(dev, ctx->pos_phcindex, ptp,
> > + ctx->pos_phcindex) {
> > + ret = ethnl_tsinfo_dump_one_ptp(skb, dev, cb, ptp);
> > + if (ret < 0 && ret != -EOPNOTSUPP)
> > + break;
> > + ctx->pos_phcqualifier =
> > HWTSTAMP_PROVIDER_QUALIFIER_PRECISE;
> > + }
> > +
> > + return ret;
>
> Perhaps it is not possible, but if the loop iterates zero times then
> ret will be used uninitialised here.

Yes thanks!

Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com