Skip to contentSkip to conversation

HID: hyperx-headset: Add support for HyperX headset devices

PATCH Superseded Sofia Schneider 2 participants 2 messages Jun 22 HID

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: hyperx-headset: Add support for HyperX headset devices

Introduce a HID driver for HyperX Cloud III Wireless headsets, supporting battery reporting and connection status.

Tested with a HyperX Cloud III Wireless only, for lack of other testable devices.

---
 MAINTAINERS                      |   6 +
 drivers/hid/Kconfig              |  11 +
 drivers/hid/Makefile             |   1 +
 drivers/hid/hid-hyperx-headset.c | 374 +++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h            |   1 +
 5 files changed, 393 insertions(+)
 create mode 100644 drivers/hid/hid-hyperx-headset.c
MAINTAINERS +6 -0
index d8252026bbd4..fa49655255f6 100644
@@ -11419,6 +11419,12 @@ F:	include/uapi/linux/hid*
 F:	samples/hid/
 F:	tools/testing/selftests/hid/
 
+HID HYPERX HEADSET DRIVER
+M:	Sofia Schneider <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/hid/hid-hyperx-headset.c
+
 HID LOGITECH DRIVERS
 R:	Filipe Laíns <[email protected]>
 L:	[email protected]
drivers/hid/Kconfig +11 -0
index f9bcaeb66385..e9f5f1f982c9 100644
@@ -1215,6 +1215,17 @@ config HID_HYPERV_MOUSE
 	help
 	Select this option to enable the Hyper-V mouse driver.
 
+config HID_HYPERX_HEADSET
+	tristate "HyperX headset devices"
+	depends on USB_HID
+	select POWER_SUPPLY
+	help
+	Support for HyperX headset devices.
+
+	Say Y here if you would like to enable support for HyperX headset devices.
+	To compile this driver as a module, choose M here: the module will be called
+	hid-hyperx-headset.
+
 config HID_SMARTJOYPLUS
 	tristate "SmartJoy PLUS PS2/USB adapter support"
 	help
drivers/hid/Makefile +1 -0
index 23e6e3dd0c56..9f3fd2c21837 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_HID_HOLTEK)	+= hid-holtek-kbd.o
 obj-$(CONFIG_HID_HOLTEK)	+= hid-holtek-mouse.o
 obj-$(CONFIG_HID_HOLTEK)	+= hid-holtekff.o
 obj-$(CONFIG_HID_HYPERV_MOUSE)	+= hid-hyperv.o
+obj-$(CONFIG_HID_HYPERX_HEADSET)	+= hid-hyperx-headset.o
 obj-$(CONFIG_HID_ICADE)		+= hid-icade.o
 obj-$(CONFIG_HID_ITE)		+= hid-ite.o
 obj-$(CONFIG_HID_JABRA)		+= hid-jabra.o
drivers/hid/hid-hyperx-headset.c new file +374 -0

374 lines not on this page · raw message

drivers/hid/hid-ids.h +1 -0
index 1059922baaac..aa2c3a71315b 100644
@@ -696,6 +696,7 @@
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_0941	0x0941
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_0641	0x0641
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_1f4a	0x1f4a
+#define USB_DEVICE_ID_HP_HYPERX_CLOUD_III_WIRELESS 0x05b7
 
 #define USB_VENDOR_ID_HUION		0x256c
 #define USB_DEVICE_ID_HUION_TABLET	0x006e
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Inverted teardown order in `hyperx_headset_remove` leads to Use-After-Free. - [High] Missing lock…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Inverted teardown order in hyperx_headset_remove leads to Use-After-Free.
- [High] Missing lock during power supply unregistration causes a data race and Use-After-Free.
- [High] Missing work cancellation on hid_hw_start error path leads to Use-After-Free.
- [Medium] Hardcoded power supply name causes sysfs collisions for multiple devices or interfaces. --

commit 435d0aab64fdcdfdde5a060312bb493c98996f6a
Author: Sofia Schneider <[email protected]>

HID: hyperx-headset: Add support for HyperX headset devices

Introduce a HID driver for HyperX Cloud III Wireless headsets, supporting battery reporting and connection status.

Quoted 4 lines
drivers/hid/hid-hyperx-headset.c new file +0 -0
new file mode 100644

[ ... ]

drivers/hid/hid-hyperx-headset.c line 104

Quoted 3 lines
drivers/hid/hid-hyperx-headset.c new file +3 -0
+static const struct power_supply_desc hyperx_headset_battery_desc = {
+	.name = "hyperx_headset_battery",
+	.type = POWER_SUPPLY_TYPE_BATTERY,

[Severity: Medium]
Does this static power supply name cause sysfs collisions?

If a user connects multiple identical headsets, or if the headset exposes multiple HID interfaces that bind to this driver, the second instance will fail to register with a -EEXIST error.

Could this be dynamically allocated, perhaps using devm_kasprintf with hdev->uniq or a counter, to ensure each device gets a unique name?

Quoted 4 lines
drivers/hid/hid-hyperx-headset.c new file +4 -0
+	.properties = hyperx_headset_battery_props,
+	.num_properties = ARRAY_SIZE(hyperx_headset_battery_props),
+	.get_property = hyperx_headset_battery_get_property,
+};

[ ... ]

Quoted 3 lines
drivers/hid/hid-hyperx-headset.c new file +3 -0
+static int hyperx_headset_probe(struct hid_device *hdev,
+				const struct hid_device_id *id)
+{

[ ... ]

drivers/hid/hid-hyperx-headset.c line 300

Quoted 11 lines
drivers/hid/hid-hyperx-headset.c new file +11 -0
+	ret = hid_parse(hdev);
+	if (ret != 0) {
+		hid_err(hdev, "parse failed\n");
+		return ret;
+	}
+
+	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+	if (ret != 0) {
+		hid_err(hdev, "hw_start failed\n");
+		return ret;
+	}

[Severity: High]
Can this error path leak pending work items?

The hid_hw_start() call initializes the low-level driver, which can immediately start receiving hardware interrupts before completing the logical HID connection.

If a packet arrives during this window, hyperx_headset_raw_event() can schedule drvdata->battery_work.

If hid_hw_start() fails and returns an error, the function exits without calling cancel_work_sync(&drvdata->battery_work). The drvdata structure is then freed by devres, leaving a pending work item that will dereference freed memory when it executes.

Should the error path ensure background work is cancelled before returning?

Quoted 5 lines
drivers/hid/hid-hyperx-headset.c new file +5 -0
+
+	schedule_delayed_work(&drvdata->poll_work, 0);
+
+	return 0;
+}

[ ... ]

drivers/hid/hid-hyperx-headset.c line 345

Quoted 7 lines
drivers/hid/hid-hyperx-headset.c new file +7 -0
+static void hyperx_headset_remove(struct hid_device *hdev)
+{
+	struct hyperx_headset_device *drvdata = hid_get_drvdata(hdev);
+
+	if (drvdata) {
+		cancel_delayed_work_sync(&drvdata->poll_work);
+		cancel_work_sync(&drvdata->battery_work);

[Severity: High]
Could this teardown sequence result in re-queued work?

The driver calls cancel_work_sync() before calling hid_hw_stop(). This leaves a window where the hardware is still active and can generate interrupts after the work queues have been canceled.

If a device state change event arrives during this window, hyperx_headset_raw_event() will call schedule_work(&drvdata->battery_work).

When hyperx_headset_remove() completes, devres frees the drvdata structure. The incorrectly re-queued work item will execute later, dereferencing the freed drvdata memory.

Should hid_hw_stop() be called before cancelling the work queues?

drivers/hid/hid-hyperx-headset.c line 350

Quoted 5 lines
drivers/hid/hid-hyperx-headset.c new file +5 -0
+
+		if (drvdata->battery) {
+			power_supply_unregister(drvdata->battery);
+			drvdata->battery = NULL;
+		}

[Severity: High]
Is it safe to access and clear drvdata->battery here without holding drvdata->lock?

If an interrupt arrives concurrently, hyperx_headset_raw_event() will acquire the lock, observe a non-null drvdata->battery, and call power_supply_changed(drvdata->battery).

Since power_supply_unregister() can concurrently drop the device reference and free the structure, power_supply_changed() might access freed memory.

Should the pointer be cleared to null under the spinlock before unregistering, similar to how it is handled in hyperx_headset_battery_work()?

Quoted 4 lines
drivers/hid/hid-hyperx-headset.c new file +4 -0
+	}
+
+	hid_hw_stop(hdev);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1