linux/drivers/net/dsa
Chen Zhongjin 633efc8b3d net: dsa: Fix possible memory leaks in dsa_loop_init()
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>
2022-10-28 10:32:59 +01:00
..
b53 net: dsa: b53: remove unnecessary set_drvdata() 2022-09-22 19:30:34 -07:00
hirschmann net: dsa: hellcreek: Offload per-tc max SDU from tc-taprio 2022-09-29 18:52:06 -07:00
microchip * 'remove' callback converted to return void. Big change with trivial 2022-10-04 18:54:33 -07:00
mv88e6xxx net: dsa: mv88e6xxx: remove unnecessary dev_set_drvdata() 2022-09-22 19:30:37 -07:00
ocelot net: dsa: felix: offload per-tc max SDU from tc-taprio 2022-09-29 18:52:05 -07:00
qca net: dsa: qca8k: fix ethtool autocast mib for big-endian systems 2022-10-14 08:22:28 +01:00
realtek net: dsa: realtek: remove unnecessary set_drvdata() 2022-09-22 19:30:39 -07:00
sja1105 net: dsa: sja1105: remove unnecessary spi_set_drvdata() 2022-09-22 19:30:39 -07:00
xrs700x * 'remove' callback converted to return void. Big change with trivial 2022-10-04 18:54:33 -07:00
bcm_sf2_cfp.c net: dsa: introduce dsa_port_get_master() 2022-09-20 10:32:35 +02:00
bcm_sf2_regs.h net: dsa: bcm_sf2: refactor LED regs access 2021-12-30 17:28:32 -08:00
bcm_sf2.c net: dsa: bcm_sf2: remove unnecessary platform_set_drvdata() 2022-09-22 19:30:35 -07:00
bcm_sf2.h net: dsa: bcm_sf2: refactor LED regs access 2021-12-30 17:28:32 -08:00
dsa_loop_bdinfo.c
dsa_loop.c net: dsa: Fix possible memory leaks in dsa_loop_init() 2022-10-28 10:32:59 +01:00
dsa_loop.h
Kconfig net: dsa: LAN9303: Add basic support for LAN9354 2022-09-07 11:06:04 +01:00
lan9303_i2c.c * 'remove' callback converted to return void. Big change with trivial 2022-10-04 18:54:33 -07:00
lan9303_mdio.c net: dsa: lan9303: remove unnecessary dev_set_drvdata() 2022-09-22 19:30:36 -07:00
lan9303-core.c net: dsa: introduce dsa_port_get_master() 2022-09-20 10:32:35 +02:00
lan9303.h net: dsa: be compatible with masters which unregister on shutdown 2021-09-19 12:08:37 +01:00
lantiq_gswip.c net: dsa: lantiq_gswip: remove unnecessary platform_set_drvdata() 2022-09-22 19:30:36 -07:00
lantiq_pce.h
Makefile net: dsa: qca8k: move driver to qca dir 2022-07-15 11:57:13 +01:00
mt7530.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-09-29 14:30:51 -07:00
mt7530.h net: dsa: mt7530: add support for in-band link status 2022-09-23 11:58:37 +01:00
mv88e6060.c net: dsa: mv88e6060: remove unnecessary dev_set_drvdata() 2022-09-22 19:30:37 -07:00
mv88e6060.h
rzn1_a5psw.c net: dsa: rzn1-a5psw: remove unnecessary platform_set_drvdata() 2022-09-22 19:30:39 -07:00
rzn1_a5psw.h net: dsa: rzn1-a5psw: add FDB support 2022-06-27 11:37:55 +01:00
vitesse-vsc73xx-core.c net: dsa: vsc73xxx: Get rid of duplicate of_node assignment 2021-12-03 14:13:02 +00:00
vitesse-vsc73xx-platform.c net: dsa: vitesse-vsc73xx: remove unnecessary set_drvdata() 2022-09-22 19:30:39 -07:00
vitesse-vsc73xx-spi.c net: dsa: vitesse-vsc73xx: remove unnecessary set_drvdata() 2022-09-22 19:30:39 -07:00
vitesse-vsc73xx.h net: dsa: vsc73xxx: Make vsc73xx_remove() return void 2021-11-15 13:15:07 +00:00