Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mdio: fix resource leak in mdiobus_register_device()

Fix a possible leak in mdiobus_register_device() when both a
reset-gpio and a reset-controller are present.
Clean up the already claimed reset-gpio, when the registration of
the reset-controller fails, so when an error code is returned, the
device retains its state before the registration attempt.

Link: https://lore.kernel.org/all/20251106144603.39053c81@kernel.org/
Fixes: 71dd6c0dff51 ("net: phy: add support for reset-controller")
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
Link: https://patch.msgid.link/4b419377f8dd7d2f63f919d0f74a336c734f8fff.1762584481.git.buday.csaba@prolan.hu
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Buday Csaba and committed by
Jakub Kicinski
e6ca8f53 0725e6af

+4 -1
+4 -1
drivers/net/phy/mdio_bus.c
··· 73 73 return err; 74 74 75 75 err = mdiobus_register_reset(mdiodev); 76 - if (err) 76 + if (err) { 77 + gpiod_put(mdiodev->reset_gpio); 78 + mdiodev->reset_gpio = NULL; 77 79 return err; 80 + } 78 81 79 82 /* Assert the reset signal */ 80 83 mdio_device_reset(mdiodev, 1);