mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 6.6.y] net: free_netdev: exit earlier if dummy
@ 2026-11-07 16:14 Dust Li
  2026-11-10  6:36 ` Dust Li
  0 siblings, 1 reply; 2+ messages in thread
From: Dust Li @ 2026-11-07 16:14 UTC (permalink / raw)
  To: stable
  Cc: Breno Leitao, Greg Kroah-Hartman, Sasha Levin, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

From: Breno Leitao <leitao@debian.org>

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()).

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Dust Li <dust.li@linux.alibaba.com>
---
 net/core/dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index f9436563a2e84..0d88d285c713f 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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;
 	}
-- 
2.43.7


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 6.6.y] net: free_netdev: exit earlier if dummy
  2026-11-07 16:14 [PATCH 6.6.y] net: free_netdev: exit earlier if dummy Dust Li
@ 2026-11-10  6:36 ` Dust Li
  0 siblings, 0 replies; 2+ messages in thread
From: Dust Li @ 2026-11-10  6:36 UTC (permalink / raw)
  To: stable
  Cc: Breno Leitao, Greg Kroah-Hartman, Sasha Levin, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel

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


>From: Breno Leitao <leitao@debian.org>
>
>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()).
>
>Suggested-by: Jakub Kicinski <kuba@kernel.org>
>Signed-off-by: Breno Leitao <leitao@debian.org>
>Reviewed-by: Ido Schimmel <idosch@nvidia.com>
>Signed-off-by: David S. Miller <davem@davemloft.net>
>Signed-off-by: Dust Li <dust.li@linux.alibaba.com>
>---
> net/core/dev.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/net/core/dev.c b/net/core/dev.c
>index f9436563a2e84..0d88d285c713f 100644
>--- a/net/core/dev.c
>+++ b/net/core/dev.c
>@@ -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;
> 	}
>-- 
>2.43.7

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-10  6:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 16:14 [PATCH 6.6.y] net: free_netdev: exit earlier if dummy Dust Li
2026-11-10  6:36 ` Dust Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®