Skip to contentSkip to conversation

hwmon: (applesmc) fix key backlight workqueue leak on register failure

PATCH Applied Cong Nguyen 3 participants 3 messages Aug 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (applesmc) fix key backlight workqueue leak on register failure

applesmc_create_key_backlight() allocates applesmc_led_wq before calling led_classdev_register(). When register fails, the error is returned to applesmc_init(), which jumps to out_light_sysfs and skips applesmc_release_key_backlight(), leaking the workqueue.

Destroy the workqueue on the register failure path. The bug was introduced when the inline init block was refactored into a helper that returns errors directly, dropping the old out_light_wq unwind label.

Fixes 0b0b5dff8967 ("hwmon: (applesmc) Simplify feature sysfs handling")
Assisted-by Claude:claude-opus-4
---
 drivers/hwmon/applesmc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hwmon/applesmc.c +6 -1
index 90a14a7f2c4c..bfe9c5b0c4f1 100644
@@ -1249,12 +1249,17 @@ static void applesmc_release_light_sensor(void)
 
 static int applesmc_create_key_backlight(void)
 {
+	int ret;
+
 	if (!smcreg.has_key_backlight)
 		return 0;
 	applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
 	if (!applesmc_led_wq)
 		return -ENOMEM;
-	return led_classdev_register(&pdev->dev, &applesmc_backlight);
+	ret = led_classdev_register(&pdev->dev, &applesmc_backlight);
+	if (ret)
+		destroy_workqueue(applesmc_led_wq);
+	return ret;
 }
 
 static void applesmc_release_key_backlight(void)
Signature · 1 line
2.25.1
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

applesmc_create_key_backlight() allocates applesmc_led_wq before calling led_classdev_register(). When register fails, the error is returned to applesmc_init(), which jumps to out_light_sysfs and skips applesmc_release_key_backlight(), leaking the workqueue.

Quoted 8 lines

Destroy the workqueue on the register failure path. The bug was introduced when the inline init block was refactored into a helper that returns errors directly, dropping the old out_light_wq unwind label.

Fixes 0b0b5dff8967 ("hwmon: (applesmc) Simplify feature sysfs handling")
Assisted-by Claude:claude-opus-4

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Cong Nguyen
Quoted 5 lines · Cong Nguyen

applesmc_create_key_backlight() allocates applesmc_led_wq before calling led_classdev_register(). When register fails, the error is returned to applesmc_init(), which jumps to out_light_sysfs and skips applesmc_release_key_backlight(), leaking the workqueue.

Quoted 8 lines

Destroy the workqueue on the register failure path. The bug was introduced when the inline init block was refactored into a helper that returns errors directly, dropping the old out_light_wq unwind label.

Fixes 0b0b5dff8967 ("hwmon: (applesmc) Simplify feature sysfs handling")
Assisted-by Claude:claude-opus-4

Applied.

Thanks,
Guenter