[PATCH 2/2] media: radio-shark2: Unwind partial LED registration

From: Tian Xuechen

Date: Fri Dec 04 2026 - 08:32:19 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: be0c44fb480f ("[media] radio-shark2: Only compile led support when CONFIG_LED_CLASS is set")
Signed-off-by: Tian Xuechen <202300460064@xxxxxxxxxxxxxxx>
---
drivers/media/radio/radio-shark2.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
index 7cc173e21074..278d9db4a254 100644
--- a/drivers/media/radio/radio-shark2.c
+++ b/drivers/media/radio/radio-shark2.c
@@ -217,6 +217,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;
}
}
@@ -301,6 +304,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);
@@ -314,7 +318,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.ops = &shark_tea_ops;
--
2.34.1