[PATCH] net: devres: fix SET_NETDEV_DEV to devm_alloc_etherdev_mqs

DORMANTno replies

From: Ozgur Kara <hidden>
Date: 2025-05-16 00:45:30
Also in: lkml
Subsystem: networking [general], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

From: Ozgur Karatas <redacted>

Hello,
I read netdevice.h file and here when netdevice is allocated with
devm_alloc_etherdev_mqs() but this device is not set with
SET_NETDEV_DEV() and i think devm_register_netdev() is probably
crashing during device removal.

I guess ensuring ndev->dev.parent get devres_add(ndev->dev.parent, dr)
is loaded correctly and unregister_netdev() or free_netdev() will not
break anymore.

So if SET_NETDEV_DEV() is not present I guess ndev->dev.parent is a
null argument and devm_register_netdev() may bind resources to null
instead of dev.

This can be fixed by explicitly calling SET_NETDEV_DEV() immediately
after allocation.

Regards

Reported-by: Ozgur Karatas <redacted>
---
 net/devres.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/net/devres.c b/net/devres.c
index 5ccf6ca311dc..a9ff607b916f 100644
--- a/net/devres.c
+++ b/net/devres.c
@@ -33,6 +33,7 @@ struct net_device *devm_alloc_etherdev_mqs(struct
device *dev, int sizeof_priv,
                return NULL;
        }

+       SET_NETDEV_DEV(dr->ndev, dev);
        devres_add(dev, dr);

        return dr->ndev;
--
2.39.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help