WSL2-Linux-Kernel/drivers/net/dsa
Chen Zhongjin 9f555b1584 net: dsa: Fix possible memory leaks in dsa_loop_init()
[ Upstream commit 633efc8b3d ]

kmemleak reported memory leaks in dsa_loop_init():

kmemleak: 12 new suspected memory leaks

unreferenced object 0xffff8880138ce000 (size 2048):
  comm "modprobe", pid 390, jiffies 4295040478 (age 238.976s)
  backtrace:
    [<000000006a94f1d5>] kmalloc_trace+0x26/0x60
    [<00000000a9c44622>] phy_device_create+0x5d/0x970
    [<00000000d0ee2afc>] get_phy_device+0xf3/0x2b0
    [<00000000dca0c71f>] __fixed_phy_register.part.0+0x92/0x4e0
    [<000000008a834798>] fixed_phy_register+0x84/0xb0
    [<0000000055223fcb>] dsa_loop_init+0xa9/0x116 [dsa_loop]
    ...

There are two reasons for memleak in dsa_loop_init().

First, fixed_phy_register() create and register phy_device:

fixed_phy_register()
  get_phy_device()
    phy_device_create() # freed by phy_device_free()
  phy_device_register() # freed by phy_device_remove()

But fixed_phy_unregister() only calls phy_device_remove().
So the memory allocated in phy_device_create() is leaked.

Second, when mdio_driver_register() fail in dsa_loop_init(),
it just returns and there is no cleanup for phydevs.

Fix the problems by catching the error of mdio_driver_register()
in dsa_loop_init(), then calling both fixed_phy_unregister() and
phy_device_free() to release phydevs.
Also add a function for phydevs cleanup to avoid duplacate.

Fixes: 98cd1552ea ("net: dsa: Mock-up driver")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-11-10 18:15:27 +01:00
..
b53
hirschmann net/dsa/hirschmann: Add missing of_node_get() in hellcreek_led_setup() 2022-07-07 17:53:27 +02:00
microchip net: dsa: microchip: ksz9477: fix fdb_dump last invalid entry 2022-08-25 11:40:24 +02:00
mv88e6xxx net: dsa: mv88e6xxx: use BMSR_ANEGCOMPLETE bit for filling an_complete 2022-06-14 18:36:19 +02:00
ocelot net: dsa: felix: fix ethtool 256-511 and 512-1023 TX packet counters 2022-08-25 11:40:25 +02:00
qca
sja1105 net: dsa: sja1105: fix buffer overflow in sja1105_setup_devlink_regions() 2022-08-25 11:40:25 +02:00
xrs700x net: dsa: xrs700x: Use irqsave variant for u64 stats update 2022-09-08 12:28:02 +02:00
Kconfig net: dsa: restrict SMSC_LAN9303_I2C kconfig 2022-06-09 10:23:03 +02:00
Makefile
bcm_sf2.c net: dsa: bcm_sf2: force pause link settings 2022-07-07 17:53:25 +02:00
bcm_sf2.h
bcm_sf2_cfp.c
bcm_sf2_regs.h
dsa_loop.c net: dsa: Fix possible memory leaks in dsa_loop_init() 2022-11-10 18:15:27 +01:00
dsa_loop.h
dsa_loop_bdinfo.c
lan9303-core.c
lan9303.h
lan9303_i2c.c
lan9303_mdio.c
lantiq_gswip.c net: dsa: lantiq_gswip: Fix refcount leak in gswip_gphy_fw_list 2022-06-14 18:36:17 +02:00
lantiq_pce.h
mt7530.c net: mt7531: only do PLL once after the reset 2022-10-05 10:39:38 +02:00
mt7530.h
mv88e6060.c net: dsa: mv88e6060: prevent crash on an unused port 2022-08-25 11:40:23 +02:00
mv88e6060.h
qca8k.c net: dsa: qca8k: reset cpu port on MTU change 2022-07-12 16:35:10 +02:00
qca8k.h
realtek-smi-core.c
realtek-smi-core.h
rtl8366.c
rtl8366rb.c
vitesse-vsc73xx-core.c
vitesse-vsc73xx-platform.c
vitesse-vsc73xx-spi.c net: dsa: vitesse-vsc73xx: silent spi_device_id warnings 2022-07-29 17:25:21 +02:00
vitesse-vsc73xx.h