From: Rafael Passos <rafael@rcpassos.me>
To: David Rheinsberg <david@readahead.eu>,
bentiss@kernel.org, jikos@kernel.org
Cc: Shuah Khan <skhan@linuxfoundation.org>,
Brigham Campbell <me@brighamcampbell.com>,
Jori Koolstra <jkoolstra@xs4all.nl>,
Rafael Passos <rafael@rcpassos.me>,
linux-input@vger.kernel.org
Subject: [PATCH v4 3/4] HID: wiimote: led_probe with scoped cleanup
Date: Mon, 17 Aug 2026 18:38:23 -0300 [thread overview]
Message-ID: <20260817213840.1053216-4-rafael@rcpassos.me> (raw)
In-Reply-To: <20260817213840.1053216-1-rafael@rcpassos.me>
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 <rafael@rcpassos.me>
---
drivers/hid/hid-wiimote-modules.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
index 3cd614466740..47fa6a8ecdae 100644
--- a/drivers/hid/hid-wiimote-modules.c
+++ b/drivers/hid/hid-wiimote-modules.c
@@ -341,11 +341,11 @@ static int wiimod_led_probe(const struct wiimod_ops *ops,
{
struct device *dev = &wdata->hdev->dev;
size_t namesz = strlen(dev_name(dev)) + 9;
- struct led_classdev *led;
char *name;
int ret;
- led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL);
+ struct led_classdev *led __free(kfree) =
+ kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL);
if (!led)
return -ENOMEM;
@@ -359,8 +359,12 @@ 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);
/* enable LED1 to stop initial LED-blinking */
if (ops->arg == 0) {
@@ -369,11 +373,6 @@ static int wiimod_led_probe(const struct wiimod_ops *ops,
}
return 0;
-
-err_free:
- wdata->leds[ops->arg] = NULL;
- kfree(led);
- return ret;
}
static void wiimod_led_remove(const struct wiimod_ops *ops,
--
2.55.0
next prev parent reply other threads:[~2026-08-17 21:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 21:38 [PATCH v4 0/4] HID: wiimote: new LED behavior on connect + scoped_guards Rafael Passos
2026-08-17 21:38 ` [PATCH v4 1/4] HID: wiimote: turn on the LEDs indicating the controller id Rafael Passos
2026-08-17 21:55 ` sashiko-bot
2026-08-17 21:38 ` [PATCH v4 2/4] HID: wiimote: replace spinlock pairs with scoped_guard Rafael Passos
2026-08-17 21:59 ` sashiko-bot
2026-08-17 21:38 ` Rafael Passos [this message]
2026-08-17 21:38 ` [PATCH v4 4/4] HID: wiimote: wiimote_probe with scoped cleanup Rafael Passos
2026-08-17 21:54 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260817213840.1053216-4-rafael@rcpassos.me \
--to=rafael@rcpassos.me \
--cc=bentiss@kernel.org \
--cc=david@readahead.eu \
--cc=jikos@kernel.org \
--cc=jkoolstra@xs4all.nl \
--cc=linux-input@vger.kernel.org \
--cc=me@brighamcampbell.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox