net: free_netdev: exit earlier if dummy
Subsystems (3)
PATCH 1/1 net: free_netdev: exit earlier if dummy
From: Breno Leitao <[email protected]>
For dummy devices, exit earlier at free_netdev() instead of executing the whole function. This is necessary, because dummy devices are special, and shouldn't have the second part of the function executed.
Otherwise reg_state, which is NETREG_DUMMY, will be overwritten and there will be no way to identify that this is a dummy device. Also, this device do not need the final put_device(), since dummy devices are not registered (through register_netdevice()), where the device reference is increased (at netdev_register_kobject()/device_add()).
--- net/core/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/dev.c +2 -1
@@ -11093,7 +11093,8 @@ void free_netdev(struct net_device *dev) dev->xdp_bulkq =NULL ;/* Compatibility with error handling in drivers */ -if (dev->reg_state ==NETREG_UNINITIALIZED ) { +if (dev->reg_state ==NETREG_UNINITIALIZED || + dev->reg_state ==NETREG_DUMMY ) {netdev_freemem (dev);return ; }
Signature · 1 line
2.43.7
On 2026-11-08 00:14:15, Dust Li wrote:
Hi Greg, Sasha
Can you pick up this patch for 6.6 ?
This is a prerequisite that was missed when 6.6.y picked up the dummy-net_device conversion of the mediatek driver.
6.6.158 took b209bd6d0bff ("net: mediatek: mtk_eth_sock: allocate dummy net_device dynamically") as d5d57501f543, followed by 16f3a28cf5f8 (as 81e82340170ae) and "allocate dummy netdev sooner" (efc91ab1d97bd).
alloc_netdev_dummy() -> init_dummy_netdev_core() sets dev->reg_state = NETREG_DUMMY, but 6.6.y free_netdev() only special cases NETREG_UNREGISTERING and NETREG_UNINITIALIZED. So every free_netdev(eth->dummy_dev) -- mtk_remove() at drivers/net/ethernet/mediatek/mtk_eth_soc.c and the probe error path -- walks into
BUG_ON(dev->reg_state != NETREG_UNREGISTERED);
Upstream f8d05679fb3f and b209bd6d0bff both landed in v6.10-rc1, so mainline was never broken.
5.10.y / 5.15.y / 6.1.y - alloc_netdev_dummy() does not exist and no
driver creates a dynamically allocated dummy net_device
So only 6.6.y need this.
Best regards,
Dust
Quoted 37 lines
From: Breno Leitao <[email protected]>
For dummy devices, exit earlier at
free_netdev()instead of executing the whole function. This is necessary, because dummy devices are special, and shouldn't have the second part of the function executed.Otherwise
reg_state, which isNETREG_DUMMY, will be overwritten and there will be no way to identify that this is a dummy device. Also, this device do not need the finalput_device(), since dummy devices are not registered (throughregister_netdevice()), where the device reference is increased (at netdev_register_kobject()/device_add()).Suggested-by Jakub Kicinski <[email protected]>Signed-off-by Breno Leitao <[email protected]>Reviewed-by Ido Schimmel <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Dust Li <[email protected]>---
net/core/dev.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/core/dev.c +2
-1@@ -11093,7 +11093,8 @@ void free_netdev(struct net_device *dev) dev->xdp_bulkq =NULL ;/* Compatibility with error handling in drivers */ -if (dev->reg_state ==NETREG_UNINITIALIZED ) { +if (dev->reg_state ==NETREG_UNINITIALIZED || + dev->reg_state ==NETREG_DUMMY ) {netdev_freemem (dev);return ; }Signature · 1 line
2.43.7
Greg Kroah-Hartman
maintainerQuoted 22 lines · Dust Li
On 2026-11-08 00:14:15, Dust Li wrote:
Hi Greg, Sasha
Can you pick up this patch for 6.6 ?
This is a prerequisite that was missed when 6.6.y picked up the dummy-net_device conversion of the mediatek driver.
6.6.158 took
b209bd6d0bff("net: mediatek:mtk_eth_sock: allocate dummynet_devicedynamically") asd5d57501f543, followed by16f3a28cf5f8(as81e82340170ae) and "allocate dummy netdev sooner" (efc91ab1d97bd).
alloc_netdev_dummy()->init_dummy_netdev_core()setsdev->reg_state=NETREG_DUMMY, but 6.6.yfree_netdev()only special casesNETREG_UNREGISTERINGandNETREG_UNINITIALIZED. So everyfree_netdev(eth->dummy_dev)--mtk_remove()atdrivers/net/ethernet/mediatek/mtk_eth_soc.cand the probe error path -- walks intoBUG_ON(dev->reg_state != NETREG_UNREGISTERED);
Quoted 8 lines
Upstream
f8d05679fb3fandb209bd6d0bffboth landed in v6.10-rc1, so mainline was never broken.5.10.y / 5.15.y / 6.1.y -
alloc_netdev_dummy()does not exist and no
driver creates a dynamically allocated dummynet_deviceSo only 6.6.y need this.
But what commit id is "this"?
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 12 lines · Dust Li
From: Breno Leitao <[email protected]>
For dummy devices, exit earlier at
free_netdev()instead of executing the whole function. This is necessary, because dummy devices are special, and shouldn't have the second part of the function executed.Otherwise
reg_state, which isNETREG_DUMMY, will be overwritten and there will be no way to identify that this is a dummy device. Also, this device do not need the finalput_device(), since dummy devices are not registered (throughregister_netdevice()), where the device reference is increased (at netdev_register_kobject()/device_add()).
Quoted 8 lines
Suggested-by Jakub Kicinski <[email protected]>Signed-off-by Breno Leitao <[email protected]>Reviewed-by Ido Schimmel <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Dust Li <[email protected]>--- net/core/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
Quoted 23 lines · Greg Kroah-Hartman
Quoted 12 lines · Dust Li
From: Breno Leitao <[email protected]>
For dummy devices, exit earlier at
free_netdev()instead of executing the whole function. This is necessary, because dummy devices are special, and shouldn't have the second part of the function executed.Otherwise
reg_state, which isNETREG_DUMMY, will be overwritten and there will be no way to identify that this is a dummy device. Also, this device do not need the finalput_device(), since dummy devices are not registered (throughregister_netdevice()), where the device reference is increased (at netdev_register_kobject()/device_add()).Quoted 8 lines
Suggested-by Jakub Kicinski <[email protected]>Signed-off-by Breno Leitao <[email protected]>Reviewed-by Ido Schimmel <[email protected]>Signed-off-by David S. Miller <[email protected]>Signed-off-by Dust Li <[email protected]>--- net/core/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 8 lines
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.</formletter>
Hi Greg,
Sorry, I missed the upstream commit id in the commit message.
I'll pay more attention on that next time.
BTW I notice Sasha had already picked it and added the corrent id, thanks Sasha !
Best regards,
Dust