From: Stanislaw Gruszka <stf_xl@wp.pl>
To: Rosen Penev <rosenp@gmail.com>
Cc: linux-wireless@vger.kernel.org, open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH wireless-next] wifi: rt2x00: Allocate LED names dynamically
Date: Mon, 18 May 2026 09:40:54 +0200 [thread overview]
Message-ID: <20260518074054.GA20466@wp.pl> (raw)
In-Reply-To: <20260517231759.56638-1-rosenp@gmail.com>
Hi,
On Sun, May 17, 2026 at 04:17:59PM -0700, Rosen Penev wrote:
> The rt2x00 LED registration path builds LED class names from the
> driver and wiphy names. A fixed stack buffer can truncate those names
> before they are passed to the LED core.
To properly justify the change you'll need to provide real world
example when the size is not sufficient.
> Allocate each LED name with kasprintf(), check allocation failures, and
> release the stored name when the LED is unregistered.
>
> Assisted-by: Codex:GPT-5.5
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> .../net/wireless/ralink/rt2x00/rt2x00leds.c | 30 ++++++++++++++-----
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00leds.c b/drivers/net/wireless/ralink/rt2x00/rt2x00leds.c
> index f5361d582d4e..8818e0b2447b 100644
> --- a/drivers/net/wireless/ralink/rt2x00/rt2x00leds.c
> +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00leds.c
> @@ -100,6 +100,8 @@ static int rt2x00leds_register_led(struct rt2x00_dev *rt2x00dev,
>
> retval = led_classdev_register(device, &led->led_dev);
> if (retval) {
> + kfree(name);
> + led->led_dev.name = NULL;
> rt2x00_err(rt2x00dev, "Failed to register led handler\n");
> return retval;
> }
> @@ -111,15 +113,19 @@ static int rt2x00leds_register_led(struct rt2x00_dev *rt2x00dev,
>
> void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
> {
> - char name[36];
> + char *name;
> int retval;
> unsigned long on_period;
> unsigned long off_period;
> const char *phy_name = wiphy_name(rt2x00dev->hw->wiphy);
>
> if (rt2x00dev->led_radio.flags & LED_INITIALIZED) {
> - snprintf(name, sizeof(name), "%s-%s::radio",
> - rt2x00dev->ops->name, phy_name);
> + name = kasprintf(GFP_KERNEL, "%s-%s::radio",
> + rt2x00dev->ops->name, phy_name);
> + if (!name) {
> + retval = -ENOMEM;
> + goto exit_fail;
> + }
This is overengineering. If needed, the name size can be increased.
Regards
Stanislaw
>
> retval = rt2x00leds_register_led(rt2x00dev,
> &rt2x00dev->led_radio,
> @@ -129,8 +135,12 @@ void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
> }
>
> if (rt2x00dev->led_assoc.flags & LED_INITIALIZED) {
> - snprintf(name, sizeof(name), "%s-%s::assoc",
> - rt2x00dev->ops->name, phy_name);
> + name = kasprintf(GFP_KERNEL, "%s-%s::assoc",
> + rt2x00dev->ops->name, phy_name);
> + if (!name) {
> + retval = -ENOMEM;
> + goto exit_fail;
> + }
>
> retval = rt2x00leds_register_led(rt2x00dev,
> &rt2x00dev->led_assoc,
> @@ -140,8 +150,12 @@ void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
> }
>
> if (rt2x00dev->led_qual.flags & LED_INITIALIZED) {
> - snprintf(name, sizeof(name), "%s-%s::quality",
> - rt2x00dev->ops->name, phy_name);
> + name = kasprintf(GFP_KERNEL, "%s-%s::quality",
> + rt2x00dev->ops->name, phy_name);
> + if (!name) {
> + retval = -ENOMEM;
> + goto exit_fail;
> + }
>
> retval = rt2x00leds_register_led(rt2x00dev,
> &rt2x00dev->led_qual,
> @@ -182,6 +196,8 @@ static void rt2x00leds_unregister_led(struct rt2x00_led *led)
> led->led_dev.brightness_set(&led->led_dev, LED_OFF);
>
> led->flags &= ~LED_REGISTERED;
> + kfree(led->led_dev.name);
> + led->led_dev.name = NULL;
> }
>
> void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev)
> --
> 2.54.0
>
prev parent reply other threads:[~2026-05-18 7:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-17 23:17 [PATCH wireless-next] wifi: rt2x00: Allocate LED names dynamically Rosen Penev
2026-05-17 23:24 ` Rosen Penev
2026-05-18 7:40 ` Stanislaw Gruszka [this message]
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=20260518074054.GA20466@wp.pl \
--to=stf_xl@wp.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=rosenp@gmail.com \
/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.