[PATCH] net: devres: fix SET_NETDEV_DEV to devm_alloc_etherdev_mqs

Ozgur Kara posted 1 patch 7 months, 1 week ago
net/devres.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] net: devres: fix SET_NETDEV_DEV to devm_alloc_etherdev_mqs
Posted by Ozgur Kara 7 months, 1 week ago
From: Ozgur Karatas <ozgur@goosey.org>

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 <ozgur@goosey.org>
---
 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