From: Arunachalam <arun07172003@gmail.com>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
Arunachalam <arun07172003@gmail.com>
Subject: [PATCH 2/2] leds: cobalt-raq: Use devm_led_classdev_register() to fix use-after-unmap
Date: Sat, 25 Jul 2026 23:22:36 +0530 [thread overview]
Message-ID: <20260725175236.32015-1-arun07172003@gmail.com> (raw)
In-Reply-To: <20260725082003.F423C1F000E9@smtp.kernel.org>
The driver had no .remove callback, but registered its LEDs with the
unmanaged led_classdev_register() while the I/O mapping for led_port
was already managed via devres. If the driver was unbound, devres
would unmap led_port, but the LED classdevs would remain registered
with no matching teardown. A subsequent sysfs brightness write would
then dereference the now-unmapped led_port pointer.
Switch to devm_led_classdev_register() so LED registration and the
I/O mapping share the same devres lifetime and are torn down in the
correct order automatically.
Signed-off-by: Arunachalam <arun07172003@gmail.com>
---
drivers/leds/leds-cobalt-raq.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/leds/leds-cobalt-raq.c b/drivers/leds/leds-cobalt-raq.c
index 5b5acaa8c..ecb64ca9d 100644
--- a/drivers/leds/leds-cobalt-raq.c
+++ b/drivers/leds/leds-cobalt-raq.c
@@ -76,19 +76,16 @@ static int cobalt_raq_led_probe(struct platform_device *pdev)
if (!led_port)
return -ENOMEM;
- retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
+ retval = devm_led_classdev_register(&pdev->dev, &raq_power_off_led);
if (retval)
goto err_null;
- retval = led_classdev_register(&pdev->dev, &raq_web_led);
+ retval = devm_led_classdev_register(&pdev->dev, &raq_web_led);
if (retval)
- goto err_unregister;
+ goto err_null;
return 0;
-err_unregister:
- led_classdev_unregister(&raq_power_off_led);
-
err_null:
led_port = NULL;
--
2.39.5
prev parent reply other threads:[~2026-07-25 17:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 8:13 [PATCH v3 1/4] leds: cobalt-raq: Add missing MODULE_DESCRIPTION Arunachalam
2026-07-25 8:13 ` [PATCH v3 2/4] leds: lp8788: Convert to dev_err_probe() Arunachalam
2026-07-25 8:21 ` sashiko-bot
2026-07-25 8:13 ` [PATCH v3 3/4] leds: menf21bmc: " Arunachalam
2026-07-25 8:19 ` sashiko-bot
2026-07-25 17:51 ` [PATCH 1/2] leds: menf21bmc: Use brightness_set_blocking instead of brightness_set Arunachalam
2026-07-25 8:13 ` [PATCH v3 4/4] leds: 88pm860x: Convert to dev_err_probe() Arunachalam
2026-07-25 8:19 ` sashiko-bot
2026-07-25 8:20 ` [PATCH v3 1/4] leds: cobalt-raq: Add missing MODULE_DESCRIPTION sashiko-bot
2026-07-25 17:52 ` Arunachalam [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=20260725175236.32015-1-arun07172003@gmail.com \
--to=arun07172003@gmail.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.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.