kernel_samsung_a53x/drivers/net/dsa
Jinjie Ruan ccb950513d net: dsa: bcm_sf2: Fix possible memory leak in bcm_sf2_mdio_register()
commit 61b40cefe51af005c72dbdcf975a3d166c6e6406 upstream.

In bcm_sf2_mdio_register(), the class_find_device() will call get_device()
to increment reference count for priv->master_mii_bus->dev if
of_mdio_find_bus() succeeds. If mdiobus_alloc() or mdiobus_register()
fails, it will call get_device() twice without decrement reference count
for the device. And it is the same if bcm_sf2_mdio_register() succeeds but
fails in bcm_sf2_sw_probe(), or if bcm_sf2_sw_probe() succeeds. If the
reference count has not decremented to zero, the dev related resource will
not be freed.

So remove the get_device() in bcm_sf2_mdio_register(), and call
put_device() if mdiobus_alloc() or mdiobus_register() fails and in
bcm_sf2_mdio_unregister() to solve the issue.

And as Simon suggested, unwind from errors for bcm_sf2_mdio_register() and
just return 0 if it succeeds to make it cleaner.

Fixes: 461cd1b03e32 ("net: dsa: bcm_sf2: Register our slave MDIO bus")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Suggested-by: Simon Horman <horms@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Link: https://lore.kernel.org/r/20231011032419.2423290-1-ruanjinjie@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-08 11:26:11 +01:00
..
b53 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
microchip Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mv88e6xxx Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ocelot Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qca Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sja1105 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bcm_sf2.c net: dsa: bcm_sf2: Fix possible memory leak in bcm_sf2_mdio_register() 2024-11-08 11:26:11 +01:00
bcm_sf2.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bcm_sf2_cfp.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
bcm_sf2_regs.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dsa_loop.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dsa_loop.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dsa_loop_bdinfo.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lan9303-core.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lan9303.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lan9303_i2c.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lan9303_mdio.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lantiq_gswip.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lantiq_pce.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mt7530.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mt7530.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mv88e6060.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mv88e6060.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qca8k.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
qca8k.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
realtek-smi-core.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
realtek-smi-core.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rtl8366.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rtl8366rb.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vitesse-vsc73xx-core.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vitesse-vsc73xx-platform.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vitesse-vsc73xx-spi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vitesse-vsc73xx.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00