mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/2] leds: cobalt-raq: Use devm_led_classdev_register() to fix use-after-unmap
       [not found] <20260725082003.F423C1F000E9@smtp.kernel.org>
@ 2026-07-25 17:52 ` Arunachalam
  0 siblings, 0 replies; only message in thread
From: Arunachalam @ 2026-07-25 17:52 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek; +Cc: linux-leds, linux-kernel, Arunachalam

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-25 17:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20260725082003.F423C1F000E9@smtp.kernel.org>
2026-07-25 17:52 ` [PATCH 2/2] leds: cobalt-raq: Use devm_led_classdev_register() to fix use-after-unmap Arunachalam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®