[PATCH 1/2] media: radio-shark: Unwind partial LED registration
From: Tian Xuechen
Date: Fri Dec 04 2026 - 08:32:22 EST
If registering a later LED fails, probe frees the radio while earlier
LEDs are still registered and their brightness work can still run.
Unregister the successfully registered LEDs and cancel their work
before returning the error. Set the USB device pointer before LED
registration so work queued during registration or cleanup can use it.
This issue was found by our static analysis tool under development.
Fixes: 3e3b92cac537 ("[media] radio-shark: Only compile led support when CONFIG_LED_CLASS is set")
Signed-off-by: Tian Xuechen <202300460064@xxxxxxxxxxxxxxx>
---
drivers/media/radio/radio-shark.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
index c1f356c5f41e..f203cea9f637 100644
--- a/drivers/media/radio/radio-shark.c
+++ b/drivers/media/radio/radio-shark.c
@@ -251,6 +251,9 @@ static int shark_register_leds(struct shark_device *shark, struct device *dev)
v4l2_err(&shark->v4l2_dev,
"couldn't register led: %s\n",
shark->led_names[i]);
+ while (i--)
+ led_classdev_unregister(&shark->leds[i]);
+ cancel_work_sync(&shark->led_work);
return retval;
}
}
@@ -335,6 +338,7 @@ static int usb_shark_probe(struct usb_interface *intf,
if (!shark->transfer_buffer)
goto err_alloc_buffer;
+ shark->usbdev = interface_to_usbdev(intf);
v4l2_device_set_name(&shark->v4l2_dev, DRV_NAME, &shark_instance);
retval = shark_register_leds(shark, &intf->dev);
@@ -348,7 +352,6 @@ static int usb_shark_probe(struct usb_interface *intf,
goto err_reg_dev;
}
- shark->usbdev = interface_to_usbdev(intf);
shark->tea.v4l2_dev = &shark->v4l2_dev;
shark->tea.private_data = shark;
shark->tea.radio_nr = -1;
--
2.34.1