Skip to contentSkip to conversation

HID: logitech-headset: add a battery driver for the PRO X 2

PATCH Superseded Méven Car 2 participants 6 messages Sep 11

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Méven Car

author
#0 lore raw

PATCH 1/1 HID: logitech-headset: add a battery driver for the PRO X 2

The PRO X 2 LIGHTSPEED receiver does not speak HID++, so hid-logitech-hidpp cannot read its battery. Its report descriptor has a consumer collection for the media keys and two vendor collections, and no report 0x10 or 0x11.

The battery answers on usage page 0xffa0. A single 64 byte frame on report 0x51 asks for it, with no handshake, and the reply gives the level and whether the headset is charging. The driver asks every 120 seconds, and it also reads the power frames that the headset sends on its own, so a headset that was switched off is reported before the next poll.

hid-generic sets HID_QUIRK_INPUT_PER_APP, so this receiver had one input device per application collection, among them the Consumer Control node for the media keys. A driver does not inherit that quirk, so probe sets it and the input devices stay as they were.

The power supply is registered with POWER_SUPPLY_SCOPE_DEVICE, and capacity returns -ENODATA until the first reply arrives.

The G522 LIGHTSPEED uses the same vendor protocol with a different frame layout. That device is left out until someone can test it.

Assisted-by Claude:claude-opus-5

---
Tested on a PRO X 2 LIGHTSPEED (046d:0af7) with 7.2.4, built as a module out of tree. The driver binds on replug without unbinding hid-generic by hand, and one power supply appears for the single HID interface of the receiver. present, status and capacity read 1, Discharging and 50, against the same frame read through hidraw: 510b000310000600040a3232.

With HID_QUIRK_INPUT_PER_APP the receiver keeps the three input devices it had under hid-generic, among them "Logitech PRO X 2 LIGHTSPEED Consumer Control". Without the quirk the three became one and that node was gone.

UPower exports the supply as an audio-device peripheral, which is what the KDE battery applet lists.

Not tested: the G522 LIGHTSPEED, which is why it is absent from the id table, and the hid_hw_raw_request fallback in logi_headset_ask, because this receiver has an interrupt out endpoint and always takes the hid_hw_output_report path.

The one checkpatch warning that is left is the ENOSYS one, and it matches how hid-input.c and hidraw.c test the return of hid_hw_output_report before they fall back to hid_hw_raw_request.

Per Documentation/process/generated-content.rst: this patch was written with Claude Code, model claude-opus-5. The protocol was read from HeadsetControl and confirmed with a python script that sent the frame over hidraw on the real device. The model wrote the driver, the Kconfig and Makefile entries and this changelog from that, and the result was built and tested on the hardware described above.

Based on v7.2.3, so it may need a rebase onto hid.git.

 drivers/hid/Kconfig                |  11 ++
 drivers/hid/Makefile               |   1 +
 drivers/hid/hid-ids.h              |   1 +
 drivers/hid/hid-logitech-headset.c | 292 +++++++++++++++++++++++++++++
 4 files changed, 305 insertions(+)
 create mode 100644 drivers/hid/hid-logitech-headset.c
drivers/hid/Kconfig +11 -0
index 48934c4f3..5c845b1b8 100644
@@ -670,6 +670,17 @@ config HID_LOGITECH_DJ
 	generic USB_HID driver and all incoming events will be multiplexed
 	into a single mouse and a single keyboard device.
 
+config HID_LOGITECH_HEADSET
+	tristate "Logitech wireless headset battery"
+	depends on USB_HID
+	select POWER_SUPPLY
+	help
+	Support for the battery of Logitech wireless gaming headsets that
+	report it over a vendor collection instead of HID++.
+
+	Supported devices:
+	- PRO X 2 LIGHTSPEED
+
 config HID_LOGITECH_HIDPP
 	tristate "Logitech HID++ devices support"
 	depends on HID_LOGITECH
drivers/hid/Makefile +1 -0
index 23e6e3dd0..b8576a5ac 100644
@@ -82,6 +82,7 @@ obj-$(CONFIG_HID_LETSKETCH)	+= hid-letsketch.o
 obj-$(CONFIG_HID_LOGITECH)	+= hid-logitech.o
 obj-$(CONFIG_HID_LOGITECH)	+= hid-lg-g15.o
 obj-$(CONFIG_HID_LOGITECH_DJ)	+= hid-logitech-dj.o
+obj-$(CONFIG_HID_LOGITECH_HEADSET)	+= hid-logitech-headset.o
 obj-$(CONFIG_HID_LOGITECH_HIDPP)	+= hid-logitech-hidpp.o
 obj-$(CONFIG_HID_MACALLY)	+= hid-macally.o
 obj-$(CONFIG_HID_MAGICMOUSE)	+= hid-magicmouse.o
drivers/hid/hid-ids.h +1 -0
index 1059922ba..0efe30b2f 100644
@@ -910,6 +910,7 @@
 #define USB_VENDOR_ID_LOGITECH		0x046d
 #define USB_DEVICE_ID_LOGITECH_Z_10_SPK	0x0a07
 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e
+#define USB_DEVICE_ID_LOGITECH_PRO_X_2_LIGHTSPEED	0x0af7
 #define USB_DEVICE_ID_LOGITECH_T651	0xb00c
 #define USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD	0xb309
 #define USB_DEVICE_ID_LOGITECH_CASA_TOUCHPAD	0xbb00
drivers/hid/hid-logitech-headset.c new file +292 -0

292 lines not on this page · raw message

Signature · 1 line
2.55.0
author
#1 lore raw

PATCH v2 1/1 HID: logitech-headset: add a battery driver for the PRO X 2

The PRO X 2 LIGHTSPEED receiver does not speak HID++, so hid-logitech-hidpp cannot read its battery. Its report descriptor has a consumer collection for the media keys and two vendor collections, and no report 0x10 or 0x11.

The battery answers on usage page 0xffa0. A single 64 byte frame on report 0x51 asks for it, with no handshake, and the reply gives the level and whether the headset is charging. The driver asks every 120 seconds, and it also reads the power frames that the headset sends on its own, so a headset that was switched off is reported before the next poll.

hid-generic sets HID_QUIRK_INPUT_PER_APP, so this receiver had one input device per application collection, among them the Consumer Control node for the media keys. A driver does not inherit that quirk, so probe sets it and the input devices stay as they were.

The power supply is registered with POWER_SUPPLY_SCOPE_DEVICE, and capacity returns -ENODATA until the first reply arrives.

The G522 LIGHTSPEED uses the same vendor protocol with a different frame layout. That device is left out until someone can test it.

Assisted-by Claude:claude-opus-5

---
Changes since v1: the Signed-off-by line, which v1 was sent without by mistake. The patch itself is unchanged.

Tested on a PRO X 2 LIGHTSPEED (046d:0af7) with 7.2.4, built as a module out of tree. The driver binds on replug without unbinding hid-generic by hand, and one power supply appears for the single HID interface of the receiver. present, status and capacity read 1, Discharging and 50, against the same frame read through hidraw: 510b000310000600040a3232.

With HID_QUIRK_INPUT_PER_APP the receiver keeps the three input devices it had under hid-generic, among them "Logitech PRO X 2 LIGHTSPEED Consumer Control". Without the quirk the three became one and that node was gone.

UPower exports the supply as an audio-device peripheral, which is what the KDE battery applet lists.

Not tested: the G522 LIGHTSPEED, which is why it is absent from the id table, and the hid_hw_raw_request fallback in logi_headset_ask, because this receiver has an interrupt out endpoint and always takes the hid_hw_output_report path.

The one checkpatch warning that is left is the ENOSYS one, and it matches how hid-input.c and hidraw.c test the return of hid_hw_output_report before they fall back to hid_hw_raw_request.

Per Documentation/process/generated-content.rst: this patch was written with Claude Code, model claude-opus-5. The protocol was read from HeadsetControl and confirmed with a python script that sent the frame over hidraw on the real device. The model wrote the driver, the Kconfig and Makefile entries and this changelog from that, and the result was built and tested on the hardware described above.

Based on v7.2.3, so it may need a rebase onto hid.git.

 drivers/hid/Kconfig                |  11 ++
 drivers/hid/Makefile               |   1 +
 drivers/hid/hid-ids.h              |   1 +
 drivers/hid/hid-logitech-headset.c | 292 +++++++++++++++++++++++++++++
 4 files changed, 305 insertions(+)
 create mode 100644 drivers/hid/hid-logitech-headset.c
drivers/hid/Kconfig +11 -0
index 48934c4f3..5c845b1b8 100644
@@ -670,6 +670,17 @@ config HID_LOGITECH_DJ
 	generic USB_HID driver and all incoming events will be multiplexed
 	into a single mouse and a single keyboard device.
 
+config HID_LOGITECH_HEADSET
+	tristate "Logitech wireless headset battery"
+	depends on USB_HID
+	select POWER_SUPPLY
+	help
+	Support for the battery of Logitech wireless gaming headsets that
+	report it over a vendor collection instead of HID++.
+
+	Supported devices:
+	- PRO X 2 LIGHTSPEED
+
 config HID_LOGITECH_HIDPP
 	tristate "Logitech HID++ devices support"
 	depends on HID_LOGITECH
drivers/hid/Makefile +1 -0
index 23e6e3dd0..b8576a5ac 100644
@@ -82,6 +82,7 @@ obj-$(CONFIG_HID_LETSKETCH)	+= hid-letsketch.o
 obj-$(CONFIG_HID_LOGITECH)	+= hid-logitech.o
 obj-$(CONFIG_HID_LOGITECH)	+= hid-lg-g15.o
 obj-$(CONFIG_HID_LOGITECH_DJ)	+= hid-logitech-dj.o
+obj-$(CONFIG_HID_LOGITECH_HEADSET)	+= hid-logitech-headset.o
 obj-$(CONFIG_HID_LOGITECH_HIDPP)	+= hid-logitech-hidpp.o
 obj-$(CONFIG_HID_MACALLY)	+= hid-macally.o
 obj-$(CONFIG_HID_MAGICMOUSE)	+= hid-magicmouse.o
drivers/hid/hid-ids.h +1 -0
index 1059922ba..0efe30b2f 100644
@@ -910,6 +910,7 @@
 #define USB_VENDOR_ID_LOGITECH		0x046d
 #define USB_DEVICE_ID_LOGITECH_Z_10_SPK	0x0a07
 #define USB_DEVICE_ID_LOGITECH_AUDIOHUB 0x0a0e
+#define USB_DEVICE_ID_LOGITECH_PRO_X_2_LIGHTSPEED	0x0af7
 #define USB_DEVICE_ID_LOGITECH_T651	0xb00c
 #define USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD	0xb309
 #define USB_DEVICE_ID_LOGITECH_CASA_TOUCHPAD	0xbb00
drivers/hid/hid-logitech-headset.c new file +292 -0

292 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The driver cancels its delayed workqueue before calling hid_hw_stop(), which violates the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The driver cancels its delayed workqueue before calling hid_hw_stop(), which violates the mandatory HID subsystem cleanup order. --

commit bd334ae3e07d607cf268d197e4923d3fe7f27cad
Author: Méven Car <[email protected]>

HID: logitech-headset: add a battery driver for the PRO X 2

This commit introduces a battery driver for the Logitech PRO X 2 LIGHTSPEED headset. The device reports its battery status over a vendor collection rather than HID++, so a custom driver is implemented to poll and parse these reports.

Quoted 5 lines
drivers/hid/hid-logitech-headset.c new file +0 -0
new file mode 100644
index 0000000000000..9081ddf5f42f2

[ ... ]

drivers/hid/hid-logitech-headset.c line 271

Quoted 7 lines
drivers/hid/hid-logitech-headset.c new file +7 -0
+static void logi_headset_remove(struct hid_device *hdev)
+{
+	struct logi_headset *headset = hid_get_drvdata(hdev);
+
+	cancel_delayed_work_sync(&headset->poll);
+	hid_hw_close(hdev);
+	hid_hw_stop(hdev);

[Severity: High]
Could this teardown sequence in logi_headset_remove() lead to a use-after-free?

In drivers/hid/hid-logitech-headset.c:logi_headset_remove(), the delayed work is cancelled before hid_hw_stop() is called. When a device is unplugged or unbound, cancelling workers before stopping the hardware (which unregisters the device interfaces) means that hardware events or userspace interactions could theoretically queue new work after the cancellation.

Since devres automatically frees the driver's private data after remove() returns, any lingering work executing subsequently would access freed memory. Calling hid_hw_stop() before cancelling the work would ensure no new work can be queued.

Quoted 1 line

+}

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#3 lore raw
Quoted 2 lines

The HID subsystem guidelines specify that hid_hw_stop must be called before cancelling asynchronous workers.

Stopping first is the unsafe order here. logi_headset_poll() ends in hid_hw_output_report(), so a work item still running would send on a transport hid_hw_stop() has already torn down.

drivers/hid mostly cancels first: steelseries, steam, kysona, asus, nvidia-shield. corsair-void stops first, but its battery_work only calls power_supply_unregister() and power_supply_changed() and never touches the device.

cancel_work_sync() handles a work that re-arms itself. The only schedule_delayed_work() calls here are in probe() and at the end of the work, raw_event() never schedules.

Which guideline do you mean? I see nothing on this in Documentation/hid/.

Quoted 48 lines · Le ven. 11 sept. 2026 à 14:10, <[email protected]> a écrit :

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The driver cancels its delayed workqueue before calling hid_hw_stop(), which violates the mandatory HID subsystem cleanup order. --

commit bd334ae3e07d607cf268d197e4923d3fe7f27cad
Author: Méven Car <[email protected]>

HID: logitech-headset: add a battery driver for the PRO X 2

This commit introduces a battery driver for the Logitech PRO X 2 LIGHTSPEED headset. The device reports its battery status over a vendor collection rather than HID++, so a custom driver is implemented to poll and parse these reports.

Quoted 5 lines
drivers/hid/hid-logitech-headset.c new file +0 -0
new file mode 100644
index 0000000000000..9081ddf5f42f2

[ ... ]

drivers/hid/hid-logitech-headset.c line 271

Quoted 7 lines
drivers/hid/hid-logitech-headset.c new file +7 -0
+static void logi_headset_remove(struct hid_device *hdev)
+{
+     struct logi_headset *headset = hid_get_drvdata(hdev);
+
+     cancel_delayed_work_sync(&headset->poll);
+     hid_hw_close(hdev);
+     hid_hw_stop(hdev);

[Severity: High]
Could this teardown sequence in logi_headset_remove() lead to a use-after-free?

In drivers/hid/hid-logitech-headset.c:logi_headset_remove(), the delayed work is cancelled before hid_hw_stop() is called. When a device is unplugged or unbound, cancelling workers before stopping the hardware (which unregisters the device interfaces) means that hardware events or userspace interactions could theoretically queue new work after the cancellation.

Since devres automatically frees the driver's private data after remove() returns, any lingering work executing subsequently would access freed memory. Calling hid_hw_stop() before cancelling the work would ensure no new work can be queued.

Quoted 1 line

+}

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

Signature · 1 line
Méven
author
#4 lore raw
In reply to [email protected]
Quoted 2 lines

The HID subsystem guidelines specify that hid_hw_stop must be called before cancelling asynchronous workers.

Stopping first is the unsafe order here. logi_headset_poll() ends in hid_hw_output_report(), so a work item still running would send on a transport hid_hw_stop() has already torn down.

drivers/hid mostly cancels first: steelseries, steam, kysona, asus, nvidia-shield. corsair-void stops first, but its battery_work only calls power_supply_unregister() and power_supply_changed() and never touches the device.

cancel_work_sync() handles a work that re-arms itself. The only schedule_delayed_work() calls here are in probe() and at the end of the work, raw_event() never schedules.

Which guideline do you mean? I find nothing on this anywhere in Documentation/, and the kerneldoc of hid_hw_stop() does not mention workers.

Signature · 1 line
Méven
#5 lore raw
In reply to Méven Car
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Incorrect teardown sequence in remove callback violates HID subsystem guidelines. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect teardown sequence in remove callback violates HID subsystem guidelines. --

commit adb0241c4db099ec7ce91b1ebd7f292627e20d96
Author: Méven Car <[email protected]>

HID: logitech-headset: add a battery driver for the PRO X 2

This commit introduces a battery driver for the Logitech PRO X 2 LIGHTSPEED headset. It communicates with the hardware over a vendor collection using a polling mechanism scheduled via a delayed work queue to report battery status.

[ ... ]

Quoted 5 lines
drivers/hid/hid-logitech-headset.c new file +0 -0
new file mode 100644
index 0000000000000..9081ddf5f42f2

[ ... ]

drivers/hid/hid-logitech-headset.c line 269

Quoted 5 lines
drivers/hid/hid-logitech-headset.c new file +5 -0
+static void logi_headset_remove(struct hid_device *hdev)
+{
+	struct logi_headset *headset = hid_get_drvdata(hdev);
+
+	cancel_delayed_work_sync(&headset->poll);

[Severity: High]
Does this teardown sequence in logi_headset_remove risk a use-after-free?

The HID subsystem guidelines specify that hid_hw_stop must be called before cancelling asynchronous workers. By executing cancel_delayed_work_sync before hid_hw_stop, it is theoretically possible for new work to be queued while the driver is in the process of unbinding.

Calling hid_hw_stop first ensures that no new events or userspace requests can trigger work to be scheduled during resource reclamation.

Quoted 3 lines
drivers/hid/hid-logitech-headset.c new file +3 -0
+	hid_hw_close(hdev);
+	hid_hw_stop(hdev);
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1