Skip to contentSkip to conversation

net: ethtool: phy: Clear the netdev context pointer for DUMP requests

PATCH In review Maxime Chevallier 2 participants 3 messages Sep 11, 2024 – Sep 13, 2024

Subsystems (4)
lore
Share & tools
lore

Maxime Chevallier

author maintainer
#0 lore raw

PATCH 1/1 net: ethtool: phy: Clear the netdev context pointer for DUMP requests

The context info allows continuing DUMP requests, shall they fill the netlink buffer. When performing unfiltered dump request, clear the dev pointer in the context at the end of the dump, avoiding the release of the netdevice. In the case of a filtered DUMP, the refcount for the netdev was held when parsing the header, and is released in the .done() callback.

Reported-by [email protected]
Fixes 17194be4c8e1 ("net: ethtool: Introduce a command to list PHYs on an interface")
---
 net/ethtool/phy.c | 5 +++++
 1 file changed, 5 insertions(+)
net/ethtool/phy.c +5 -0
index 560dd039c662..99d2a8b6144c 100644
@@ -301,6 +301,11 @@ int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
 
 			ctx->phy_index = 0;
 		}
+
+		/* Clear the context netdev pointer so avoid a netdev_put from
+		 * the .done() callback
+		 */
+		ctx->phy_req_info->base.dev = NULL;
 	}
 	rtnl_unlock();
 
Signature · 1 line
2.46.0
maintainer
#1 lore raw

net/ethtool/phy.c int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 308

Quoted 4 lines · On Wed, 11 Sep 2024 15:46:21 +0200 Maxime Chevallier wrote:
net/ethtool/phy.c +4 -0
+		/* Clear the context netdev pointer so avoid a netdev_put from
+		 * the .done() callback
+		 */
+		ctx->phy_req_info->base.dev = NULL;

Why do we assign to req_base.dev in the first place? req is for the parsed request in my mind, and I don't see anything in the PHY dump handlers actually using dev?

author maintainer
#2 lore raw

Hello Jakub,

Quoted 9 lines · On Thu, 12 Sep 2024 20:44:38 -0700 Jakub Kicinski <[email protected]> wrote:

net/ethtool/phy.c int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb) · line 308

Quoted 4 lines · On Wed, 11 Sep 2024 15:46:21 +0200 Maxime Chevallier wrote:
net/ethtool/phy.c +4 -0
+		/* Clear the context netdev pointer so avoid a netdev_put from
+		 * the .done() callback
+		 */
+		ctx->phy_req_info->base.dev = NULL;  

Why do we assign to req_base.dev in the first place? req is for the parsed request in my mind, and I don't see anything in the PHY dump handlers actually using dev?

After reading the code back, that's true. It's just a leftover from when I hadn't considered that dumps could be interrupted/resumed.

Let me clean that up then.

Thanks for the review Jakub,

Maxime