Skip to content

Commit 4540e41

Browse files
qasim-ijazJiri Kosina
authored andcommitted
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: 93a0fc4 ("HID: hid-appletb-kbd: add support for automatic brightness control while using the touchbar") Cc: [email protected] Signed-off-by: Qasim Ijaz <[email protected]> Reviewed-by: Aditya Garg <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent f305415 commit 4540e41

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

drivers/hid/hid-appletb-kbd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id
438438
return 0;
439439

440440
close_hw:
441+
if (kbd->backlight_dev)
442+
put_device(&kbd->backlight_dev->dev);
441443
hid_hw_close(hdev);
442444
stop_hw:
443445
hid_hw_stop(hdev);
@@ -453,6 +455,9 @@ static void appletb_kbd_remove(struct hid_device *hdev)
453455
input_unregister_handler(&kbd->inp_handler);
454456
timer_delete_sync(&kbd->inactivity_timer);
455457

458+
if (kbd->backlight_dev)
459+
put_device(&kbd->backlight_dev->dev);
460+
456461
hid_hw_close(hdev);
457462
hid_hw_stop(hdev);
458463
}

0 commit comments

Comments
 (0)