Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] HID: Input: Add battery list cleanup in hidinput_disconnect()
@ 2026-06-02  1:50 Rafael Passos
  2026-06-02  2:03 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Rafael Passos @ 2026-06-02  1:50 UTC (permalink / raw)
  To: linux-input, lcasmz54, bentiss
  Cc: hadess, jikos, linux-kernel, linux-pm, sre, kernel, Rafael Passos

The batteries list (hdev->batteries) is not cleaned up during
hidinput_disconnect(), but struct hid_battery entries are allocated
with devm_kzalloc.
When a driver is unbound (e.g. during devicereprobe), devm frees those
entries while their list_head nodesremain dangling in hdev->batteries,
which persists across rebinds.

Fixes: 4a58ae85c3f9 ("HID: input: Add support for multiple batteries per device")
Signed-off-by: Rafael Passos <rafael@rcpassos.me>
---

Hi, I hope there is time to land this in this cycle.
Tell me if I should make any changes.
I built and tested it againts the mainline.

Bug report link:
    https://lore.kernel.org/all/20260602011949.2825852-1-rafael@rcpassos.me/

 drivers/hid/hid-input.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index d73cfa2e73d3..95815e140fdf 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -2408,6 +2408,15 @@ EXPORT_SYMBOL_GPL(hidinput_connect);
 void hidinput_disconnect(struct hid_device *hid)
 {
 	struct hid_input *hidinput, *next;
+#ifdef CONFIG_HID_BATTERY_STRENGTH
+	{
+		struct hid_battery *bat, *tmp;
+
+		list_for_each_entry_safe(bat, tmp, &hid->batteries, list) {
+			list_del_init(&bat->list);
+		}
+	}
+#endif
 
 	list_for_each_entry_safe(hidinput, next, &hid->inputs, list) {
 		list_del(&hidinput->list);
-- 
2.53.0


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

end of thread, other threads:[~2026-06-02  2:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02  1:50 [PATCH] HID: Input: Add battery list cleanup in hidinput_disconnect() Rafael Passos
2026-06-02  2:03 ` sashiko-bot

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