Skip to contentSkip to conversation

HID: add driver for Gigabyte Aero vendor-specific brightness keys

PATCH Superseded Uddhav Swami 2 participants 9 messages Jul 15 – Oct 3 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: add driver for Gigabyte Aero vendor-specific brightness keys

The Gigabyte Aero 15 XB keyboard (Chu Yuen Enterprise Co., Ltd, USB ID 1044:7a3f) sends brightness up/down keypresses as vendor-defined HID reports (Usage Page 0xFF02, Report ID 4) rather than standard HID Consumer Control usages, causing KEY_BRIGHTNESSUP and KEY_BRIGHTNESSDOWN to never reach the input subsystem.

Add a minimal HID driver that intercepts Report ID 4 and maps values 0x7D and 0x7E to KEY_BRIGHTNESSDOWN and KEY_BRIGHTNESSUP respectively.

Tested on: Gigabyte Aero 15 XB (USB ID 1044:7a3f)

---
 drivers/hid/Kconfig        |  10 +++
 drivers/hid/Makefile       |   1 +
 drivers/hid/hid-gigabyte.c | 127 +++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h      |   5 +-
 4 files changed, 141 insertions(+), 2 deletions(-)
 create mode 100644 drivers/hid/hid-gigabyte.c
drivers/hid/Kconfig +10 -0
index 03f36899e458..fa74e67e35c8 100644
@@ -406,6 +406,16 @@ config HID_GFRM
 	help
 	Support for Google Fiber TV Box remote controls
 
+config HID_GIGABYTE_AERO
+	tristate "Gigabyte Aero laptop vendor-specific keys"
+	depends on USB_HID
+	help
+	  Support for vendor-specific keyboard keys on Gigabyte Aero
+	  laptops
+
+	  Currently the following device is known to be supported:
+	   - Gigabyte Aero 15 XB
+
 config HID_GLORIOUS
 	tristate "Glorious PC Gaming Race mice"
 	help
drivers/hid/Makefile +1 -0
index 23e6e3dd0c56..ef3a14b04126 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_HID_EZKEY)		+= hid-ezkey.o
 obj-$(CONFIG_HID_FT260)		+= hid-ft260.o
 obj-$(CONFIG_HID_GEMBIRD)	+= hid-gembird.o
 obj-$(CONFIG_HID_GFRM)		+= hid-gfrm.o
+obj-$(CONFIG_HID_GIGABYTE_AERO)	+= hid-gigabyte.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o
 obj-$(CONFIG_HID_GOODIX_SPI)	+= hid-goodix-spi.o
drivers/hid/hid-gigabyte.c new file +127 -0

127 lines not on this page · raw message

drivers/hid/hid-ids.h +3 -2
index b70f719b3b07..e33cdf33929b 100644
@@ -330,6 +330,9 @@
 #define USB_VENDOR_ID_CHUNGHWAT		0x2247
 #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH	0x0001
 
+#define USB_VENDOR_ID_CHU_YUEN			0x1044
+#define USB_DEVICE_ID_CHU_YUEN_AERO_KBD		0x7a3f
+
 #define USB_VENDOR_ID_CIDC		0x1677
 
 #define I2C_VENDOR_ID_CIRQUE           0x0488
@@ -1319,7 +1322,6 @@
 #define USB_DEVICE_ID_SMK_NSG_MR5U_REMOTE       0x0368
 #define USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE       0x0369
 
-
 #define USB_VENDOR_ID_SONY			0x054c
 #define USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE	0x024b
 #define USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE	0x0374
@@ -1610,7 +1612,6 @@
 #define USB_DEVICE_ID_PRIMAX_PIXART_MOUSE_4D65	0x4d65
 #define USB_DEVICE_ID_PRIMAX_PIXART_MOUSE_4E22	0x4e22
 
-
 #define USB_VENDOR_ID_RISO_KAGAKU	0x1294	/* Riso Kagaku Corp. */
 #define USB_DEVICE_ID_RI_KA_WEBMAIL	0x1320	/* Webmail Notifier */
 
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Dangling pointer in `drvdata->input` leads to Use-After-Free if `hidinput_connect()` fails during…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Dangling pointer in drvdata->input leads to Use-After-Free if hidinput_connect() fails during device probe. --

--- Patch [1]: [PATCH] HID: add driver for Gigabyte Aero vendor-specific brightness keys --- commit 1b9632575a5f9cf3b6d4d94e30945e582cc34a94
Author: Uddhav Swami <[email protected]>

HID: add driver for Gigabyte Aero vendor-specific brightness keys

This commit adds a minimal HID driver that intercepts vendor-defined HID reports for the Gigabyte Aero 15 XB keyboard. It maps values 0x7D and 0x7E to KEY_BRIGHTNESSDOWN and KEY_BRIGHTNESSUP respectively.

Quoted 6 lines
drivers/hid/hid-gigabyte.c new file +0 -0
new file mode 100644
index 0000000000000..1c242734aed3f
@@ -0,0 +1,127 @@

[ ... ]

drivers/hid/hid-gigabyte.c line 79

Quoted 10 lines
drivers/hid/hid-gigabyte.c new file +10 -0
+static int gigabyte_aero_input_configured(struct hid_device *hdev,
+					  struct hid_input *hi)
+{
+	struct gigabyte_drvdata *drvdata = hid_get_drvdata(hdev);
+	struct input_dev *input = hi->input;
+
+	input_set_capability(input, EV_KEY, KEY_BRIGHTNESSUP);
+	input_set_capability(input, EV_KEY, KEY_BRIGHTNESSDOWN);
+
+	drvdata->input = input;

[Severity: High]
Can drvdata->input become a dangling pointer here if input registration fails?

If hidinput_connect() fails later during the probe sequence (for example, if input_register_device() fails), hidinput_disconnect() will be called and it frees the input_dev.

However, because this driver implements a .raw_event callback, hid_connect() will still return success. This allows hid_hw_start() to return 0 and the probe to complete successfully.

If that happens, drvdata->input is left pointing to the freed input_dev, which will trigger a use-after-free in gigabyte_aero_raw_event() when a brightness key is pressed:

	case GIGABYTE_AERO_BRIGHTNESS_DOWN:
		input_report_key(drvdata->input, KEY_BRIGHTNESSDOWN, 1);

Could we avoid this by checking if (hdev->claimed & HID_CLAIMED_INPUT) is set after hid_hw_start() completes in gigabyte_aero_probe()?

Quoted 3 lines
drivers/hid/hid-gigabyte.c new file +3 -0
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v2 1/1 HID: add driver for Gigabyte Aero vendor-specific brightness keys

In reply to Uddhav Swami

The Gigabyte Aero 15 XB keyboard (Chu Yuen Enterprise Co., Ltd, USB ID 1044:7a3f) sends brightness up/down keypresses as vendor-defined HID reports (Usage Page 0xFF02, Report ID 4) rather than standard HID Consumer Control usages, causing KEY_BRIGHTNESSUP and KEY_BRIGHTNESSDOWN to never reach the input subsystem.

Add a minimal HID driver that intercepts Report ID 4 and maps values 0x7D and 0x7E to KEY_BRIGHTNESSDOWN and KEY_BRIGHTNESSUP respectively.

Tested on: Gigabyte Aero 15 XB (USB ID 1044:7a3f)

---
v2: Check HID_CLAIMED_INPUT after hid_hw_start() to avoid potential
use-after-free if input_register_device() fails during probe. Reported by Sashiko.

 drivers/hid/Kconfig        |  10 +++
 drivers/hid/Makefile       |   1 +
 drivers/hid/hid-gigabyte.c | 133 +++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h      |   5 +-
 4 files changed, 147 insertions(+), 2 deletions(-)
 create mode 100644 drivers/hid/hid-gigabyte.c
drivers/hid/Kconfig +10 -0
index 03f36899e458..fa74e67e35c8 100644
@@ -406,6 +406,16 @@ config HID_GFRM
 	help
 	Support for Google Fiber TV Box remote controls
 
+config HID_GIGABYTE_AERO
+	tristate "Gigabyte Aero laptop vendor-specific keys"
+	depends on USB_HID
+	help
+	  Support for vendor-specific keyboard keys on Gigabyte Aero
+	  laptops
+
+	  Currently the following device is known to be supported:
+	   - Gigabyte Aero 15 XB
+
 config HID_GLORIOUS
 	tristate "Glorious PC Gaming Race mice"
 	help
drivers/hid/Makefile +1 -0
index 23e6e3dd0c56..ef3a14b04126 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_HID_EZKEY)		+= hid-ezkey.o
 obj-$(CONFIG_HID_FT260)		+= hid-ft260.o
 obj-$(CONFIG_HID_GEMBIRD)	+= hid-gembird.o
 obj-$(CONFIG_HID_GFRM)		+= hid-gfrm.o
+obj-$(CONFIG_HID_GIGABYTE_AERO)	+= hid-gigabyte.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o
 obj-$(CONFIG_HID_GOODIX_SPI)	+= hid-goodix-spi.o
drivers/hid/hid-gigabyte.c new file +133 -0

133 lines not on this page · raw message

drivers/hid/hid-ids.h +3 -2
index b70f719b3b07..e33cdf33929b 100644
@@ -330,6 +330,9 @@
 #define USB_VENDOR_ID_CHUNGHWAT		0x2247
 #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH	0x0001
 
+#define USB_VENDOR_ID_CHU_YUEN			0x1044
+#define USB_DEVICE_ID_CHU_YUEN_AERO_KBD		0x7a3f
+
 #define USB_VENDOR_ID_CIDC		0x1677
 
 #define I2C_VENDOR_ID_CIRQUE           0x0488
@@ -1319,7 +1322,6 @@
 #define USB_DEVICE_ID_SMK_NSG_MR5U_REMOTE       0x0368
 #define USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE       0x0369
 
-
 #define USB_VENDOR_ID_SONY			0x054c
 #define USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE	0x024b
 #define USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE	0x0374
@@ -1610,7 +1612,6 @@
 #define USB_DEVICE_ID_PRIMAX_PIXART_MOUSE_4D65	0x4d65
 #define USB_DEVICE_ID_PRIMAX_PIXART_MOUSE_4E22	0x4e22
 
-
 #define USB_VENDOR_ID_RISO_KAGAKU	0x1294	/* Riso Kagaku Corp. */
 #define USB_DEVICE_ID_RI_KA_WEBMAIL	0x1320	/* Webmail Notifier */
 
Signature · 1 line
2.55.0
#3 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Unconditional capability mapping forces the registration of all hid_inputs and unpredictably…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Unconditional capability mapping forces the registration of all hid_inputs and unpredictably overwrites drvdata->input.
- [Low] Uses 'ret' instead of 'error' or 'err' for error variable.
--

--- Patch [1]: [PATCH v2] HID: add driver for Gigabyte Aero vendor-specific brightness keys --- commit a88dff22dbe03f72cc6b7e002b5c019c9cd1010f
Author: Uddhav Swami <[email protected]>

HID: add driver for Gigabyte Aero vendor-specific brightness keys

This patch intercepts vendor-defined HID reports for brightness keys on Gigabyte Aero laptops and maps them to standard KEY_BRIGHTNESSUP and KEY_BRIGHTNESSDOWN input events.

Quoted 5 lines
drivers/hid/hid-gigabyte.c new file +0 -0
new file mode 100644
index 0000000000000..3f0c9a1b6bc1d

[ ... ]

drivers/hid/hid-gigabyte.c line 79

Quoted 10 lines
drivers/hid/hid-gigabyte.c new file +10 -0
+static int gigabyte_aero_input_configured(struct hid_device *hdev,
+					  struct hid_input *hi)
+{
+	struct gigabyte_drvdata *drvdata = hid_get_drvdata(hdev);
+	struct input_dev *input = hi->input;
+
+	input_set_capability(input, EV_KEY, KEY_BRIGHTNESSUP);
+	input_set_capability(input, EV_KEY, KEY_BRIGHTNESSDOWN);
+
+	drvdata->input = input;

[Severity: Medium]
Does this code accidentally force the registration of all hid_inputs?

Since capabilities are applied unconditionally to every hid_input application exposed by the device, it appears this defeats the HID core's hidinput_has_been_populated() check. This could result in dummy input devices being registered for collections that have no mapped usages and would otherwise be cleaned up.

Also, because drvdata->input is unconditionally overwritten on every callback during device probe, will brightness events be unpredictably routed to whichever hid_input happened to be parsed last by the HID core?

drivers/hid/hid-gigabyte.c line 88

Quoted 9 lines
drivers/hid/hid-gigabyte.c new file +9 -0
+
+	return 0;
+}
+
+static int gigabyte_aero_probe(struct hid_device *hdev,
+			       const struct hid_device_id *id)
+{
+	struct gigabyte_drvdata *drvdata;
+	int ret;

[Severity: Low]
This isn't a bug, but could we use a different variable name here?

The input subsystem maintainer preferences suggest using 'error' or 'err' for variables that hold only negative error codes and 0 for success, rather than 'ret'.

Quoted 4 lines
drivers/hid/hid-gigabyte.c new file +4 -0
+
+	drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata)
+		return -ENOMEM;

[ ... ]

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

PATCH v3 1/1 HID: add driver for Gigabyte Aero vendor-specific brightness keys

In reply to Uddhav Swami

The Gigabyte Aero 15 XB keyboard (Chu Yuen Enterprise Co., Ltd, USB ID 1044:7a3f) sends brightness up/down keypresses as vendor-defined HID reports (Usage Page 0xFF02, Report ID 4) rather than standard HID Consumer Control usages, causing KEY_BRIGHTNESSUP and KEY_BRIGHTNESSDOWN to never reach the input subsystem.

Add a minimal HID driver that intercepts Report ID 4 and maps values 0x7D and 0x7E to KEY_BRIGHTNESSDOWN and KEY_BRIGHTNESSUP respectively.

Tested on: Gigabyte Aero 15 XB (USB ID 1044:7a3f)

---
v3:
- Restrict registration of brightness key capabilities to only the hid_input containing GIGABYTE_AERO_REPORT_ID, avoiding the registration of redundant/dummy input devices for other collections (reported by Sashiko).
- Scan the hi->reports list to find the report, as hi->report is NULL unless HID_QUIRK_MULTI_INPUT is set.
- Rename the error return variable in gigabyte_aero_probe() from 'ret' to 'error' to follow input subsystem conventions.

v2:
- Check HID_CLAIMED_INPUT after hid_hw_start() to avoid potential use-after-free if input_register_device() fails during probe. Reported by Sashiko.

 drivers/hid/Kconfig        |  10 +++
 drivers/hid/Makefile       |   1 +
 drivers/hid/hid-gigabyte.c | 144 +++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h      |   5 +-
 4 files changed, 158 insertions(+), 2 deletions(-)
 create mode 100644 drivers/hid/hid-gigabyte.c
drivers/hid/Kconfig +10 -0
index 03f36899e458..fa74e67e35c8 100644
@@ -406,6 +406,16 @@ config HID_GFRM
 	help
 	Support for Google Fiber TV Box remote controls
 
+config HID_GIGABYTE_AERO
+	tristate "Gigabyte Aero laptop vendor-specific keys"
+	depends on USB_HID
+	help
+	  Support for vendor-specific keyboard keys on Gigabyte Aero
+	  laptops
+
+	  Currently the following device is known to be supported:
+	   - Gigabyte Aero 15 XB
+
 config HID_GLORIOUS
 	tristate "Glorious PC Gaming Race mice"
 	help
drivers/hid/Makefile +1 -0
index 23e6e3dd0c56..ef3a14b04126 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_HID_EZKEY)		+= hid-ezkey.o
 obj-$(CONFIG_HID_FT260)		+= hid-ft260.o
 obj-$(CONFIG_HID_GEMBIRD)	+= hid-gembird.o
 obj-$(CONFIG_HID_GFRM)		+= hid-gfrm.o
+obj-$(CONFIG_HID_GIGABYTE_AERO)	+= hid-gigabyte.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o
 obj-$(CONFIG_HID_GOODIX_SPI)	+= hid-goodix-spi.o
drivers/hid/hid-gigabyte.c new file +144 -0

144 lines not on this page · raw message

drivers/hid/hid-ids.h +3 -2
index b70f719b3b07..e33cdf33929b 100644
@@ -330,6 +330,9 @@
 #define USB_VENDOR_ID_CHUNGHWAT		0x2247
 #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH	0x0001
 
+#define USB_VENDOR_ID_CHU_YUEN			0x1044
+#define USB_DEVICE_ID_CHU_YUEN_AERO_KBD		0x7a3f
+
 #define USB_VENDOR_ID_CIDC		0x1677
 
 #define I2C_VENDOR_ID_CIRQUE           0x0488
@@ -1319,7 +1322,6 @@
 #define USB_DEVICE_ID_SMK_NSG_MR5U_REMOTE       0x0368
 #define USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE       0x0369
 
-
 #define USB_VENDOR_ID_SONY			0x054c
 #define USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE	0x024b
 #define USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE	0x0374
@@ -1610,7 +1612,6 @@
 #define USB_DEVICE_ID_PRIMAX_PIXART_MOUSE_4D65	0x4d65
 #define USB_DEVICE_ID_PRIMAX_PIXART_MOUSE_4E22	0x4e22
 
-
 #define USB_VENDOR_ID_RISO_KAGAKU	0x1294	/* Riso Kagaku Corp. */
 #define USB_DEVICE_ID_RI_KA_WEBMAIL	0x1320	/* Webmail Notifier */
 
Signature · 1 line
2.55.0
#5 lore raw

Hi Jiri, Benjamin,

Gentle ping on this patch. Happy to address any feedback.

Thanks,
Uddhav

#6 lore raw

PATCH v4 1/1 HID: chuyuen: add driver for vendor-specific brightness keys

In reply to Uddhav Swami

The Gigabyte Aero 15 XB keyboard (Chu Yuen Enterprise Co., Ltd, USB ID 1044:7a3f) sends brightness up/down keypresses as vendor-defined HID reports (Usage Page 0xFF02, Report ID 4) rather than standard HID Consumer Control usages, causing KEY_BRIGHTNESSUP and KEY_BRIGHTNESSDOWN to never reach the input subsystem.

Add a minimal HID driver that intercepts Report ID 4 and maps values 0x7D and 0x7E to KEY_BRIGHTNESSDOWN and KEY_BRIGHTNESSUP respectively.

Tested on: Gigabyte Aero 15 XB (USB ID 1044:7a3f)

---
v4:
- Rename driver from hid-gigabyte to hid-chuyuen (and Kconfig symbol HID_GIGABYTE_AERO to HID_CHUYUEN, module name to hid_chuyuen) to follow the hid-<vendor> naming convention, since Chu Yuen Enterprise is the actual USB vendor, not Gigabyte. (Jiri)
v3:
- Fix a NULL pointer dereference: hi->report can be NULL for some hid_input instances. Iterate hi->reports via list_for_each_entry() on hidinput_list to find report ID 0x04 before setting capabilities.
- Rename local variable ret to error in probe for clarity. v2:
- Fix a use-after-free: check HID_CLAIMED_INPUT after hid_hw_start() to catch a failed input_register_device().

 drivers/hid/Kconfig       |  10 +++
 drivers/hid/Makefile      |   1 +
 drivers/hid/hid-chuyuen.c | 145 ++++++++++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h     |   3 +
 4 files changed, 159 insertions(+)
 create mode 100644 drivers/hid/hid-chuyuen.c
drivers/hid/Kconfig +10 -0
index 03f36899e458..6647434d5adf 100644
@@ -243,6 +243,16 @@ config HID_CHICONY
 	help
 	Support for Chicony Tactical pad and special keys on Chicony keyboards.
 
+config HID_CHUYUEN
+	tristate "Chu Yuen Aero laptop vendor-specific keys"
+	depends on USB_HID
+	help
+	  Support for vendor-specific keyboard keys on Chu Yuen keyboards
+	  found in Gigabyte Aero laptops.
+
+	  Currently the following device is known to be supported:
+	   - Gigabyte Aero 15 XB
+
 config HID_CORSAIR
 	tristate "Corsair devices"
 	depends on USB_HID && LEDS_CLASS
drivers/hid/Makefile +1 -0
index 23e6e3dd0c56..7f7503261b4f 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_HID_BETOP_FF)	+= hid-betopff.o
 obj-$(CONFIG_HID_BIGBEN_FF)	+= hid-bigbenff.o
 obj-$(CONFIG_HID_CHERRY)	+= hid-cherry.o
 obj-$(CONFIG_HID_CHICONY)	+= hid-chicony.o
+obj-$(CONFIG_HID_CHUYUEN)	+= hid-chuyuen.o
 obj-$(CONFIG_HID_CMEDIA)	+= hid-cmedia.o
 obj-$(CONFIG_HID_CORSAIR)	+= hid-corsair.o hid-corsair-void.o
 obj-$(CONFIG_HID_COUGAR)	+= hid-cougar.o
drivers/hid/hid-chuyuen.c new file +145 -0

145 lines not on this page · raw message

drivers/hid/hid-ids.h +3 -0
index b70f719b3b07..b6bca8d8d94d 100644
@@ -330,6 +330,9 @@
 #define USB_VENDOR_ID_CHUNGHWAT		0x2247
 #define USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH	0x0001
 
+#define USB_VENDOR_ID_CHU_YUEN			0x1044
+#define USB_DEVICE_ID_CHU_YUEN_AERO_KBD		0x7a3f
+
 #define USB_VENDOR_ID_CIDC		0x1677
 
 #define I2C_VENDOR_ID_CIRQUE           0x0488
Signature · 1 line
2.55.0
#7 lore raw

Re: [PATCH v4] HID: chuyuen: add driver for vendor-specific brightness keys

Hi Jiri, Benjamin,

Gentle ping on this patch. v4 renames the driver to hid-chuyuen as Jiri suggested.

Thanks,
Uddhav