[PATCH net] net: dsa: hellcreek: fix missing error handling in LED registration

Pavel Zhigulin posted 1 patch 2 months, 3 weeks ago
drivers/net/dsa/hirschmann/hellcreek_ptp.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
[PATCH net] net: dsa: hellcreek: fix missing error handling in LED registration
Posted by Pavel Zhigulin 2 months, 3 weeks ago
The LED setup routine registered both led_sync_good
and led_is_gm devices without checking the return
values of led_classdev_register(). If either registration
failed, the function continued silently, leaving the
driver in a partially-initialized state and leaking
a registered LED classdev.

Add proper error handling

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 7d9ee2e8ff15 ("net: dsa: hellcreek: Add PTP status LEDs")
Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
---
 drivers/net/dsa/hirschmann/hellcreek_ptp.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/hirschmann/hellcreek_ptp.c b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
index bfe21f9f7dcd..cb23bea9c21b 100644
--- a/drivers/net/dsa/hirschmann/hellcreek_ptp.c
+++ b/drivers/net/dsa/hirschmann/hellcreek_ptp.c
@@ -376,8 +376,18 @@ static int hellcreek_led_setup(struct hellcreek *hellcreek)
 		hellcreek_set_brightness(hellcreek, STATUS_OUT_IS_GM, 1);

 	/* Register both leds */
-	led_classdev_register(hellcreek->dev, &hellcreek->led_sync_good);
-	led_classdev_register(hellcreek->dev, &hellcreek->led_is_gm);
+	ret = led_classdev_register(hellcreek->dev, &hellcreek->led_sync_good);
+	if (ret) {
+		dev_err(hellcreek->dev, "Failed to register sync_good LED\n");
+		goto out;
+	}
+
+	ret = led_classdev_register(hellcreek->dev, &hellcreek->led_is_gm);
+	if (ret) {
+		dev_err(hellcreek->dev, "Failed to register is_gm LED\n");
+		led_classdev_unregister(&hellcreek->led_sync_good);
+		goto out;
+	}

 	ret = 0;

--
2.43.0
Re: [PATCH net] net: dsa: hellcreek: fix missing error handling in LED registration
Posted by Kurt Kanzenbach 2 months, 3 weeks ago
On Thu Nov 13 2025, Pavel Zhigulin wrote:
> The LED setup routine registered both led_sync_good
> and led_is_gm devices without checking the return
> values of led_classdev_register(). If either registration
> failed, the function continued silently, leaving the
> driver in a partially-initialized state and leaking
> a registered LED classdev.
>
> Add proper error handling
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: 7d9ee2e8ff15 ("net: dsa: hellcreek: Add PTP status LEDs")
> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>

Acked-by: Kurt Kanzenbach <kurt@linutronix.de>
Re: [PATCH net] net: dsa: hellcreek: fix missing error handling in LED registration
Posted by Andrew Lunn 2 months, 3 weeks ago
On Thu, Nov 13, 2025 at 04:57:44PM +0300, Pavel Zhigulin wrote:
> The LED setup routine registered both led_sync_good
> and led_is_gm devices without checking the return
> values of led_classdev_register(). If either registration
> failed, the function continued silently, leaving the
> driver in a partially-initialized state and leaking
> a registered LED classdev.
> 
> Add proper error handling
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.

Does it say anything about leaking leds?

> Fixes: 7d9ee2e8ff15 ("net: dsa: hellcreek: Add PTP status LEDs")
> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew