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

From
Kory Maincent <kory.maincent@bootlin.com>
Date
2024-05-17 15:21:19
Also in
linux-doc, lkml
Reply to
Simon Horman, 2024-05-04
On Sat, 4 May 2024 11:33:05 +0100
Simon Horman [off-list ref] 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.
...
quoted
diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c  
...
quoted
+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
Thread (21 messages) 21 messages, 3 authors, last reply 2024-05-17
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help