From: "Heiko Stübner" <heiko@sntech.de>
To: Florian Eckert <fe@dev.tdt.de>
Cc: lee@kernel.org, jdelvare@suse.com, linux@roeck-us.net,
dmitry.torokhov@gmail.com, pavel@ucw.cz, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, ukleinek@debian.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-hwmon@vger.kernel.org,
linux-input@vger.kernel.org, linux-leds@vger.kernel.org
Subject: Re: [PATCH v2 3/7] leds: add driver for LEDs from qnap-mcu devices
Date: Mon, 29 Jul 2024 09:48:50 +0200 [thread overview]
Message-ID: <2916408.FA0FI3ke8A@diego> (raw)
In-Reply-To: <f7d10147a643f4d0d7cf2decbe490315@dev.tdt.de>
Hi Florian,
Am Montag, 29. Juli 2024, 08:24:26 CEST schrieb Florian Eckert:
> > +static int qnap_mcu_register_err_led(struct device *dev, struct
> > qnap_mcu *mcu, int num)
> > +{
> > + struct qnap_mcu_err_led *err_led;
> > + char tmp_buf[LED_MAX_NAME_SIZE];
> > + int ret;
> > +
> > + err_led = devm_kzalloc(dev, sizeof(*err_led), GFP_KERNEL);
> > + if (!err_led)
> > + return -ENOMEM;
> > +
> > + err_led->mcu = mcu;
> > + err_led->num = num;
> > + err_led->mode = QNAP_MCU_ERR_LED_OFF;
> > +
> > + snprintf(tmp_buf, LED_MAX_NAME_SIZE, "hdd%d:red:status", num + 1);
> > + err_led->cdev.name = tmp_buf;
>
> Should not the memory have to be allocated here via 'kzalloc' for
> 'err_led->cdev.name'?
> After leaving the function, tmp_buf is no longer on the stack?
Reading the led_classdev_register thing, cdev->name is used only for
creating the final-name for the LED and thus copied into yet another
temporary buffer [0] .
And cdev->name is not accessed anymore outside the register function.
But thinking more about that, you're still right, because after registering
cdev->name is in a bad state, pointing to something no valid anymore.
So if the LED core changes behaviour in the future, this will cause breakage.
So I'll change that.
Thanks for catching that
Heiko
[0] https://elixir.bootlin.com/linux/v6.10.1/source/drivers/leds/led-class.c#L500
https://elixir.bootlin.com/linux/v6.10.1/source/drivers/leds/led-class.c#L503
next prev parent reply other threads:[~2024-07-29 7:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-28 21:17 [PATCH v2 0/7] Drivers to support the MCU on QNAP NAS devices Heiko Stuebner
2024-07-28 21:17 ` [PATCH v2 1/7] dt-bindings: mfd: add binding for qnap,ts433-mcu devices Heiko Stuebner
2024-07-28 21:17 ` [PATCH v2 2/7] mfd: add base driver for qnap-mcu devices Heiko Stuebner
2024-07-28 21:17 ` [PATCH v2 3/7] leds: add driver for LEDs from " Heiko Stuebner
2024-07-29 6:24 ` Florian Eckert
2024-07-29 7:48 ` Heiko Stübner [this message]
2024-07-28 21:17 ` [PATCH v2 4/7] Input: add driver for the input part of " Heiko Stuebner
2024-07-29 0:12 ` Dmitry Torokhov
2024-07-28 21:17 ` [PATCH v2 5/7] hwmon: add driver for the hwmon parts " Heiko Stuebner
2024-07-30 15:27 ` Guenter Roeck
2024-07-28 21:17 ` [PATCH v2 6/7] arm64: dts: rockchip: hook up the MCU on the QNAP TS433 Heiko Stuebner
2024-07-28 21:17 ` [PATCH v2 7/7] arm64: dts: rockchip: set hdd led labels on qnap-ts433 Heiko Stuebner
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=2916408.FA0FI3ke8A@diego \
--to=heiko@sntech.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=fe@dev.tdt.de \
--cc=jdelvare@suse.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux@roeck-us.net \
--cc=pavel@ucw.cz \
--cc=robh@kernel.org \
--cc=ukleinek@debian.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;
as well as URLs for NNTP newsgroup(s).