From: "David Rheinsberg" <david@readahead.eu>
To: "Rafael Passos" <rafael@rcpassos.me>,
"Benjamin Tissoires" <bentiss@kernel.org>,
"Jiri Kosina" <jikos@kernel.org>
Cc: "Shuah Khan" <skhan@linuxfoundation.org>,
"Brigham Campbell" <me@brighamcampbell.com>,
"Jori Koolstra" <jkoolstra@xs4all.nl>,
linux-input@vger.kernel.org
Subject: Re: [PATCH v4 3/4] HID: wiimote: led_probe with scoped cleanup
Date: Sun, 20 Sep 2026 10:17:11 +0200 [thread overview]
Message-ID: <4fa49d62-ce93-46e6-a0be-9b2750bee9c7@app.fastmail.com> (raw)
In-Reply-To: <20260817213840.1053216-4-rafael@rcpassos.me>
Hi
On Mon, Aug 17, 2026, at 11:38 PM, Rafael Passos wrote:
> 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);
We usually do not allow mixed declarations and code. So the variable declaration including the `__free(kfree)` should be moved to the top.
Otherwise, this looks good:
Reviewed-by: David Rheinsberg <david@readahead.eu>
Thanks!
> 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-09-20 8:17 UTC|newest]
Thread overview: 15+ 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-09-20 8:24 ` David Rheinsberg
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-09-20 8:12 ` David Rheinsberg
2026-08-17 21:38 ` [PATCH v4 3/4] HID: wiimote: led_probe with scoped cleanup Rafael Passos
2026-09-20 8:17 ` David Rheinsberg [this message]
2026-08-17 21:38 ` [PATCH v4 4/4] HID: wiimote: wiimote_probe " Rafael Passos
2026-08-17 21:54 ` sashiko-bot
2026-09-20 8:21 ` David Rheinsberg
2026-10-04 15:03 ` Rafael Passos
2026-09-03 13:30 ` [PATCH v4 0/4] HID: wiimote: new LED behavior on connect + scoped_guards Rafael Passos
2026-09-11 16:44 ` Jiri Kosina
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=4fa49d62-ce93-46e6-a0be-9b2750bee9c7@app.fastmail.com \
--to=david@readahead.eu \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=jkoolstra@xs4all.nl \
--cc=linux-input@vger.kernel.org \
--cc=me@brighamcampbell.com \
--cc=rafael@rcpassos.me \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.