linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting
@ 2025-06-15 22:59 Qasim Ijaz
  2025-06-18 13:00 ` Aditya Garg
  2025-06-20  7:01 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Qasim Ijaz @ 2025-06-15 22:59 UTC (permalink / raw)
  To: jikos, bentiss; +Cc: gargaditya08, linux-input, linux-kernel, stable

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")
Cc: stable@vger.kernel.org
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
---
 drivers/hid/hid-appletb-kbd.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/hid/hid-appletb-kbd.c b/drivers/hid/hid-appletb-kbd.c
index ef51b2c06872..e06567886e50 100644
--- a/drivers/hid/hid-appletb-kbd.c
+++ b/drivers/hid/hid-appletb-kbd.c
@@ -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);
 }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting
  2025-06-15 22:59 [PATCH] HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting Qasim Ijaz
@ 2025-06-18 13:00 ` Aditya Garg
  2025-06-20  7:01 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Aditya Garg @ 2025-06-18 13:00 UTC (permalink / raw)
  To: Qasim Ijaz
  Cc: jikos@kernel.org, bentiss@kernel.org, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org

Hi Qasim

> 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.

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

Thanks for the fix!

> Fixes: 93a0fc489481 ("HID: hid-appletb-kbd: add support for automatic brightness control while using the touchbar")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>

Reviewed-by: Aditya Garg <gargaditya08@live.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting
  2025-06-15 22:59 [PATCH] HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting Qasim Ijaz
  2025-06-18 13:00 ` Aditya Garg
@ 2025-06-20  7:01 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2025-06-20  7:01 UTC (permalink / raw)
  To: Qasim Ijaz; +Cc: bentiss, gargaditya08, linux-input, linux-kernel, stable

On Sun, 15 Jun 2025, Qasim Ijaz wrote:

> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-20  7:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-15 22:59 [PATCH] HID: appletb-kbd: fix "appletb_backlight" backlight device reference counting Qasim Ijaz
2025-06-18 13:00 ` Aditya Garg
2025-06-20  7:01 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).