Re: kernel BUG at net/core/net-sysfs.c:LINE!

From: wanghai (M)
Date: Mon Mar 25 2019 - 11:20:35 EST


thanks , Can it be fixed like this?

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 4ff661f..e609c8d 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -1745,16 +1745,21 @@ int netdev_register_kobject(struct net_device *ndev)

ÂÂÂÂÂÂÂ error = device_add(dev);
ÂÂÂÂÂÂÂ if (error)
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return error;
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto error_put_device;

ÂÂÂÂÂÂÂ error = register_queue_kobjects(ndev);
-ÂÂÂÂÂÂ if (error) {
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ device_del(dev);
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return error;
-ÂÂÂÂÂÂ }
+ÂÂÂÂÂÂ if (error)
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto error_device_del;

ÂÂÂÂÂÂÂ pm_runtime_set_memalloc_noio(dev, true);

+ÂÂÂÂÂÂ return 0;
+
+error_device_del:
+ÂÂÂÂÂÂ device_del(dev);
+error_put_device:
+ÂÂÂÂÂÂ ndev->reg_state = NETREG_RELEASED;
+ÂÂÂÂÂÂ put_device(dev);
ÂÂÂÂÂÂÂ return error;
Â}

å 2019/3/24 1:16, Andy Shevchenko åé:
Nice.

I looked briefly in the flow of this report and it looks like the patch above
should be reverted.

The problem is not so easy to fix. One approach is to initialize device
(and thus kobject) somewhere in alloc_netdev() and put device in free_netdev()
respectively, but this might produce more interesting regressions.