Skip to contentSkip to conversation

HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting

PATCH Applied Qasim Ijaz 3 participants 3 messages Jun 15, 2025 – Jun 20, 2025

Subsystems (2)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH 1/1 HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting

During appletb_kbd_probe, probe attempts to get the backlight device by name. When this happens backlight_device_get_by_name looks for a device in the backlight class which has name "appletb_backlight" and upon finding a match it increments the reference count for the device and returns it to the caller. However this reference is never released leading to a reference leak.

Fix this by decrementing the backlight device reference count on removal via put_device and on probe failure.

Fixes 93a0fc489481 ("HID: hid-appletb-kbd: add support for automatic brightness control while using the touchbar")
---
 drivers/hid/hid-appletb-kbd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/hid/hid-appletb-kbd.c +5 -0
index ef51b2c06872..e06567886e50 100644
@@ -438,6 +438,8 @@ static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id
 	return 0;
 
 close_hw:
+	if (kbd->backlight_dev)
+		put_device(&kbd->backlight_dev->dev);
 	hid_hw_close(hdev);
 stop_hw:
 	hid_hw_stop(hdev);
@@ -453,6 +455,9 @@ static void appletb_kbd_remove(struct hid_device *hdev)
 	input_unregister_handler(&kbd->inp_handler);
 	timer_delete_sync(&kbd->inactivity_timer);
 
+	if (kbd->backlight_dev)
+		put_device(&kbd->backlight_dev->dev);
+
 	hid_hw_close(hdev);
 	hid_hw_stop(hdev);
 }
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw

Hi Qasim

Quoted 6 lines

During appletb_kbd_probe, probe attempts to get the backlight device by name. When this happens backlight_device_get_by_name looks for a device in the backlight class which has name "appletb_backlight" and upon finding a match it increments the reference count for the device and returns it to the caller. However this reference is never released leading to a reference leak.

Good catch.

Quoted 2 lines

Fix this by decrementing the backlight device reference count on removal via put_device and on probe failure.

Thanks for the fix!

Quoted 3 lines
Fixes 93a0fc489481 ("HID: hid-appletb-kbd: add support for automatic brightness control while using the touchbar")
maintainer Applied
#2 lore raw
In reply to Qasim Ijaz
Quoted 7 lines · Qasim Ijaz

During appletb_kbd_probe, probe attempts to get the backlight device by name. When this happens backlight_device_get_by_name looks for a device in the backlight class which has name "appletb_backlight" and upon finding a match it increments the reference count for the device and returns it to the caller. However this reference is never released leading to a reference leak.

Quoted 6 lines

Fix this by decrementing the backlight device reference count on removal via put_device and on probe failure.

Fixes 93a0fc489481 ("HID: hid-appletb-kbd: add support for automatic brightness control while using the touchbar")

Applied, thanks.

Signature · 2 lines
Jiri Kosina
SUSE Labs