From 1484db59f5847fa3945b4f47f8e8ba28883a6cee Mon Sep 17 00:00:00 2001 From: Rafael Passos Date: Thu, 8 Oct 2026 23:28:01 -0300 Subject: [PATCH] HID: wiimote: led_probe with scoped cleanup Cleanup code in led probe function, using the modern scoped cleanup. This prevents mistakes in future changes to this function. Signed-off-by: Rafael Passos Reviewed-by: David Rheinsberg Signed-off-by: Jiri Kosina --- drivers/hid/hid-wiimote-modules.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index fa8c63eb6097..199589cbf2b8 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c @@ -339,9 +339,9 @@ static void wiimod_led_set(struct led_classdev *led_dev, static int wiimod_led_probe(const struct wiimod_ops *ops, struct wiimote_data *wdata) { + struct led_classdev *led __free(kfree) = NULL; struct device *dev = &wdata->hdev->dev; size_t namesz = strlen(dev_name(dev)) + 9; - struct led_classdev *led; char *name; int ret; @@ -359,15 +359,14 @@ static int wiimod_led_probe(const struct wiimod_ops *ops, wdata->leds[ops->arg] = led; ret = led_classdev_register(dev, led); - if (ret) - goto err_free; + if (ret) { + wdata->leds[ops->arg] = NULL; + return ret; + } + + retain_and_null_ptr(led); return 0; - -err_free: - wdata->leds[ops->arg] = NULL; - kfree(led); - return ret; } static void wiimod_led_remove(const struct wiimod_ops *ops,