Skip to contentSkip to conversation

HID: asus: add support for ROG Ally handhelds

PATCH Superseded Denis Benato 6 participants 52 messages Oct 25 – Oct 31 Page 2 of 2

Subsystems (3)

v11 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#34 lore raw

Re: [PATCH v11 11/18] HID: asus: add support for btn remapping

In reply to Ilpo Järvinen
Quoted 281 lines · Ilpo Järvinen
Quoted 279 lines · Denis Benato
Quoted 278 lines · Ilpo Järvinen
Quoted 264 lines · Denis Benato

Add support for buttons remapping: the ability to assign different button events to each one of the physical button on the device.

Each button exposes a remap_index sysfs attribute listing the valid remap target names for the current gamepad mode: M1 and M2 can be remapped to anything at any time, while other buttons may only be remapped to gamepad codes in gamepad mode and keyboard/mouse/media codes in desktop mode.

When the gamepad mode is changed the firmware automatically restores its internal defaults, so the software cache is refreshed to reflect the hardware state.

---
 drivers/hid/hid-asus.c | 1059 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 1037 insertions(+), 22 deletions(-)
drivers/hid/hid-asus.c +205 -1
index ed95b2cdec81..ea27495c3df6 100644
@@ -275,9 +275,25 @@ struct ally_turbo_config {
 	struct ally_btn_turbo_params btn_m1;
 };
 
+/* Button remap attribute structure */
+struct button_remap_attr {
+	struct device_attribute dev_attr;
+	enum ally_button_id button_id;
+	bool is_macro;
+	/*
+	 * The attributes are created while hid_asus_ally_probe() is still
+	 * running, before asus_probe() publishes drvdata->rog_ally: carry
+	 * the pointer like the turbo entries do, so the callbacks work
+	 * from the moment the files exist.
+	 */
+	struct ally_handheld *ally;
+};
+
+#define to_button_remap_attr(x) container_of(x, struct button_remap_attr, dev_attr)
+
 struct ally_btn_sysfs_entry {
 	struct attribute_group group;
-	struct attribute *attrs[5]; /* turbo_period + toggle_period + ranges + NULL */
+	struct attribute *attrs[8]; /* turbo + ranges + remap + macro + remap_index + NULL */
 	/*
 	 * The entries are created while hid_asus_ally_probe() is still running,
 	 * before asus_probe() publishes drvdata->rog_ally: carrying the shared
@@ -289,6 +305,9 @@ struct ally_btn_sysfs_entry {
 	enum ally_button_id btn;
 	struct device_attribute attr_turbo_period;
 	struct device_attribute attr_toggle_period;
+	struct button_remap_attr *remap_attr;
+	struct button_remap_attr *macro_attr;
+	struct device_attribute attr_remap_index;
 };
 
 enum ally_gamepad_mode_index {
@@ -296,6 +315,35 @@ enum ally_gamepad_mode_index {
 	ALLY_GAMEPAD_MODE_KEYBOARD = 0x02,
 };
 
+/* Button pair indexes for mapping commands */
+enum btn_pair_index {
+	BTN_PAIR_DPAD_UPDOWN    = 0x01,
+	BTN_PAIR_DPAD_LEFTRIGHT = 0x02,
+	BTN_PAIR_STICK_LR       = 0x03,
+	BTN_PAIR_BUMPER_LR      = 0x04,
+	BTN_PAIR_AB             = 0x05,
+	BTN_PAIR_XY             = 0x06,
+	BTN_PAIR_VIEW_MENU      = 0x07,
+	BTN_PAIR_M1M2           = 0x08,
+	BTN_PAIR_TRIGGER_LR     = 0x09,
+};
+
+struct button_map {
+	const struct btn_code_map *remap;
+	const struct btn_code_map *macro;
+};
+
+struct button_pair_map {
+	enum btn_pair_index pair_index;
+	struct button_map first;
+	struct button_map second;
+};
+
+/* Store button mapping per gamepad mode */
+struct ally_button_mapping {
+	struct button_pair_map button_pairs[9]; /* 9 button pairs */
+};
+
 struct ally_config {
 	/* Must be locked if the data is being changed */
 	struct mutex config_mutex;
@@ -331,6 +379,8 @@ struct ally_config {
 
 	struct ally_turbo_config turbo;
 	struct ally_btn_sysfs_entry *button_entries;
+	/* Button mappings of the current gamepad mode */
+	struct ally_button_mapping button_mappings;
 
 	struct ally_joystick_resp_curve left_curve;
 	struct ally_joystick_resp_curve right_curve;
@@ -1072,6 +1122,295 @@ static int ally_set_gamepad_mode(struct ally_handheld *ally, struct hid_device *
 	return 0;
 }
 
+enum btn_map_type {
+	BTN_TYPE_NONE = 0,
+	BTN_TYPE_PAD = 0x01,
+	BTN_TYPE_KB = 0x02,
+	BTN_TYPE_MOUSE = 0x03,
+	BTN_TYPE_MEDIA = 0x05,
+};
+
+struct btn_code_map {
+	unsigned char type;
+	unsigned char value;
+	const char *name;
+};
+
+static const struct btn_code_map ally_btn_codes[] = {
+	{ BTN_TYPE_NONE, 0x00, "NONE" },
+	/* Gamepad button codes */
+	{ BTN_TYPE_PAD, 0x01, "BTN_SOUTH" },
+	{ BTN_TYPE_PAD, 0x02, "BTN_EAST" },
+	{ BTN_TYPE_PAD, 0x03, "BTN_NORTH" },
+	{ BTN_TYPE_PAD, 0x04, "BTN_WEST" },
+	{ BTN_TYPE_PAD, 0x05, "BTN_TL" },
+	{ BTN_TYPE_PAD, 0x06, "BTN_TR" },
+	{ BTN_TYPE_PAD, 0x07, "BTN_THUMBL" },
+	{ BTN_TYPE_PAD, 0x08, "BTN_THUMBR" },
+	{ BTN_TYPE_PAD, 0x09, "ABS_HAT0Y_NEG" },
+	{ BTN_TYPE_PAD, 0x0A, "ABS_HAT0Y_POS" },
+	{ BTN_TYPE_PAD, 0x0B, "ABS_HAT0X_NEG" },
+	{ BTN_TYPE_PAD, 0x0C, "ABS_HAT0X_POS" },
+	{ BTN_TYPE_PAD, 0x0D, "ABS_Z" },
+	{ BTN_TYPE_PAD, 0x0E, "ABS_RZ" },
+	{ BTN_TYPE_PAD, 0x11, "BTN_SELECT" },
+	{ BTN_TYPE_PAD, 0x12, "BTN_START" },
+	{ BTN_TYPE_PAD, 0x13, "BTN_MODE" },
+
+	/* Keyboard button codes */
+	{ BTN_TYPE_KB, 0x8E, "FN_M2" },
+	{ BTN_TYPE_KB, 0x8F, "FN_M1" },
+	{ BTN_TYPE_KB, 0x76, "KEY_ESC" },
+	{ BTN_TYPE_KB, 0x05, "KEY_F1" },
+	{ BTN_TYPE_KB, 0x06, "KEY_F2" },
+	{ BTN_TYPE_KB, 0x04, "KEY_F3" },
+	{ BTN_TYPE_KB, 0x0C, "KEY_F4" },
+	{ BTN_TYPE_KB, 0x03, "KEY_F5" },
+	{ BTN_TYPE_KB, 0x0B, "KEY_F6" },
+	{ BTN_TYPE_KB, 0x80, "KEY_F7" },
+	{ BTN_TYPE_KB, 0x0A, "KEY_F8" },
+	{ BTN_TYPE_KB, 0x01, "KEY_F9" },
+	{ BTN_TYPE_KB, 0x09, "KEY_F10" },
+	{ BTN_TYPE_KB, 0x78, "KEY_F11" },
+	{ BTN_TYPE_KB, 0x07, "KEY_F12" },
+	{ BTN_TYPE_KB, 0x08, "KEY_F13" },
+	{ BTN_TYPE_KB, 0x10, "KEY_F14" },
+	{ BTN_TYPE_KB, 0x18, "KEY_F15" },
+	{ BTN_TYPE_KB, 0x0E, "KEY_GRAVE" }, // backtick
+	{ BTN_TYPE_KB, 0x16, "KEY_1" },
+	{ BTN_TYPE_KB, 0x1E, "KEY_2" },
+	{ BTN_TYPE_KB, 0x26, "KEY_3" },
+	{ BTN_TYPE_KB, 0x25, "KEY_4" },
+	{ BTN_TYPE_KB, 0x2E, "KEY_5" },
+	{ BTN_TYPE_KB, 0x36, "KEY_6" },
+	{ BTN_TYPE_KB, 0x3D, "KEY_7" },
+	{ BTN_TYPE_KB, 0x3E, "KEY_8" },
+	{ BTN_TYPE_KB, 0x46, "KEY_9" },
+	{ BTN_TYPE_KB, 0x45, "KEY_0" },
+	{ BTN_TYPE_KB, 0x4E, "KEY_MINUS" }, // hyphen
+	{ BTN_TYPE_KB, 0x55, "KEY_EQUAL" },
+	{ BTN_TYPE_KB, 0x66, "KEY_BACKSPACE" },
+	{ BTN_TYPE_KB, 0x0D, "KEY_TAB" },
+	{ BTN_TYPE_KB, 0x15, "KEY_Q" },
+	{ BTN_TYPE_KB, 0x1D, "KEY_W" },
+	{ BTN_TYPE_KB, 0x24, "KEY_E" },
+	{ BTN_TYPE_KB, 0x2D, "KEY_R" },
+	{ BTN_TYPE_KB, 0x2C, "KEY_T" },
+	{ BTN_TYPE_KB, 0x35, "KEY_Y" },
+	{ BTN_TYPE_KB, 0x3C, "KEY_U" },
+	{ BTN_TYPE_KB, 0x43, "KEY_I" },
+	{ BTN_TYPE_KB, 0x44, "KEY_O" },
+	{ BTN_TYPE_KB, 0x4D, "KEY_P" },
+	{ BTN_TYPE_KB, 0x54, "KEY_LEFTBRACE" },
+	{ BTN_TYPE_KB, 0x5B, "KEY_RIGHTBRACE" },
+	{ BTN_TYPE_KB, 0x5D, "KEY_BACKSLASH" },
+	{ BTN_TYPE_KB, 0x58, "KEY_CAPSLOCK" },
+	{ BTN_TYPE_KB, 0x1C, "KEY_A" },
+	{ BTN_TYPE_KB, 0x1B, "KEY_S" },
+	{ BTN_TYPE_KB, 0x23, "KEY_D" },
+	{ BTN_TYPE_KB, 0x2B, "KEY_F" },
+	{ BTN_TYPE_KB, 0x34, "KEY_G" },
+	{ BTN_TYPE_KB, 0x33, "KEY_H" },
+	{ BTN_TYPE_KB, 0x3B, "KEY_J" },
+	{ BTN_TYPE_KB, 0x42, "KEY_K" },
+	{ BTN_TYPE_KB, 0x4B, "KEY_L" },
+	{ BTN_TYPE_KB, 0x4C, "KEY_SEMICOLON" },
+	{ BTN_TYPE_KB, 0x52, "KEY_APOSTROPHE" },
+	{ BTN_TYPE_KB, 0x5A, "KEY_ENTER" },
+	{ BTN_TYPE_KB, 0x88, "KEY_LEFTSHIFT" },
+	{ BTN_TYPE_KB, 0x1A, "KEY_Z" },
+	{ BTN_TYPE_KB, 0x22, "KEY_X" },
+	{ BTN_TYPE_KB, 0x21, "KEY_C" },
+	{ BTN_TYPE_KB, 0x2A, "KEY_V" },
+	{ BTN_TYPE_KB, 0x32, "KEY_B" },
+	{ BTN_TYPE_KB, 0x31, "KEY_N" },
+	{ BTN_TYPE_KB, 0x3A, "KEY_M" },
+	{ BTN_TYPE_KB, 0x41, "KEY_COMMA" },
+	{ BTN_TYPE_KB, 0x49, "KEY_DOT" },
+	{ BTN_TYPE_KB, 0x4A, "KEY_SLASH" },
+	{ BTN_TYPE_KB, 0x89, "KEY_RIGHTSHIFT" },
+	{ BTN_TYPE_KB, 0x82, "KEY_LEFTMETA" },
+	{ BTN_TYPE_KB, 0x8A, "KEY_LEFTALT" },
+	{ BTN_TYPE_KB, 0x29, "KEY_SPACE" },
+	{ BTN_TYPE_KB, 0x8B, "KEY_RIGHTALT" },
+	{ BTN_TYPE_KB, 0x84, "KEY_COMPOSE" },
+	{ BTN_TYPE_KB, 0x8D, "KEY_RIGHTCTRL" },
+	{ BTN_TYPE_KB, 0xC3, "KEY_SYSRQ" },
+	{ BTN_TYPE_KB, 0x7E, "KEY_SCROLLLOCK" },
+	{ BTN_TYPE_KB, 0x91, "KEY_PAUSE" },
+	{ BTN_TYPE_KB, 0xC2, "KEY_INSERT" },
+	{ BTN_TYPE_KB, 0x94, "KEY_HOME" },
+	{ BTN_TYPE_KB, 0x96, "KEY_PAGEUP" },
+	{ BTN_TYPE_KB, 0xC0, "KEY_DELETE" },
+	{ BTN_TYPE_KB, 0x95, "KEY_END" },
+	{ BTN_TYPE_KB, 0x97, "KEY_PAGEDOWN" },
+	{ BTN_TYPE_KB, 0x98, "KEY_UP" },
+	{ BTN_TYPE_KB, 0x99, "KEY_DOWN" },
+	{ BTN_TYPE_KB, 0x9A, "KEY_LEFT" },
+	{ BTN_TYPE_KB, 0x9B, "KEY_RIGHT" },
+
+	/* Numpad button codes */
+	{ BTN_TYPE_KB, 0x77, "KEY_NUMLOCK" },
+	{ BTN_TYPE_KB, 0x90, "KEY_KPSLASH" },
+	{ BTN_TYPE_KB, 0x7C, "KEY_KPASTERISK" },
+	{ BTN_TYPE_KB, 0x7B, "KEY_KPMINUS" },
+	{ BTN_TYPE_KB, 0x70, "KEY_KP0" },
+	{ BTN_TYPE_KB, 0x69, "KEY_KP1" },
+	{ BTN_TYPE_KB, 0x72, "KEY_KP2" },
+	{ BTN_TYPE_KB, 0x7A, "KEY_KP3" },
+	{ BTN_TYPE_KB, 0x6B, "KEY_KP4" },
+	{ BTN_TYPE_KB, 0x73, "KEY_KP5" },
+	{ BTN_TYPE_KB, 0x74, "KEY_KP6" },
+	{ BTN_TYPE_KB, 0x6C, "KEY_KP7" },
+	{ BTN_TYPE_KB, 0x75, "KEY_KP8" },
+	{ BTN_TYPE_KB, 0x7D, "KEY_KP9" },
+	{ BTN_TYPE_KB, 0x79, "KEY_KPPLUS" },
+	{ BTN_TYPE_KB, 0x81, "KEY_KPENTER" },
+	{ BTN_TYPE_KB, 0x71, "KEY_KPDOT" },
+
+	/* Mouse button codes */
+	{ BTN_TYPE_MOUSE, 0x01, "BTN_LEFT" },
+	{ BTN_TYPE_MOUSE, 0x02, "BTN_RIGHT" },
+	{ BTN_TYPE_MOUSE, 0x03, "BTN_MIDDLE" },
+	{ BTN_TYPE_MOUSE, 0x04, "REL_WHEEL_HI_RES_UP" },
+	{ BTN_TYPE_MOUSE, 0x05, "REL_WHEEL_HI_RES_DOWN" },
+
+	/* Media button codes */

drivers/hid/hid-asus.c static int ally_set_gamepad_mode(struct ally_handheld *ally, struct hid_device * · line 1288

Quoted 10 lines
drivers/hid/hid-asus.c +10 -0
+	{ BTN_TYPE_MEDIA, 0x16, "MEDIA_SCREENSHOT" },
+	{ BTN_TYPE_MEDIA, 0x19, "MEDIA_SHOW_KEYBOARD" },
+	{ BTN_TYPE_MEDIA, 0x1C, "MEDIA_SHOW_DESKTOP" },
+	{ BTN_TYPE_MEDIA, 0x1E, "MEDIA_START_RECORDING" },
+	{ BTN_TYPE_MEDIA, 0x01, "MEDIA_MIC_OFF" },
+	{ BTN_TYPE_MEDIA, 0x02, "MEDIA_VOL_DOWN" },
+	{ BTN_TYPE_MEDIA, 0x03, "MEDIA_VOL_UP" },
+};
+
+static const size_t keymap_len = ARRAY_SIZE(ally_btn_codes);

Why is this a variable???? Can't the users just directly use ARRAY_SIZE on the array????

Quoted 5 lines
Quoted 2 lines

Not understood: you say variable, but both are const(s), isn't const the exact opposite of variable?

My point was that you should use ARRAY_SIZE(ally_btn_codes) directly in the 2 place (IIRC) instead of keymap_len. Then you can just drop keymap_len entirely.

Aaaaaahhhh... oooohhh. Okay got it now. On it, thank you!

Quoted 10 lines
Quoted 8 lines

I am stepping away for today, but I have cleaned up much of this mess.

Quoted 1 line

At v11 it's odd to find this much garbage still remaining... :-(

At a certain (late) point of the development I noticed that remapping buttons on the X applied immediately, while on my Ally 1 it had to go through apply_all old sysfs interface, so I attempted to unify them late on development, sorry.

I think my comment was a bit uncalled for anyway, but please see it in the light how much lines I had read at that point.

Don't worry, I understand very well. I reworked this patch so many times due to new discoveries, differences in ally 1 vs vs ally X and random things.....

This patch is the reason the whole driver exists and it is also the weakest spot because getting attributes out of sync with what gets emitted is super easy and no readback exists (as far as we know).

Many things made sense when I implemented them, then I had to rework, mass-replace, rework again etc... And the thing became that long thing that somehow apparently covers most of the thing (finally).

It is a bit ugly, I agree.

author maintainer
#35 lore raw

PATCH v11 12/18 HID: asus: size feature reports from the HID report descriptor

In reply to Denis Benato

From: Denis Benato <[email protected]>

The ASUS vendor protocol uses the same feature report IDs across very different devices: on N-KEY keyboards and ROG Ally report 0x5A/0x5E are 64-byte reports, while on XG Mobile stations report 0x5E is a 300-byte report. The driver currently hardcodes transfer lengths (16 bytes for the handshake, FEATURE_KBD_REPORT_SIZE for reads, ROG_XGM_REPORT_SIZE for the XG Mobile LED), which mismatches what the hardware expects and would break if a new device used yet another size for the same report ID.

Derive the transfer length of every feature report from the HID report descriptor of the device at hand:

- add asus_report_len(), which resolves a report ID to its struct hid_report and returns hid_report_len();
- asus_kbd_set_report() now zero-pads short payloads to the exact report size and rejects payloads that do not fit the report;
- add asus_kbd_get_report() and use it from asus_kbd_init() and asus_kbd_get_functions() so reads are sized per report as well;
- asus_xgm_led_set() sends a minimal payload and checks the transfer result against the descriptor length instead of the hardcoded ROG_XGM_REPORT_SIZE, which is removed along with the fixed-size buffers in asus_kbd_set_fn_lock() and asus_kbd_set_brightness().

Captured USB traffic of the same commands issued by Windows shows they are always written at the full report length, which this change now matches.

---
 drivers/hid/hid-asus.c | 148 +++++++++++++++++++++++++++++++++--------
 1 file changed, 120 insertions(+), 28 deletions(-)
drivers/hid/hid-asus.c +120 -28
index ea27495c3df6..fe2a326ccd86 100644
@@ -63,8 +63,6 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define FEATURE_KBD_LED_REPORT_ID1 0x5d
 #define FEATURE_KBD_LED_REPORT_ID2 0x5e
 
-#define ROG_XGM_REPORT_SIZE 300
-
 #define ROG_ALLY_REPORT_SIZE 64
 #define ROG_ALLY_X_MIN_MCU 313
 #define ROG_ALLY_MIN_MCU 319
@@ -658,6 +656,51 @@ static void ally_probe_release_role(int ep)
 	spin_unlock_irqrestore(&ally_data_lock, flags);
 }
 
+/**
+ * asus_find_report() - Find a report of the given type by its ID
+ * @hdev: HID device
+ * @type: report type (HID_INPUT_REPORT, HID_OUTPUT_REPORT or
+ * HID_FEATURE_REPORT)
+ * @report_id: report ID to look for
+ *
+ * Return: the report with the given ID, or NULL if the device does not
+ * declare such a report
+ */
+static struct hid_report *asus_find_report(struct hid_device *hdev,
+					   unsigned int type, u8 report_id)
+{
+	struct hid_report *report;
+
+	list_for_each_entry(report, &hdev->report_enum[type].report_list, list) {
+		if (report->id == report_id)
+			return report;
+	}
+
+	return NULL;
+}
+
+/**
+ * asus_report_len() - Length of a feature report for the device
+ * @hdev: HID device
+ * @report_id: report ID of the feature report
+ *
+ * The same ASUS report ID can have different sizes depending on the device:
+ * report 0x5E is a 64-byte report on laptops but a 300-byte report on XG
+ * Mobile stations. Always size transfers from the report descriptor of the
+ * device at hand instead of hardcoding lengths.
+ *
+ * Return: the length of the feature report in bytes, or 0 if the device
+ * does not declare the report
+ */
+static size_t asus_report_len(struct hid_device *hdev, u8 report_id)
+{
+	struct hid_report *report;
+
+	report = asus_find_report(hdev, HID_FEATURE_REPORT, report_id);
+
+	return report ? hid_report_len(report) : 0;
+}
+
 static const u8 asus_report_id_init[] = {
 	FEATURE_KBD_REPORT_ID,
 	FEATURE_KBD_LED_REPORT_ID1,
@@ -5370,18 +5413,64 @@ static int asus_raw_event(struct hid_device *hdev,
 
 static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, size_t buf_size)
 {
-	u8 *dmabuf __free(kfree) = kmemdup(buf, buf_size, GFP_KERNEL);
+	size_t hw_len = asus_report_len(hdev, buf[0]);
+
+	/* The payload (including the report ID) must fit the device report. */
+	if (!hw_len || buf_size > hw_len)
+		return -EINVAL;
+
+	u8 *dmabuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
 	if (!dmabuf)
 		return -ENOMEM;
 
+	memcpy(dmabuf, buf, buf_size);
+
 	/*
-	 * The report ID should be set from the incoming buffer due to LED and key
-	 * interfaces having different pages
+	 * The report ID should be set from the incoming buffer due to LED and
+	 * key interfaces having different pages. Short payloads are zero-padded
+	 * to the exact report size the hardware expects for this report ID.
 	 */
-	return hid_hw_raw_request(hdev, buf[0], dmabuf, buf_size, HID_FEATURE_REPORT,
+	return hid_hw_raw_request(hdev, buf[0], dmabuf, hw_len, HID_FEATURE_REPORT,
 				  HID_REQ_SET_REPORT);
 }
 
+/**
+ * asus_kbd_get_report() - Read a report sized from the descriptor
+ * @hdev: HID device
+ * @report_id: report ID to read
+ * @buf: buffer to store the report in
+ * @buf_size: size of @buf
+ *
+ * The transfer is performed at the exact report size the device declares
+ * for @report_id. The device may answer with a short read, and only the
+ * bytes that fit in @buf are copied into it.
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+static int asus_kbd_get_report(struct hid_device *hdev, u8 report_id,
+			       u8 *buf, size_t buf_size)
+{
+	size_t hw_len = asus_report_len(hdev, report_id);
+	int ret;
+
+	if (!hw_len)
+		return -EINVAL;
+
+	u8 *dmabuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
+	if (!dmabuf)
+		return -ENOMEM;
+
+	ret = hid_hw_raw_request(hdev, report_id, dmabuf, hw_len,
+				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+	if (ret < 0)
+		return ret;
+
+	/* The device may return less than requested (short read). */
+	memcpy(buf, dmabuf, min(buf_size, hw_len));
+
+	return 0;
+}
+
 static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
 {
 	/*
@@ -5390,8 +5479,13 @@ static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
 	 */
 	const u8 buf[] = { report_id, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54,
 		     0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 };
+	size_t hw_len = asus_report_len(hdev, report_id);
+	size_t cmp_len;
 	int ret;
 
+	if (!hw_len)
+		return -EINVAL;
+
 	ret = asus_kbd_set_report(hdev, buf, sizeof(buf));
 	if (ret < 0) {
 		hid_err(hdev, "Asus handshake %02x failed to send: %d\n",
@@ -5399,19 +5493,20 @@ static int asus_kbd_init(struct hid_device *hdev, u8 report_id)
 		return ret;
 	}
 
-	u8 *readbuf __free(kfree) = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL);
+	u8 *readbuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
 	if (!readbuf)
 		return -ENOMEM;
 
-	ret = hid_hw_raw_request(hdev, report_id, readbuf,
-				 FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT,
-				 HID_REQ_GET_REPORT);
+	ret = asus_kbd_get_report(hdev, report_id, readbuf, hw_len);
 	if (ret < 0) {
 		hid_warn(hdev, "Asus handshake %02x failed to receive ack: %d\n",
 			 report_id, ret);
-	} else if (memcmp(readbuf, buf, sizeof(buf)) != 0) {
-		hid_warn(hdev, "Asus handshake %02x returned invalid response: %*ph\n",
-			 report_id, FEATURE_KBD_REPORT_SIZE, readbuf);
+	} else {
+		cmp_len = min_t(size_t, sizeof(buf), hw_len);
+		if (memcmp(readbuf, buf, cmp_len) != 0) {
+			hid_warn(hdev, "Asus handshake %02x returned invalid response: %*ph\n",
+				 report_id, (int)cmp_len, readbuf);
+		}
 	}
 
 	/*
@@ -5426,7 +5521,7 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
 				  u8 report_id)
 {
 	const u8 buf[] = { report_id, 0x05, 0x20, 0x31, 0x00, 0x08 };
-	u8 *readbuf;
+	size_t hw_len = asus_report_len(hdev, report_id);
 	int ret;
 
 	ret = asus_kbd_set_report(hdev, buf, sizeof(buf));
@@ -5435,23 +5530,22 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
 		return ret;
 	}
 
-	readbuf = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL);
+	if (!hw_len)
+		return -EINVAL;
+
+	u8 *readbuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
 	if (!readbuf)
 		return -ENOMEM;
 
-	ret = hid_hw_raw_request(hdev, report_id, readbuf,
-				 FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT,
-				 HID_REQ_GET_REPORT);
+	ret = asus_kbd_get_report(hdev, report_id, readbuf, hw_len);
 	if (ret < 0) {
 		hid_err(hdev, "Asus failed to request functions: %d\n", ret);
-		kfree(readbuf);
 		return ret;
 	}
 
 	*kbd_func = readbuf[6];
 
-	kfree(readbuf);
-	return ret;
+	return 0;
 }
 
 static int asus_kbd_disable_oobe(struct hid_device *hdev)
@@ -5476,7 +5570,7 @@ static int asus_kbd_disable_oobe(struct hid_device *hdev)
 
 static void asus_kbd_set_fn_lock(struct hid_device *hdev, bool enabled)
 {
-	const u8 buf[FEATURE_KBD_REPORT_SIZE] = { FEATURE_KBD_REPORT_ID, 0xd0, 0x4e, !!enabled };
+	const u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xd0, 0x4e, !!enabled };
 	int ret;
 
 	ret = asus_kbd_set_report(hdev, buf, sizeof(buf));
@@ -5486,7 +5580,7 @@ static void asus_kbd_set_fn_lock(struct hid_device *hdev, bool enabled)
 
 static void asus_kbd_set_brightness(struct hid_device *hdev, u8 brightness)
 {
-	const u8 buf[FEATURE_KBD_REPORT_SIZE] = {
+	const u8 buf[] = {
 		FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, brightness
 	};
 	int ret;
@@ -5957,17 +6051,15 @@ static int asus_battery_probe(struct hid_device *hdev)
 
 static int asus_xgm_led_set(struct led_classdev *led_cdev, enum led_brightness value)
 {
-	const u8 buf[ROG_XGM_REPORT_SIZE] = {
-		FEATURE_KBD_LED_REPORT_ID2, 0xC5, (value) ? 0x50 : 0x00
-	};
+	const u8 buf[] = { FEATURE_KBD_LED_REPORT_ID2, 0xC5, (value) ? 0x50 : 0x00 };
 	struct asus_xgm_led *xgm = container_of(led_cdev, struct asus_xgm_led, cdev);
 	int ret;
 
-	ret = asus_kbd_set_report(xgm->hdev, buf, ROG_XGM_REPORT_SIZE);
+	ret = asus_kbd_set_report(xgm->hdev, buf, sizeof(buf));
 	if (ret < 0) {
 		hid_err(xgm->hdev, "Unable to set XG mobile led state: %d\n", ret);
 		return ret;
-	} else if (ret != ROG_XGM_REPORT_SIZE) {
+	} else if (ret != (int)asus_report_len(xgm->hdev, FEATURE_KBD_LED_REPORT_ID2)) {
 		hid_err(xgm->hdev, "Unexpected partial transfer to XG mobile: %d\n", ret);
 		return -EIO;
 	}
Signature · 1 line
2.47.3
#36 lore raw

Re: [PATCH v11 12/18] HID: asus: size feature reports from the HID report descriptor

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] HID: asus: slab out-of-bounds read in asus_kbd_get_functions() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] HID: asus: slab out-of-bounds read in asus_kbd_get_functions()
--

commit c08fc8186d8cfc7d33787c731647d924103580c9
Author: Denis Benato <[email protected]>

HID: asus: size feature reports from the HID report descriptor

This commit derives feature report transfer lengths dynamically from the device's HID report descriptor instead of using hardcoded sizes. It adds asus_report_len() and asus_kbd_get_report(), updates asus_kbd_set_report() to zero-pad short payloads to the report length, and converts callers to size their buffers per report.

Quoted 4 lines
drivers/hid/hid-asus.c +0 -0
index ea27495c3df66..fe2a326ccd861 100644

[ ... ]

Quoted 22 lines
drivers/hid/hid-asus.c +5 -3
@@ -5426,7 +5521,7 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
 				  u8 report_id)
 {
 	const u8 buf[] = { report_id, 0x05, 0x20, 0x31, 0x00, 0x08 };
-	u8 *readbuf;
+	size_t hw_len = asus_report_len(hdev, report_id);
 	int ret;
 
 	ret = asus_kbd_set_report(hdev, buf, sizeof(buf));
@@ -5435,23 +5530,22 @@ static int asus_kbd_get_functions(struct hid_device *hdev,
 		return ret;
 	}
 
-	readbuf = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL);
+	if (!hw_len)
+		return -EINVAL;
+
+	u8 *readbuf __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
 	if (!readbuf)
 		return -ENOMEM;
 
-	ret = hid_hw_raw_request(hdev, report_id, readbuf,

drivers/hid/hid-asus.c static int asus_kbd_get_functions(struct hid_device *hdev, · line 5546

Quoted 10 lines
drivers/hid/hid-asus.c +1 -3
-				 FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT,
-				 HID_REQ_GET_REPORT);
+	ret = asus_kbd_get_report(hdev, report_id, readbuf, hw_len);
 	if (ret < 0) {
 		hid_err(hdev, "Asus failed to request functions: %d\n", ret);
-		kfree(readbuf);
 		return ret;
 	}
 
 	*kbd_func = readbuf[6];

[Severity: High]
Can this read past the end of readbuf[] when a device descriptor declares a 6-byte feature report for report_id?

Previously, asus_kbd_get_functions() in drivers/hid/hid-asus.c allocated readbuf with FEATURE_KBD_REPORT_SIZE (64 bytes). With this change, readbuf is allocated with size hw_len.

In asus_kbd_get_functions(), sizeof(buf) is 6, so asus_kbd_set_report() accepts hw_len == 6 via:

    if (!hw_len || buf_size > hw_len)
        return -EINVAL;

asus_kbd_get_functions() then only checks !hw_len before allocating readbuf of 6 bytes and reading readbuf[6] (the 7th byte), resulting in a 1-byte slab out-of-bounds read during probe via asus_probe()->asus_kbd_register_leds()->asus_kbd_get_functions().

Should asus_kbd_get_functions() check that hw_len is at least 7 (or hw_len <= 6) before allocating readbuf and indexing readbuf[6]?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Tested-by on v11 12/18
#37 lore raw

Re: [PATCH v11 12/18] HID: asus: size feature reports from the HID report descriptor

In reply to Denis Benato

Hi Denis,

in the cover letter you asked Paolo and me to try asus_report_len() on the Zenbook Duo. It works there, and it covers what Paolo's v4 5/7 ("Do not send feature reports larger than declared") was written for.

Setup: hid.git for-next (hid-asus.c f6aa1be09ad5, the base of your 01/18), your patches 01-12, then Paolo's v4 1-4 and 6-7, leaving out 5/7. I stopped at 12 because 16/17 change asus-wmi and asus-armoury, which I cannot swap on this kernel. Paolo's 4/7 needed a trivial manual fixup (include context and the enum hunk); 6/7 and 7/7 applied cleanly. Built out-of-tree against a 7.2.6-based distribution kernel, UX8407AA, with my userspace workaround stopped.

- Docked (USB, 0b05:1cd7), captured with usbmon while reloading the module and pressing the backlight key: every feature report goes to interface 4 as report 0x5a with wLength 16, zero-padded. That is the handshake SET and its GET read-back, the 0x05 function query and its GET, the initial brightness, and two brightness changes. All transfers completed with status 0. The backlight key and Fn+F (platform profile) work.
- Bluetooth (0b05:1cd8): the backlight key and Fn+F work, no errors in the log. This is where, as described in 5/7, the 64 byte writes used to fail with -EIO.
- After docking again: backlight and Fn+F still work, and the input devices keep their hid-generic names.

So from my side 5/7 can be dropped in favour of this patch, and Paolo can rebase the remaining Zenbook Duo patches on top of it.

Thanks,
Rebecca

author maintainer
#38 lore raw

Re: [PATCH v11 12/18] HID: asus: size feature reports from the HID report descriptor

Quoted 5 lines · Rebecca Mara Müller

Hi Denis,

in the cover letter you asked Paolo and me to try asus_report_len() on the Zenbook Duo. It works there, and it covers what Paolo's v4 5/7 ("Do not send feature reports larger than declared") was written for.

Hi Rebecca,

Yeah I felt like putting an end about that whole class of bugs while also unifying some core code across devices was the right move.

I apologize for making things a bit more complicated (and perhaps adding delay) but I feel like this is the right thing to do for everyone.

Quoted 7 lines

Setup: hid.git for-next (hid-asus.c f6aa1be09ad5, the base of your 01/18), your patches 01-12, then Paolo's v4 1-4 and 6-7, leaving out 5/7. I stopped at 12 because 16/17 change asus-wmi and asus-armoury, which I cannot swap on this kernel. Paolo's 4/7 needed a trivial manual fixup (include context and the enum hunk); 6/7 and 7/7 applied cleanly. Built out-of-tree against a 7.2.6-based distribution kernel, UX8407AA, with my userspace workaround stopped.

Those asus-wmi changes are for the old non-thunderbolt XG mobile:
you don't have that hardware connector anyway and no more laptops will be made with it so not a problem, I have this hardware and can confirm it kept working (albeit sashiko-bot spotted an issue that I couldn't with just my nvidia).

Quoted 13 lines

- Docked (USB, 0b05:1cd7), captured with usbmon while reloading the module and pressing the backlight key: every feature report goes to interface 4 as report 0x5a with wLength 16, zero-padded. That is the handshake SET and its GET read-back, the 0x05 function query and its GET, the initial brightness, and two brightness changes. All transfers completed with status 0. The backlight key and Fn+F (platform profile) work.
- Bluetooth (0b05:1cd8): the backlight key and Fn+F work, no errors in the log. This is where, as described in 5/7, the 64 byte writes used to fail with -EIO.
- After docking again: backlight and Fn+F still work, and the input devices keep their hid-generic names.

Quoted 4 lines

So from my side 5/7 can be dropped in favour of this patch, and Paolo can rebase the remaining Zenbook Duo patches on top of it.

Splendid! Thank you very much! With this tested, a ROG ally, an ASUS touchpad and a 2022 TUF tested this should improve the driver for at least 90% of supported devices!

Quoted 2 lines

Thanks,
Rebecca

author maintainer
#39 lore raw

PATCH v11 13/18 HID: asus: identify XG Mobile stations and bind the LED to the reported model

In reply to Denis Benato

From: Denis Benato <[email protected]>

The XG Mobile LED interface is currently bound to two USB product IDs (0x1970, 0x1a9a). The stations identify themselves through the vendor report 0x5E: after the usual "ASUS Tech.Inc." unlock, the 0xCE 0x01 query answers with a NUL terminated string of the form

MB:<mainboard>;SN:<serial>;PRO:<model>;PNUM:<part number>;

Run this query at probe time to initialize the LED interface only on supported models (GC31, GC32 and GC33), and name the LED after the reported model (asus:xgm-<model>:led).

---
 drivers/hid/hid-asus.c | 183 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 182 insertions(+), 1 deletion(-)
drivers/hid/hid-asus.c +182 -1
index fe2a326ccd86..e751bf163434 100644
@@ -63,6 +63,12 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define FEATURE_KBD_LED_REPORT_ID1 0x5d
 #define FEATURE_KBD_LED_REPORT_ID2 0x5e
 
+/* XG Mobile station protocol on report 0x5E */
+#define ASUS_XGM_CMD_QUERY 0xce
+#define ASUS_XGM_QUERY_IDENTITY 0x01
+#define ASUS_XGM_QUERY_VERSION 0x03
+#define ASUS_XGM_INFO_LEN 32
+
 #define ROG_ALLY_REPORT_SIZE 64
 #define ROG_ALLY_X_MIN_MCU 313
 #define ROG_ALLY_MIN_MCU 319
@@ -174,6 +180,13 @@ struct asus_xgm_led {
 	struct hid_device *hdev;
 };
 
+struct asus_xgm_info {
+	char mainboard[ASUS_XGM_INFO_LEN];
+	char serial[ASUS_XGM_INFO_LEN];
+	char model[ASUS_XGM_INFO_LEN];
+	char part_number[ASUS_XGM_INFO_LEN];
+};
+
 struct asus_touchpad_info {
 	int max_x;
 	int max_y;
@@ -471,6 +484,7 @@ struct asus_drvdata {
 	struct asus_hid_listener listener;
 	bool fn_lock;
 	struct asus_xgm_led *xgm_led;
+	struct asus_xgm_info *xgm_info;
 };
 
 static int asus_report_battery(struct asus_drvdata *, u8 *, int);
@@ -6049,6 +6063,147 @@ static int asus_battery_probe(struct hid_device *hdev)
 	return ret;
 }
 
+/**
+ * asus_xgm_query() - Run a query command against an XG Mobile station
+ * @hdev: HID device
+ * @subcmd: query sub-command
+ * @buf: buffer to store the answer in
+ * @buf_size: size of @buf
+ *
+ * Windows re-sends the "ASUS Tech.Inc." unlock before every command
+ * burst, so do the same.
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+static int asus_xgm_query(struct hid_device *hdev, u8 subcmd,
+			  u8 *buf, size_t buf_size)
+{
+	const u8 unlock[] = {
+		FEATURE_KBD_LED_REPORT_ID2,
+		'A', 'S', 'U', 'S', ' ', 'T', 'e', 'c', 'h', '.', 'I', 'n', 'c', '.'
+	};
+	const u8 cmd[] = { FEATURE_KBD_LED_REPORT_ID2, ASUS_XGM_CMD_QUERY, subcmd };
+	int ret;
+
+	ret = asus_kbd_set_report(hdev, unlock, sizeof(unlock));
+	if (ret < 0)
+		return ret;
+
+	ret = asus_kbd_set_report(hdev, cmd, sizeof(cmd));
+	if (ret < 0)
+		return ret;
+
+	return asus_kbd_get_report(hdev, FEATURE_KBD_LED_REPORT_ID2, buf, buf_size);
+}
+
+/**
+ * asus_xgm_info_assign() - Copy an identity field up to its ';'
+ * terminator
+ * @dst: destination buffer
+ * @dst_len: size of @dst, including the trailing NUL
+ * @src: start of the field inside the identity string
+ * @src_len: number of bytes available at @src
+ *
+ * Copies up to @dst_len - 1 bytes from @src, stopping at the first ';'
+ * field separator, and NUL terminates @dst.
+ */
+static void asus_xgm_info_assign(char *dst, size_t dst_len,
+				 const char *src, size_t src_len)
+{
+	const char *sep = strnchr(src, src_len, ';');
+	size_t n = sep ? (size_t)(sep - src) : src_len;
+
+	if (n >= dst_len)
+		n = dst_len - 1;
+
+	memcpy(dst, src, n);
+	dst[n] = '\0';
+}
+
+/**
+ * asus_xgm_get_identity() - Query the identity of an XG Mobile station
+ * @hdev: HID device
+ * @info: identity structure to fill in
+ *
+ * The identity query answers with a NUL terminated string of the form
+ * "MB:<mainboard>;SN:<serial>;PRO:<model>;PNUM:<part number>;", which is
+ * split into the fields of @info. The model field is mandatory: a station
+ * that does not report one is treated as absent.
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+static int asus_xgm_get_identity(struct hid_device *hdev,
+				 struct asus_xgm_info *info)
+{
+	size_t len = asus_report_len(hdev, FEATURE_KBD_LED_REPORT_ID2);
+	const char *start, *p;
+	size_t rem;
+	int ret;
+
+	if (!len)
+		return -EINVAL;
+
+	u8 *buf __free(kfree) = kzalloc(len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = asus_xgm_query(hdev, ASUS_XGM_QUERY_IDENTITY, buf, len);
+	if (ret < 0)
+		return ret;
+
+	if (len < 4 || buf[1] != ASUS_XGM_CMD_QUERY ||
+	    buf[2] != ASUS_XGM_QUERY_IDENTITY)
+		return -ENODEV;
+
+	start = (char *)&buf[3];
+	rem = strnlen(start, len - 3);
+	if (!rem)
+		return -ENODEV;
+
+	p = strnstr(start, "MB:", rem);
+	if (p)
+		asus_xgm_info_assign(info->mainboard, sizeof(info->mainboard),
+				     p + 3, rem - (p + 3 - start));
+	p = strnstr(start, "SN:", rem);
+	if (p)
+		asus_xgm_info_assign(info->serial, sizeof(info->serial),
+				     p + 3, rem - (p + 3 - start));
+	p = strnstr(start, "PRO:", rem);
+	if (p)
+		asus_xgm_info_assign(info->model, sizeof(info->model),
+				     p + 4, rem - (p + 4 - start));
+	p = strnstr(start, "PNUM:", rem);
+	if (p)
+		asus_xgm_info_assign(info->part_number, sizeof(info->part_number),
+				     p + 5, rem - (p + 5 - start));
+
+	if (!info->model[0])
+		return -ENODEV;
+
+	return 0;
+}
+
+static const char * const asus_xgm_models[] = { "GC31", "GC32", "GC33" };
+
+/**
+ * asus_xgm_is_supported_model() - Check that a station is supported
+ * @info: identity of the station
+ *
+ * The supported families are the GC31, GC32 and GC33 stations.
+ *
+ * Return: true if the reported model belongs to one of the supported
+ * families, false otherwise
+ */
+static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info)
+{
+	for (size_t i = 0; i < ARRAY_SIZE(asus_xgm_models); i++)
+		if (strncmp(info->model, asus_xgm_models[i],
+			    strlen(asus_xgm_models[i])) == 0)
+			return true;
+
+	return false;
+}
+
 static int asus_xgm_led_set(struct led_classdev *led_cdev, enum led_brightness value)
 {
 	const u8 buf[] = { FEATURE_KBD_LED_REPORT_ID2, 0xC5, (value) ? 0x50 : 0x00 };
@@ -6315,15 +6470,41 @@ static void asus_initialize_reports(struct hid_device *hdev)
 
 static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 {
+	struct asus_xgm_info *info;
 	const char *name;
 	int ret;
 
+	info = devm_kzalloc(&hdev->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	/*
+	 * The station reports its identity through the query protocol: the
+	 * reported model decides whether the LED interface is registered
+	 * and what name it gets.
+	 */
+	ret = asus_xgm_get_identity(hdev, info);
+	if (ret < 0) {
+		hid_warn(hdev, "Failed to query XG Mobile identity: %d\n", ret);
+		return 0;
+	}
+
+	hid_info(hdev, "XG Mobile: model %s, serial %s\n",
+		 info->model, info->serial);
+
+	if (!asus_xgm_is_supported_model(info)) {
+		hid_warn(hdev, "Unsupported XG Mobile model %s\n", info->model);
+		return 0;
+	}
+
+	drvdata->xgm_info = info;
+
 	drvdata->xgm_led = devm_kzalloc(&hdev->dev, sizeof(*drvdata->xgm_led), GFP_KERNEL);
 	if (drvdata->xgm_led == NULL)
 		return -ENOMEM;
 
 	name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "asus:xgm-%s:led",
-			      strlen(hdev->uniq) ? hdev->uniq : dev_name(&hdev->dev));
+			      info->model);
 
 	if (name == NULL) {
 		ret = -ENOMEM;
Signature · 1 line
2.47.3
author maintainer
#40 lore raw

PATCH v11 14/18 HID: asus: expose XG Mobile identity and firmware information

In reply to Denis Benato

From: Denis Benato <[email protected]>

The identity query also reports the mainboard part number, the serial number and the part number of the station, and the 0xCE 0x03 query answers with an 8-byte binary blob followed by "tag, length, data" fields where GEN holds the station generation and VER the firmware version.

Collect this information at probe time and expose it read-only on the HID device:

/sys/bus/hid/devices/<bus>:<addr>.<intf>/xgm_model (PRO)

  .../xgm_serial                                              (SN)
  .../xgm_mainboard                                           (MB)
  .../xgm_part_number                                         (PNUM)
  .../xgm_firmware_version                                    (VER)
  .../xgm_generation                                          (GEN)
---
 drivers/hid/hid-asus.c | 176 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 174 insertions(+), 2 deletions(-)
drivers/hid/hid-asus.c +174 -2
index e751bf163434..f438cad13264 100644
@@ -185,6 +185,8 @@ struct asus_xgm_info {
 	char serial[ASUS_XGM_INFO_LEN];
 	char model[ASUS_XGM_INFO_LEN];
 	char part_number[ASUS_XGM_INFO_LEN];
+	char firmware_version[ASUS_XGM_INFO_LEN];
+	char generation[ASUS_XGM_INFO_LEN];
 };
 
 struct asus_touchpad_info {
@@ -6204,6 +6206,148 @@ static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info)
 	return false;
 }
 
+/**
+ * asus_xgm_tlv_str() - Extract a "tag, length, data" field
+ * @dst: destination buffer
+ * @dst_len: size of @dst, including the trailing NUL
+ * @buf: answer of a version query
+ * @len: size of @buf
+ * @tag: three characters tag to look for
+ *
+ * The version query answers with an 8-byte binary blob followed by
+ * "tag, length, data" fields, where GEN holds the station generation and
+ * VER the firmware version.
+ *
+ * Return: 0 on success, -ENOENT if @tag is missing or its data does not
+ * fit @dst
+ */
+static int asus_xgm_tlv_str(char *dst, size_t dst_len, const u8 *buf,
+			    size_t len, const char *tag)
+{
+	size_t i;
+	u8 n;
+
+	for (i = 3; i + 4 <= len; i++) {
+		if (memcmp(buf + i, tag, 3))
+			continue;
+
+		n = buf[i + 3];
+		if (i + 4 + n > len || n >= dst_len)
+			return -ENOENT;
+
+		memcpy(dst, buf + i + 4, n);
+		dst[n] = '\0';
+
+		return 0;
+	}
+
+	return -ENOENT;
+}
+
+/**
+ * asus_xgm_get_version() - Query the firmware version of a station
+ * @hdev: HID device
+ * @info: identity structure whose generation and firmware_version fields
+ * get filled in
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+static int asus_xgm_get_version(struct hid_device *hdev,
+				struct asus_xgm_info *info)
+{
+	size_t len = asus_report_len(hdev, FEATURE_KBD_LED_REPORT_ID2);
+	int ret;
+
+	if (!len)
+		return -EINVAL;
+
+	u8 *buf __free(kfree) = kzalloc(len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = asus_xgm_query(hdev, ASUS_XGM_QUERY_VERSION, buf, len);
+	if (ret < 0)
+		return ret;
+
+	if (len < 4 || buf[1] != ASUS_XGM_CMD_QUERY ||
+	    buf[2] != ASUS_XGM_QUERY_VERSION)
+		return -ENODEV;
+
+	asus_xgm_tlv_str(info->generation, sizeof(info->generation),
+			 buf, len, "GEN");
+	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
+			 buf, len, "VER");
+
+	return 0;
+}
+
+/**
+ * asus_xgm_drvdata() - Get the drvdata behind an XG Mobile attribute
+ * @dev: HID device the attribute is attached to
+ *
+ * Return: the asus_drvdata of @dev
+ */
+static struct asus_drvdata *asus_xgm_drvdata(struct device *dev)
+{
+	return hid_get_drvdata(to_hid_device(dev));
+}
+
+static ssize_t xgm_model_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->model);
+}
+static DEVICE_ATTR_RO(xgm_model);
+
+static ssize_t xgm_serial_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->serial);
+}
+static DEVICE_ATTR_RO(xgm_serial);
+
+static ssize_t xgm_mainboard_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->mainboard);
+}
+static DEVICE_ATTR_RO(xgm_mainboard);
+
+static ssize_t xgm_part_number_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->part_number);
+}
+static DEVICE_ATTR_RO(xgm_part_number);
+
+static ssize_t xgm_firmware_version_show(struct device *dev,
+					 struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->firmware_version);
+}
+static DEVICE_ATTR_RO(xgm_firmware_version);
+
+static ssize_t xgm_generation_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->generation);
+}
+static DEVICE_ATTR_RO(xgm_generation);
+
+static struct attribute *asus_xgm_attrs[] = {
+	&dev_attr_xgm_model.attr,
+	&dev_attr_xgm_serial.attr,
+	&dev_attr_xgm_mainboard.attr,
+	&dev_attr_xgm_part_number.attr,
+	&dev_attr_xgm_firmware_version.attr,
+	&dev_attr_xgm_generation.attr,
+	NULL
+};
+
+static const struct attribute_group asus_xgm_attr_group = {
+	.attrs = asus_xgm_attrs,
+};
+
 static int asus_xgm_led_set(struct led_classdev *led_cdev, enum led_brightness value)
 {
 	const u8 buf[] = { FEATURE_KBD_LED_REPORT_ID2, 0xC5, (value) ? 0x50 : 0x00 };
@@ -6499,9 +6643,29 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 
 	drvdata->xgm_info = info;
 
+	ret = asus_xgm_get_version(hdev, info);
+	if (ret < 0)
+		hid_warn(hdev, "Failed to query XG Mobile version: %d\n", ret);
+	else
+		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
+			 info->firmware_version, info->generation);
+
+	/*
+	 * The attribute group is not devm-managed: a creation failure is
+	 * fatal and unwound through asus_xgm_init_err, while on the unbind
+	 * path the removal is gated on xgm_info exactly like the creation.
+	 */
+	ret = sysfs_create_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	if (ret) {
+		hid_err(hdev, "Failed to create XG Mobile attributes: %d\n", ret);
+		goto asus_xgm_init_err;
+	}
+
 	drvdata->xgm_led = devm_kzalloc(&hdev->dev, sizeof(*drvdata->xgm_led), GFP_KERNEL);
-	if (drvdata->xgm_led == NULL)
-		return -ENOMEM;
+	if (!drvdata->xgm_led) {
+		ret = -ENOMEM;
+		goto asus_xgm_init_err;
+	}
 
 	name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "asus:xgm-%s:led",
 			      info->model);
@@ -6533,6 +6697,8 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 
 	return 0;
 asus_xgm_init_err:
+	sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	drvdata->xgm_info = NULL;
 	drvdata->xgm_led = NULL;
 	return ret;
 }
@@ -6750,6 +6916,9 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
+	if (drvdata->xgm_info)
+		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
 
@@ -6768,6 +6937,9 @@ static void asus_remove(struct hid_device *hdev)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
+	if (drvdata->xgm_info)
+		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
 
Signature · 1 line
2.47.3
#41 lore raw

Re: [PATCH v11 14/18] HID: asus: expose XG Mobile identity and firmware information

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] HID: asus: unchecked return and unaligned scan in asus_xgm_tlv_str() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] HID: asus: unchecked return and unaligned scan in asus_xgm_tlv_str() --

commit a88274a1b2531f51181e1da6036282f6753460c3
Author: Denis Benato <[email protected]>

HID: asus: expose XG Mobile identity and firmware information

This commit queries the XG Mobile station for its firmware version and generation at probe time and exposes the station's identity and firmware fields through read-only sysfs attributes on the HID device.

Quoted 4 lines
drivers/hid/hid-asus.c +0 -0
index e751bf1634349..f438cad13264a 100644

[ ... ]

Quoted 68 lines
drivers/hid/hid-asus.c +64 -0
@@ -6204,6 +6206,148 @@ static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info)
 	return false;
 }
 
+/**
+ * asus_xgm_tlv_str() - Extract a "tag, length, data" field
+ * @dst: destination buffer
+ * @dst_len: size of @dst, including the trailing NUL
+ * @buf: answer of a version query
+ * @len: size of @buf
+ * @tag: three characters tag to look for
+ *
+ * The version query answers with an 8-byte binary blob followed by
+ * "tag, length, data" fields, where GEN holds the station generation and
+ * VER the firmware version.
+ *
+ * Return: 0 on success, -ENOENT if @tag is missing or its data does not
+ * fit @dst
+ */
+static int asus_xgm_tlv_str(char *dst, size_t dst_len, const u8 *buf,
+			    size_t len, const char *tag)
+{
+	size_t i;
+	u8 n;
+
+	for (i = 3; i + 4 <= len; i++) {
+		if (memcmp(buf + i, tag, 3))
+			continue;
+
+		n = buf[i + 3];
+		if (i + 4 + n > len || n >= dst_len)
+			return -ENOENT;
+
+		memcpy(dst, buf + i + 4, n);
+		dst[n] = '\0';
+
+		return 0;
+	}
+
+	return -ENOENT;
+}
+
+/**
+ * asus_xgm_get_version() - Query the firmware version of a station
+ * @hdev: HID device
+ * @info: identity structure whose generation and firmware_version fields
+ * get filled in
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+static int asus_xgm_get_version(struct hid_device *hdev,
+				struct asus_xgm_info *info)
+{
+	size_t len = asus_report_len(hdev, FEATURE_KBD_LED_REPORT_ID2);
+	int ret;
+
+	if (!len)
+		return -EINVAL;
+
+	u8 *buf __free(kfree) = kzalloc(len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = asus_xgm_query(hdev, ASUS_XGM_QUERY_VERSION, buf, len);
+	if (ret < 0)
+		return ret;
+
+	if (len < 4 || buf[1] != ASUS_XGM_CMD_QUERY ||

drivers/hid/hid-asus.c static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info) · line 6282

Quoted 10 lines
drivers/hid/hid-asus.c +10 -0
+	    buf[2] != ASUS_XGM_QUERY_VERSION)
+		return -ENODEV;
+
+	asus_xgm_tlv_str(info->generation, sizeof(info->generation),
+			 buf, len, "GEN");
+	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
+			 buf, len, "VER");
+
+	return 0;
+}

[Severity: Medium]
In drivers/hid/hid-asus.c, asus_xgm_tlv_str() is documented to follow an 8-byte binary blob after the 3-byte report/command header (buf[0..2]) and return -ENOENT when a tag is missing or its length is out of bounds.

However, in the asus_probe() -> asus_xgm_init() -> asus_xgm_get_version() -> asus_xgm_tlv_str() path, two things stand out:

1. asus_xgm_tlv_str() starts scanning at i = 3 (inside the 8-byte binary blob at buf[3..10]) and increments byte-by-byte (i++) rather than starting at offset 11 and advancing across record boundaries by 4 + n. If the binary blob or an earlier field's payload happens to contain the bytes "GEN" or "VER", could asus_xgm_tlv_str() treat the following byte as the length and either abort early with -ENOENT or copy unintended bytes into dst?

2. asus_xgm_get_version() ignores the return values of both asus_xgm_tlv_str() calls and unconditionally returns 0. When a tag is missing or truncated, asus_xgm_init() will log empty strings for info->firmware_version and info->generation via hid_info() instead of taking the ret < 0 warning branch:

	ret = asus_xgm_get_version(hdev, info);
	if (ret < 0)
		hid_warn(hdev, "Failed to query XG Mobile version: %d\n", ret);
	else
		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
			 info->firmware_version, info->generation);

Should asus_xgm_tlv_str() start after the 8-byte binary header (or step by TLV record length), and should asus_xgm_get_version() check and propagate the return values of asus_xgm_tlv_str()?

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

Re: [PATCH v11 14/18] HID: asus: expose XG Mobile identity and firmware information

In reply to Denis Benato
Quoted 44 lines · Denis Benato

From: Denis Benato <[email protected]>

The identity query also reports the mainboard part number, the serial number and the part number of the station, and the 0xCE 0x03 query answers with an 8-byte binary blob followed by "tag, length, data" fields where GEN holds the station generation and VER the firmware version.

Collect this information at probe time and expose it read-only on the HID device:

/sys/bus/hid/devices/<bus>:<addr>.<intf>/xgm_model (PRO)

  .../xgm_serial                                              (SN)
  .../xgm_mainboard                                           (MB)
  .../xgm_part_number                                         (PNUM)
  .../xgm_firmware_version                                    (VER)
  .../xgm_generation                                          (GEN)
---
 drivers/hid/hid-asus.c | 176 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 174 insertions(+), 2 deletions(-)
drivers/hid/hid-asus.c +6 -0
index e751bf163434..f438cad13264 100644
@@ -185,6 +185,8 @@ struct asus_xgm_info {
 	char serial[ASUS_XGM_INFO_LEN];
 	char model[ASUS_XGM_INFO_LEN];
 	char part_number[ASUS_XGM_INFO_LEN];
+	char firmware_version[ASUS_XGM_INFO_LEN];
+	char generation[ASUS_XGM_INFO_LEN];
 };
 
 struct asus_touchpad_info {
@@ -6204,6 +6206,148 @@ static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info)
 	return false;
 }
 
+/**
+ * asus_xgm_tlv_str() - Extract a "tag, length, data" field
+ * @dst: destination buffer
+ * @dst_len: size of @dst, including the trailing NUL

drivers/hid/hid-asus.c static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info) · line 6222

Quoted 10 lines
drivers/hid/hid-asus.c +10 -0
+ * @buf: answer of a version query
+ * @len: size of @buf
+ * @tag: three characters tag to look for
+ *
+ * The version query answers with an 8-byte binary blob followed by
+ * "tag, length, data" fields, where GEN holds the station generation and
+ * VER the firmware version.
+ *
+ * Return: 0 on success, -ENOENT if @tag is missing or its data does not
+ * fit @dst

.

Quoted 6 lines
drivers/hid/hid-asus.c +6 -0
+ */
+static int asus_xgm_tlv_str(char *dst, size_t dst_len, const u8 *buf,
+			    size_t len, const char *tag)
+{
+	size_t i;
+	u8 n;

drivers/hid/hid-asus.c static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info) · line 6238

Quoted 10 lines
drivers/hid/hid-asus.c +10 -0
+
+	for (i = 3; i + 4 <= len; i++) {
+		if (memcmp(buf + i, tag, 3))
+			continue;
+
+		n = buf[i + 3];
+		if (i + 4 + n > len || n >= dst_len)
+			return -ENOENT;
+
+		memcpy(dst, buf + i + 4, n);

Many magic numbers in this function making it pretty unreadable without lots of thinking. Replacing the literals with named defines would improve readability a lot.

Quoted 177 lines
drivers/hid/hid-asus.c +142 -2
+		dst[n] = '\0';
+
+		return 0;
+	}
+
+	return -ENOENT;
+}
+
+/**
+ * asus_xgm_get_version() - Query the firmware version of a station
+ * @hdev: HID device
+ * @info: identity structure whose generation and firmware_version fields
+ * get filled in
+ *
+ * Return: 0 on success, negative errno on failure
+ */
+static int asus_xgm_get_version(struct hid_device *hdev,
+				struct asus_xgm_info *info)
+{
+	size_t len = asus_report_len(hdev, FEATURE_KBD_LED_REPORT_ID2);
+	int ret;
+
+	if (!len)
+		return -EINVAL;
+
+	u8 *buf __free(kfree) = kzalloc(len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = asus_xgm_query(hdev, ASUS_XGM_QUERY_VERSION, buf, len);
+	if (ret < 0)
+		return ret;
+
+	if (len < 4 || buf[1] != ASUS_XGM_CMD_QUERY ||
+	    buf[2] != ASUS_XGM_QUERY_VERSION)
+		return -ENODEV;
+
+	asus_xgm_tlv_str(info->generation, sizeof(info->generation),
+			 buf, len, "GEN");
+	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
+			 buf, len, "VER");
+
+	return 0;
+}
+
+/**
+ * asus_xgm_drvdata() - Get the drvdata behind an XG Mobile attribute
+ * @dev: HID device the attribute is attached to
+ *
+ * Return: the asus_drvdata of @dev
+ */
+static struct asus_drvdata *asus_xgm_drvdata(struct device *dev)
+{
+	return hid_get_drvdata(to_hid_device(dev));
+}
+
+static ssize_t xgm_model_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->model);
+}
+static DEVICE_ATTR_RO(xgm_model);
+
+static ssize_t xgm_serial_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->serial);
+}
+static DEVICE_ATTR_RO(xgm_serial);
+
+static ssize_t xgm_mainboard_show(struct device *dev,
+				  struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->mainboard);
+}
+static DEVICE_ATTR_RO(xgm_mainboard);
+
+static ssize_t xgm_part_number_show(struct device *dev,
+				    struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->part_number);
+}
+static DEVICE_ATTR_RO(xgm_part_number);
+
+static ssize_t xgm_firmware_version_show(struct device *dev,
+					 struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->firmware_version);
+}
+static DEVICE_ATTR_RO(xgm_firmware_version);
+
+static ssize_t xgm_generation_show(struct device *dev,
+				   struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%s\n", asus_xgm_drvdata(dev)->xgm_info->generation);
+}
+static DEVICE_ATTR_RO(xgm_generation);
+
+static struct attribute *asus_xgm_attrs[] = {
+	&dev_attr_xgm_model.attr,
+	&dev_attr_xgm_serial.attr,
+	&dev_attr_xgm_mainboard.attr,
+	&dev_attr_xgm_part_number.attr,
+	&dev_attr_xgm_firmware_version.attr,
+	&dev_attr_xgm_generation.attr,
+	NULL
+};
+
+static const struct attribute_group asus_xgm_attr_group = {
+	.attrs = asus_xgm_attrs,
+};
+
 static int asus_xgm_led_set(struct led_classdev *led_cdev, enum led_brightness value)
 {
 	const u8 buf[] = { FEATURE_KBD_LED_REPORT_ID2, 0xC5, (value) ? 0x50 : 0x00 };
@@ -6499,9 +6643,29 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 
 	drvdata->xgm_info = info;
 
+	ret = asus_xgm_get_version(hdev, info);
+	if (ret < 0)
+		hid_warn(hdev, "Failed to query XG Mobile version: %d\n", ret);
+	else
+		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
+			 info->firmware_version, info->generation);
+
+	/*
+	 * The attribute group is not devm-managed: a creation failure is
+	 * fatal and unwound through asus_xgm_init_err, while on the unbind
+	 * path the removal is gated on xgm_info exactly like the creation.
+	 */
+	ret = sysfs_create_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	if (ret) {
+		hid_err(hdev, "Failed to create XG Mobile attributes: %d\n", ret);
+		goto asus_xgm_init_err;
+	}
+
 	drvdata->xgm_led = devm_kzalloc(&hdev->dev, sizeof(*drvdata->xgm_led), GFP_KERNEL);
-	if (drvdata->xgm_led == NULL)
-		return -ENOMEM;
+	if (!drvdata->xgm_led) {
+		ret = -ENOMEM;
+		goto asus_xgm_init_err;
+	}
 
 	name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "asus:xgm-%s:led",
 			      info->model);
@@ -6533,6 +6697,8 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 
 	return 0;
 asus_xgm_init_err:
+	sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	drvdata->xgm_info = NULL;
 	drvdata->xgm_led = NULL;
 	return ret;
 }
@@ -6750,6 +6916,9 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
+	if (drvdata->xgm_info)
+		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
 
@@ -6768,6 +6937,9 @@ static void asus_remove(struct hid_device *hdev)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
+	if (drvdata->xgm_info)
+		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
 
Signature · 1 line
 i.
author maintainer
#43 lore raw

PATCH v11 15/18 HID: asus: size ally gamepad commands from the HID report descriptor

In reply to Denis Benato

ally_alloc_cmd() hardcodes ROG_ALLY_REPORT_SIZE both for the command buffer allocation and, at every call site, for the transfer length, and mcu_request_version() uses it for the size of the MCU version response. The gamepad protocol speaks through the 0x5A feature report, whose transfer length is declared by the HID report descriptor of the device at hand, and the MCU version is read back from the 0x0d feature report the same way.

Size both from the report descriptor instead:

- ally_alloc_cmd() takes the HID device, resolves the length of the 0x5A feature report through asus_report_len() and returns it to the
caller;
- every caller sends and receives with the returned length instead of the hardcoded ROG_ALLY_REPORT_SIZE;
- ally_set_button_mapping() declares the size of its mapping block (the length byte at buf[4] plus the four 11-byte entries, up to buf[48]) so a descriptor with a short 0x5A report is rejected by the fit check instead of being overflowed by the fixed-offset writes;
- mcu_request_version() sizes the 0x0d response buffer with asus_report_len() and gives up when the device does not declare the report at all; ROG_ALLY_REPORT_SIZE has no users left and is removed.

---
 drivers/hid/hid-asus.c | 103 +++++++++++++++++++++++++++--------------
 1 file changed, 69 insertions(+), 34 deletions(-)
drivers/hid/hid-asus.c +69 -34
index f438cad13264..e444cad85b32 100644
@@ -69,7 +69,6 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define ASUS_XGM_QUERY_VERSION 0x03
 #define ASUS_XGM_INFO_LEN 32
 
-#define ROG_ALLY_REPORT_SIZE 64
 #define ROG_ALLY_X_MIN_MCU 313
 #define ROG_ALLY_MIN_MCU 319
 
@@ -943,28 +942,33 @@ static int ally_gamepad_send_receive_packet(struct ally_handheld *ally,
 
 /**
  * ally_alloc_cmd() - Construct a command buffer for the gamepad
+ * @hdev: HID device the command is built for
  * @cmd: Command code to send
  * @payload: Optional payload data to include in the command
  * @payload_size: Size of the payload data
+ * @size: Where to store the length of the allocated buffer
  *
- * The constructed buffer is 64 bytes long, and it is the caller
- * responsibility to free the buffer using kfree().
+ * The buffer is sized after the feature report the device declares for
+ * the gamepad commands, and it is the caller responsibility to free the
+ * buffer using kfree().
  *
  * Return: the newly allocated buffer containing the command, or NULL on
  * allocation failure or if the payload would not fit in the report
  */
-static u8 *ally_alloc_cmd(u8 cmd, const u8 *payload, u8 payload_size)
+static u8 *ally_alloc_cmd(struct hid_device *hdev, u8 cmd, const u8 *payload,
+			  u8 payload_size, size_t *size)
 {
+	size_t hw_len = asus_report_len(hdev, HID_ALLY_SET_REPORT_ID);
 	u8 *hidbuf;
 
 	/*
 	 * The payload is written after the 4-byte command header:
 	 * reject one that would spill past the end of the report.
 	 */
-	if (payload_size > ROG_ALLY_REPORT_SIZE - 4)
+	if (hw_len < 4 || payload_size > hw_len - 4)
 		return NULL;
 
-	hidbuf = kzalloc(ROG_ALLY_REPORT_SIZE, GFP_KERNEL);
+	hidbuf = kzalloc(hw_len, GFP_KERNEL);
 
 	if (!hidbuf)
 		return NULL;
@@ -977,6 +981,8 @@ static u8 *ally_alloc_cmd(u8 cmd, const u8 *payload, u8 payload_size)
 	if (payload_size > 0 && payload)
 		memcpy(&hidbuf[4], payload, payload_size);
 
+	*size = hw_len;
+
 	return hidbuf;
 }
 
@@ -992,15 +998,17 @@ static bool ally_check_capability(struct hid_device *hdev, struct ally_handheld
 				  enum ally_command_codes check_cmd)
 {
 	u8 payload[] = { 0x00 };
+	size_t buf_len;
 	int ret;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(check_cmd, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, check_cmd, payload,
+					       sizeof(payload), &buf_len);
 	if (!buf) {
 		hid_err(hdev, "Failed to allocate buffer for capability check.\n");
 		return false;
 	}
 
-	ret = ally_gamepad_send_receive_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_receive_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to check capability 0x%02x: %d\n", check_cmd, ret);
 		return false;
@@ -1043,16 +1051,18 @@ static int ally_set_xbox_controller(struct hid_device *hdev,
 				    struct ally_config *cfg, bool enabled)
 {
 	u8 payload[] = { enabled ? 0x01 : 0x00 };
+	size_t buf_len;
 	int ret;
 
 	if (!cfg || !cfg->xbox_controller_support)
 		return -EOPNOTSUPP;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_XBOX_CONTROLLER, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_XBOX_CONTROLLER,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set Xbox controller mode: %d\n", ret);
 		return ret;
@@ -1160,6 +1170,7 @@ static DEVICE_ATTR_RW(xbox_controller);
 static int ally_set_gamepad_mode(struct ally_handheld *ally, struct hid_device *hdev, u8 mode)
 {
 	u8 payload[] = { mode };
+	size_t buf_len;
 	int ret;
 
 	if (mode < ALLY_GAMEPAD_MODE_GAMEPAD ||
@@ -1168,11 +1179,12 @@ static int ally_set_gamepad_mode(struct ally_handheld *ally, struct hid_device *
 		return -EINVAL;
 	}
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_GAMEPAD_MODE, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_GAMEPAD_MODE,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set gamepad mode: %d\n", ret);
 		return ret;
@@ -1609,13 +1621,15 @@ static int ally_set_vibration_intensity(struct ally_handheld *ally,
 					struct hid_device *hdev, u8 left, u8 right)
 {
 	const u8 data[] = { left, right };
+	size_t buf_len;
 	int ret;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_VIBRATION_INTENSITY, data, sizeof(data));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_VIBRATION_INTENSITY,
+					       data, sizeof(data), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set vibration intensity: %d\n", ret);
 		return ret;
@@ -1777,13 +1791,15 @@ static int ally_set_joystick_thresholds(struct ally_handheld *ally,
 					u8 left_it, u8 left_ot, u8 right_it, u8 right_ot)
 {
 	const u8 payload[] = { left_it, left_ot, right_it, right_ot };
+	size_t buf_len;
 	int ret;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_JOYSTICK_DEADZONE, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_JOYSTICK_DEADZONE,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set joystick ranges: %d\n", ret);
 		return ret;
@@ -2125,6 +2141,7 @@ static int ally_set_anti_deadzone(struct ally_handheld *ally,
 				  u8 left_adz, u8 right_adz)
 {
 	const u8 payload[] = { left_adz, right_adz };
+	size_t buf_len;
 	int ret;
 
 	if (!cfg->anti_deadzone_support) {
@@ -2132,11 +2149,12 @@ static int ally_set_anti_deadzone(struct ally_handheld *ally,
 		return -EOPNOTSUPP;
 	}
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_ANTI_DEADZONE, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_ANTI_DEADZONE,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set anti-deadzone values: %d\n", ret);
 		return ret;
@@ -2320,13 +2338,15 @@ static int ally_set_trigger_ranges(struct ally_handheld *ally,
 				   u8 left_it, u8 left_ot, u8 right_it, u8 right_ot)
 {
 	const u8 payload[] = { left_it, left_ot, right_it, right_ot };
+	size_t buf_len;
 	int ret;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_TRIGGER_RANGE, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_TRIGGER_RANGE,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set trigger ranges: %d\n", ret);
 		return ret;
@@ -2676,13 +2696,15 @@ static int ally_set_joystick_resp_curve(struct ally_handheld *ally,
 		curve->entry_3.move, curve->entry_3.resp,
 		curve->entry_4.move, curve->entry_4.resp
 	};
+	size_t buf_len;
 	int ret;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_RESP_CURVE, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_RESP_CURVE,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0)
 		return ret;
 
@@ -3039,13 +3061,15 @@ static int ally_set_turbo_params(struct ally_handheld *ally,
 		turbo->btn_m1.turbo,
 		turbo->btn_m1.toggle,
 	};
+	size_t buf_len;
 	int ret;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_TURBO_PARAMS, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_TURBO_PARAMS,
+					       payload, sizeof(payload), &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
-	ret = ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 	if (ret < 0) {
 		hid_err(hdev, "Failed to set turbo parameters: %d\n", ret);
 		return ret;
@@ -3318,12 +3342,18 @@ static int ally_set_button_mapping(struct hid_device *hdev, struct ally_handheld
 	 */
 	u8 macro_bytes[11] = {0};
 	u8 btn_bytes[11] = {0};
+	size_t buf_len;
 
 	if (!mapping || !mapping->first.remap || !mapping->first.macro ||
 	    !mapping->second.remap || !mapping->second.macro)
 		return -EINVAL;
 
-	u8 *buf __free(kfree) = ally_alloc_cmd(CMD_SET_MAPPING, NULL, 0);
+	/*
+	 * The mapping block spans buf[4]..buf[48]: give ally_alloc_cmd() its
+	 * size so the fit check protects the fixed-offset writes below.
+	 */
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_SET_MAPPING, NULL,
+					       1 + 0x2C, &buf_len);
 	if (!buf)
 		return -ENOMEM;
 
@@ -3439,7 +3469,7 @@ static int ally_set_button_mapping(struct hid_device *hdev, struct ally_handheld
 		memcpy(&buf[38], macro_bytes, 11);
 	}
 
-	return ally_gamepad_send_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	return ally_gamepad_send_packet(ally, hdev, buf, buf_len);
 }
 
 /**
@@ -4156,14 +4186,16 @@ static void ally_config_remove(struct hid_device *hdev, struct ally_config *cfg)
 static int ally_gamepad_check_ready(struct ally_handheld *ally, struct hid_device *hdev)
 {
 	u8 payload[] = { 0x00 };
+	size_t buf_len;
 	int ret;
 
 	for (int i = 0; i < HID_ALLY_READY_MAX_TRIES; i++) {
-		u8 *buf __free(kfree) = ally_alloc_cmd(CMD_CHECK_READY, payload, sizeof(payload));
+		u8 *buf __free(kfree) = ally_alloc_cmd(hdev, CMD_CHECK_READY,
+						       payload, sizeof(payload), &buf_len);
 		if (!buf)
 			return -ENOMEM;
 
-		ret = ally_gamepad_send_receive_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+		ret = ally_gamepad_send_receive_packet(ally, hdev, buf, buf_len);
 		if (ret < 0) {
 			hid_dbg(hdev, "ROG Ally check %d/%d failed: %d\n", i,
 				HID_ALLY_READY_MAX_TRIES, ret);
@@ -5796,10 +5828,14 @@ static int mcu_parse_version_string(const u8 *response, size_t response_size)
 
 static int mcu_request_version(struct hid_device *hdev)
 {
-	u8 *response __free(kfree) = kzalloc(ROG_ALLY_REPORT_SIZE, GFP_KERNEL);
+	size_t hw_len = asus_report_len(hdev, FEATURE_REPORT_ID);
 	const u8 request[] = { 0x5a, 0x05, 0x03, 0x31, 0x00, 0x20 };
 	int ret;
 
+	if (!hw_len)
+		return -EINVAL;
+
+	u8 *response __free(kfree) = kzalloc(hw_len, GFP_KERNEL);
 	if (!response)
 		return -ENOMEM;
 
@@ -5807,17 +5843,16 @@ static int mcu_request_version(struct hid_device *hdev)
 	if (ret < 0)
 		return ret;
 
-	ret = hid_hw_raw_request(hdev, FEATURE_REPORT_ID, response,
-				ROG_ALLY_REPORT_SIZE, HID_FEATURE_REPORT,
-				HID_REQ_GET_REPORT);
+	ret = hid_hw_raw_request(hdev, FEATURE_REPORT_ID, response, hw_len,
+				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
 	if (ret < 0)
 		return ret;
 
-	ret = mcu_parse_version_string(response, ROG_ALLY_REPORT_SIZE);
+	ret = mcu_parse_version_string(response, hw_len);
 	if (ret < 0) {
 		pr_err("Failed to parse MCU version: %d\n", ret);
 		print_hex_dump(KERN_ERR, "MCU: ", DUMP_PREFIX_NONE,
-			      16, 1, response, ROG_ALLY_REPORT_SIZE, false);
+			       16, 1, response, hw_len, false);
 	}
 
 	return ret;
Signature · 1 line
2.47.3
#44 lore raw

Re: [PATCH v11 15/18] HID: asus: size ally gamepad commands from the HID report descriptor

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] HID: asus: ally_dev_get_report() sizes 0x0D read from 0x5A report length --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] HID: asus: ally_dev_get_report() sizes 0x0D read from 0x5A report length --

commit 10b46a2b16e439d019a0b1a24882abca2924c954
Author: Denis Benato <[email protected]>

HID: asus: size ally gamepad commands from the HID report descriptor

This commit replaces the hardcoded ROG_ALLY_REPORT_SIZE constant with dynamic buffer sizing derived from the HID report descriptor via asus_report_len() for ROG Ally gamepad commands and MCU version requests.

Quoted 67 lines
drivers/hid/hid-asus.c +13 -6
index f438cad13264a..e444cad85b32c 100644
@@ -69,7 +69,6 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define ASUS_XGM_QUERY_VERSION 0x03
 #define ASUS_XGM_INFO_LEN 32
 
-#define ROG_ALLY_REPORT_SIZE 64
 #define ROG_ALLY_X_MIN_MCU 313
 #define ROG_ALLY_MIN_MCU 319
 
@@ -943,28 +942,33 @@ static int ally_gamepad_send_receive_packet(struct ally_handheld *ally,
 
 /**
  * ally_alloc_cmd() - Construct a command buffer for the gamepad
+ * @hdev: HID device the command is built for
  * @cmd: Command code to send
  * @payload: Optional payload data to include in the command
  * @payload_size: Size of the payload data
+ * @size: Where to store the length of the allocated buffer
  *
- * The constructed buffer is 64 bytes long, and it is the caller
- * responsibility to free the buffer using kfree().
+ * The buffer is sized after the feature report the device declares for
+ * the gamepad commands, and it is the caller responsibility to free the
+ * buffer using kfree().
  *
  * Return: the newly allocated buffer containing the command, or NULL on
  * allocation failure or if the payload would not fit in the report
  */
-static u8 *ally_alloc_cmd(u8 cmd, const u8 *payload, u8 payload_size)
+static u8 *ally_alloc_cmd(struct hid_device *hdev, u8 cmd, const u8 *payload,
+			  u8 payload_size, size_t *size)
 {
+	size_t hw_len = asus_report_len(hdev, HID_ALLY_SET_REPORT_ID);
 	u8 *hidbuf;
 
 	/*
 	 * The payload is written after the 4-byte command header:
 	 * reject one that would spill past the end of the report.
 	 */
-	if (payload_size > ROG_ALLY_REPORT_SIZE - 4)
+	if (hw_len < 4 || payload_size > hw_len - 4)
 		return NULL;
 
-	hidbuf = kzalloc(ROG_ALLY_REPORT_SIZE, GFP_KERNEL);
+	hidbuf = kzalloc(hw_len, GFP_KERNEL);
 
 	if (!hidbuf)
 		return NULL;
@@ -977,6 +981,8 @@ static u8 *ally_alloc_cmd(u8 cmd, const u8 *payload, u8 payload_size)
 	if (payload_size > 0 && payload)
 		memcpy(&hidbuf[4], payload, payload_size);
 
+	*size = hw_len;
+
 	return hidbuf;
 }
 
@@ -992,15 +998,17 @@ static bool ally_check_capability(struct hid_device *hdev, struct ally_handheld
 				  enum ally_command_codes check_cmd)
 {
 	u8 payload[] = { 0x00 };
+	size_t buf_len;
 	int ret;
 

drivers/hid/hid-asus.c static bool ally_check_capability(struct hid_device *hdev, struct ally_handheld · line 1011

Quoted 10 lines
drivers/hid/hid-asus.c +3 -2
-	u8 *buf __free(kfree) = ally_alloc_cmd(check_cmd, payload, sizeof(payload));
+	u8 *buf __free(kfree) = ally_alloc_cmd(hdev, check_cmd, payload,
+					       sizeof(payload), &buf_len);
 	if (!buf) {
 		hid_err(hdev, "Failed to allocate buffer for capability check.\n");
 		return false;
 	}
 
-	ret = ally_gamepad_send_receive_packet(ally, hdev, buf, ROG_ALLY_REPORT_SIZE);
+	ret = ally_gamepad_send_receive_packet(ally, hdev, buf, buf_len);

[Severity: Medium]
Does ally_gamepad_send_receive_packet() end up sizing the 0x0d feature report read using the length of the 0x5a feature report?

In ally_alloc_cmd(), buf_len is resolved from HID_ALLY_SET_REPORT_ID (0x5a). However, when ally_check_capability() and ally_gamepad_check_ready() pass buf_len into ally_gamepad_send_receive_packet(), the same length is passed to both ally_dev_set_report() and ally_dev_get_report():

drivers/hid/hid-asus.c:ally_gamepad_send_receive_packet() {
	scoped_guard(mutex, &ally->intf_mutex) {
		ret = ally_dev_set_report(hdev, buf, len);
		if (ret >= 0) {
			memset(buf, 0, len);
			ret = ally_dev_get_report(hdev, buf, len);
		}
	}
}

While ally_dev_set_report() sends report 0x5a, ally_dev_get_report() reads from HID_ALLY_GET_REPORT_ID (0x0d):

drivers/hid/hid-asus.c:ally_dev_get_report() {
	return hid_hw_raw_request(hdev, HID_ALLY_GET_REPORT_ID, out, len,
		HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
}

If a device declares different report lengths for feature reports 0x5a and 0x0d (or omits report 0x0d from its descriptor), ally_dev_get_report() will request the wrong transfer size rather than consulting asus_report_len(hdev, HID_ALLY_GET_REPORT_ID). Should the receive path in ally_dev_get_report() or ally_gamepad_send_receive_packet() also check the length of HID_ALLY_GET_REPORT_ID from the report descriptor?

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

PATCH v11 16/18 platform/x86: asus-armoury: pick the eGPU activation from the reported GPU

In reply to Denis Benato

The egpu_enable attribute is a switch: writing 0 turns the eGPU off and writing 1 turns it on. Turning it on has always sent the NVIDIA activation value, which only works for NVIDIA stations, and the WMI interface cannot tell which GPU is installed in the connected one.

Let drivers that detect the station report the GPU vendor through
asus-wmi: writing 1 sends the activation value matching the reported vendor and falls back to NVIDIA when nothing has been reported, so existing tools keep working unchanged on every station.

---
 drivers/platform/x86/asus-armoury.c        | 53 +++++++++++++---------
 drivers/platform/x86/asus-wmi.c            | 29 ++++++++++++
 include/linux/platform_data/x86/asus-wmi.h | 11 +++++
 3 files changed, 71 insertions(+), 22 deletions(-)
drivers/platform/x86/asus-armoury.c +31 -22
index fb382de5b57b..6cc5f0f6b3f5 100644
@@ -538,13 +538,27 @@ static ssize_t dgpu_disable_current_value_store(struct kobject *kobj,
 ASUS_WMI_SHOW_INT(dgpu_disable_current_value, ASUS_WMI_DEVID_DGPU);
 ASUS_ATTR_GROUP_BOOL(dgpu_disable, "dgpu_disable", "Disable the dGPU");
 
-/* Values map for eGPU activation requests. */
-static u32 egpu_status_map[] = {
-	[0] = 0x00000000U,
-	[1] = 0x00000001U,
-	[2] = 0x00000101U,
-	[3] = 0x00000201U,
-};
+/*
+ * egpu_default_enable_value() - Activation value for the connected station
+ *
+ * The eGPU switch activation value selects the vendor of the external
+ * GPU: 0x0001 activates NVIDIA, 0x0101 AMD and 0x0201 Intel. Pick the
+ * value matching the GPU vendor reported for the connected station,
+ * and fall back to NVIDIA when no vendor has been reported.
+ *
+ * Return: the activation value for the reported GPU vendor
+ */
+static u32 egpu_default_enable_value(void)
+{
+	switch (asus_wmi_egpu_vendor()) {
+	case PCI_VENDOR_ID_ATI:
+		return 0x0101;
+	case PCI_VENDOR_ID_INTEL:
+		return 0x0201;
+	default:
+		return 0x0001;
+	}
+}
 
 /*
  * armoury_pci_rescan() - Performs a PCI rescan
@@ -578,9 +592,14 @@ static ssize_t egpu_enable_current_value_store(struct kobject *kobj, struct kobj
 	if (err)
 		return err;
 
-	if (requested >= ARRAY_SIZE(egpu_status_map))
+	if (requested > 1)
 		return -EINVAL;
-	enable = egpu_status_map[requested];
+
+	/*
+	 * 0 deactivates the eGPU, 1 activates it with the value matching
+	 * the GPU reported for the connected station.
+	 */
+	enable = requested ? egpu_default_enable_value() : 0;
 
 	scoped_guard(mutex, &asus_armoury.egpu_mutex) {
 		/* Ensure the eGPU is connected before attempting to activate it. */
@@ -661,7 +680,7 @@ static ssize_t egpu_enable_current_value_store(struct kobject *kobj, struct kobj
 static ssize_t egpu_enable_current_value_show(struct kobject *kobj, struct kobj_attribute *attr,
 						char *buf)
 {
-	int i, err;
+	int err;
 	u32 status;
 
 	scoped_guard(mutex, &asus_armoury.egpu_mutex) {
@@ -670,20 +689,10 @@ static ssize_t egpu_enable_current_value_show(struct kobject *kobj, struct kobj_
 			return err;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(egpu_status_map); i++) {
-		if (egpu_status_map[i] == status)
-			return sysfs_emit(buf, "%u\n", i);
-	}
-
-	return -EIO;
+	return sysfs_emit(buf, "%u\n", status != 0);
 }
 
-static ssize_t egpu_enable_possible_values_show(struct kobject *kobj, struct kobj_attribute *attr,
-						char *buf)
-{
-	return armoury_attr_enum_list(buf, ARRAY_SIZE(egpu_status_map));
-}
-ASUS_ATTR_GROUP_ENUM(egpu_enable, "egpu_enable", "Enable the eGPU (also disables dGPU)");
+ASUS_ATTR_GROUP_BOOL(egpu_enable, "egpu_enable", "Enable the eGPU (also disables dGPU)");
 
 /* Device memory available to APU */
 
drivers/platform/x86/asus-wmi.c +29 -0
index a65090429ca7..40b4cf32c0ac 100644
@@ -881,6 +881,35 @@ static DEVICE_ATTR_RW(dgpu_disable);
 #endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */
 
 /* eGPU ********************************************************************/
+
+static u16 egpu_gpu_vendor;
+
+/**
+ * asus_wmi_egpu_set_vendor() - Report the vendor of the external GPU
+ * @vendor: PCI vendor ID of the GPU installed in the connected eGPU
+ * station, or 0 to fall back to the default activation value
+ *
+ * Drivers that detect an eGPU station report the vendor of the GPU
+ * they found so that the eGPU activation can use the matching value.
+ */
+void asus_wmi_egpu_set_vendor(u16 vendor)
+{
+	egpu_gpu_vendor = vendor;
+}
+EXPORT_SYMBOL_NS_GPL(asus_wmi_egpu_set_vendor, "ASUS_WMI");
+
+/**
+ * asus_wmi_egpu_vendor() - Vendor of the external GPU
+ *
+ * Return: the PCI vendor ID last reported with
+ * asus_wmi_egpu_set_vendor(), or 0 when no station is known
+ */
+u16 asus_wmi_egpu_vendor(void)
+{
+	return egpu_gpu_vendor;
+}
+EXPORT_SYMBOL_NS_GPL(asus_wmi_egpu_vendor, "ASUS_WMI");
+
 #if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS)
 static ssize_t egpu_enable_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
include/linux/platform_data/x86/asus-wmi.h +11 -0
index b5ed8c83ace1..a53b2828bb1d 100644
@@ -204,6 +204,8 @@ int asus_hid_register_listener(struct asus_hid_listener *cdev);
 void asus_hid_unregister_listener(struct asus_hid_listener *cdev);
 int asus_hid_event(enum asus_hid_event event);
 bool asus_wmi_custom_fan_curve_is_enabled(void);
+void asus_wmi_egpu_set_vendor(u16 vendor);
+u16 asus_wmi_egpu_vendor(void);
 #else
 static inline void set_ally_mcu_hack(enum asus_ally_mcu_hack status)
 {
@@ -239,6 +241,15 @@ static inline bool asus_wmi_custom_fan_curve_is_enabled(void)
 {
 	return false;
 }
+
+static inline void asus_wmi_egpu_set_vendor(u16 vendor)
+{
+}
+
+static inline u16 asus_wmi_egpu_vendor(void)
+{
+	return 0;
+}
 #endif
 
 #endif	/* __PLATFORM_DATA_X86_ASUS_WMI_H */
Signature · 1 line
2.47.3
author maintainer
#46 lore raw

PATCH v11 17/18 HID: asus: report the XG Mobile GPU vendor to asus-wmi

In reply to Denis Benato

The version query answers with the 4-part PCI ID of the GPU installed in the station. Parse it, report its vendor part to asus-wmi as soon as the station is identified and clear it when the station goes away, so that enabling the eGPU through egpu_enable composes the right activation value for NVIDIA, AMD and Intel stations alike.

---
 drivers/hid/hid-asus.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/hid/hid-asus.c +16 -2
index e444cad85b32..244d103fbd4c 100644
@@ -186,6 +186,7 @@ struct asus_xgm_info {
 	char part_number[ASUS_XGM_INFO_LEN];
 	char firmware_version[ASUS_XGM_INFO_LEN];
 	char generation[ASUS_XGM_INFO_LEN];
+	u8 gpu_id[4];
 };
 
 struct asus_touchpad_info {
@@ -6313,6 +6314,12 @@ static int asus_xgm_get_version(struct hid_device *hdev,
 	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
 			 buf, len, "VER");
 
+	/* the 4-part PCI ID of the GPU installed in the station: buf[3..10] */
+	if (len < 11)
+		return -ENODATA;
+
+	memcpy(info->gpu_id, buf + 3, sizeof(info->gpu_id));
+
 	return 0;
 }
 
@@ -6685,6 +6692,8 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
 			 info->firmware_version, info->generation);
 
+	asus_wmi_egpu_set_vendor(info->gpu_id[0]);
+
 	/*
 	 * The attribute group is not devm-managed: a creation failure is
 	 * fatal and unwound through asus_xgm_init_err, while on the unbind
@@ -6732,6 +6741,7 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 
 	return 0;
 asus_xgm_init_err:
+	asus_wmi_egpu_set_vendor(0);
 	sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
 	drvdata->xgm_info = NULL;
 	drvdata->xgm_led = NULL;
@@ -6951,8 +6961,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
-	if (drvdata->xgm_info)
+	if (drvdata->xgm_info) {
+		asus_wmi_egpu_set_vendor(0);
 		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	}
 
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
@@ -6972,8 +6984,10 @@ static void asus_remove(struct hid_device *hdev)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
-	if (drvdata->xgm_info)
+	if (drvdata->xgm_info) {
+		asus_wmi_egpu_set_vendor(0);
 		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	}
 
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
Signature · 1 line
2.47.3
#47 lore raw

Re: [PATCH v11 17/18] HID: asus: report the XG Mobile GPU vendor to asus-wmi

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] HID: asus: u8 gpu_id[4] truncates 16-bit PCI vendor ID in asus_xgm_init() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] HID: asus: u8 gpu_id[4] truncates 16-bit PCI vendor ID in asus_xgm_init() --

commit 739505f96f6292806a14e712690bf33782dd803a
Author: Denis Benato <[email protected]>

HID: asus: report the XG Mobile GPU vendor to asus-wmi

This commit parses the 4-part GPU PCI ID from the XG Mobile station version query response and reports the GPU vendor ID to asus-wmi on initialization, clearing it when the station is unbound.

Quoted 26 lines
drivers/hid/hid-asus.c +7 -0
index e444cad85b32c..244d103fbd4c8 100644
@@ -186,6 +186,7 @@ struct asus_xgm_info {
 	char part_number[ASUS_XGM_INFO_LEN];
 	char firmware_version[ASUS_XGM_INFO_LEN];
 	char generation[ASUS_XGM_INFO_LEN];
+	u8 gpu_id[4];
 };
 
 struct asus_touchpad_info {
@@ -6313,6 +6314,12 @@ static int asus_xgm_get_version(struct hid_device *hdev,
 	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
 			 buf, len, "VER");
 
+	/* the 4-part PCI ID of the GPU installed in the station: buf[3..10] */
+	if (len < 11)
+		return -ENODATA;
+
+	memcpy(info->gpu_id, buf + 3, sizeof(info->gpu_id));
+
 	return 0;
 }
 

drivers/hid/hid-asus.c static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata) · line 6695

Quoted 4 lines
drivers/hid/hid-asus.c +1 -0
@@ -6685,6 +6692,8 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
 			 info->firmware_version, info->generation);
 
+	asus_wmi_egpu_set_vendor(info->gpu_id[0]);

[Severity: High]
Does declaring gpu_id as u8 gpu_id[4] in struct asus_xgm_info truncate the 16-bit PCI vendor ID to a single byte?

In asus_xgm_get_version(), the comment and length check expect the 4-part PCI ID to occupy 8 bytes in buf[3..10] (four 16-bit fields), but sizeof(info->gpu_id) is 4, so memcpy() only copies buf[3..6].

When asus_probe() -> asus_xgm_init() calls asus_wmi_egpu_set_vendor(info->gpu_id[0]), it passes a single u8 value (0x00..0xff) to asus_wmi_egpu_set_vendor(u16 vendor). Downstream in drivers/platform/x86/asus-armoury.c:egpu_default_enable_value():

static u32 egpu_default_enable_value(void)

{
	switch (asus_wmi_egpu_vendor()) {
	case PCI_VENDOR_ID_ATI:
		return 0x0101;
	case PCI_VENDOR_ID_INTEL:
		return 0x0201;
	default:
		return 0x0001;
	}
}

the 8-bit value can never match the 16-bit constants PCI_VENDOR_ID_ATI (0x1002) or PCI_VENDOR_ID_INTEL (0x8086), causing egpu_enable to always fall back to 0x0001.

Should gpu_id be a 4-element 16-bit array (such as u16 gpu_id[4] or __le16 gpu_id[4] with the appropriate endianness conversion) so the full 8-byte PCI ID is stored and the 16-bit vendor ID is passed to asus_wmi_egpu_set_vendor()?

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

Re: [PATCH v11 17/18] HID: asus: report the XG Mobile GPU vendor to asus-wmi

In reply to Denis Benato
Quoted 24 lines · Denis Benato

The version query answers with the 4-part PCI ID of the GPU installed in the station. Parse it, report its vendor part to asus-wmi as soon as the station is identified and clear it when the station goes away, so that enabling the eGPU through egpu_enable composes the right activation value for NVIDIA, AMD and Intel stations alike.

---
 drivers/hid/hid-asus.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/hid/hid-asus.c +1 -0
index e444cad85b32..244d103fbd4c 100644
@@ -186,6 +186,7 @@ struct asus_xgm_info {
 	char part_number[ASUS_XGM_INFO_LEN];
 	char firmware_version[ASUS_XGM_INFO_LEN];
 	char generation[ASUS_XGM_INFO_LEN];
+	u8 gpu_id[4];
 };
 
 struct asus_touchpad_info {

drivers/hid/hid-asus.c static int asus_xgm_get_version(struct hid_device *hdev, · line 6321

Quoted 8 lines
drivers/hid/hid-asus.c +5 -0
@@ -6313,6 +6314,12 @@ static int asus_xgm_get_version(struct hid_device *hdev,
 	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
 			 buf, len, "VER");
 
+	/* the 4-part PCI ID of the GPU installed in the station: buf[3..10] */
+	if (len < 11)
+		return -ENODATA;
+
+	memcpy(info->gpu_id, buf + 3, sizeof(info->gpu_id));

Is this 3 also related to tag length (the literals comment I had to the other patch)?

--
i.

Quoted 46 lines
drivers/hid/hid-asus.c +10 -2
+
 	return 0;
 }
 
@@ -6685,6 +6692,8 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
 			 info->firmware_version, info->generation);
 
+	asus_wmi_egpu_set_vendor(info->gpu_id[0]);
+
 	/*
 	 * The attribute group is not devm-managed: a creation failure is
 	 * fatal and unwound through asus_xgm_init_err, while on the unbind
@@ -6732,6 +6741,7 @@ static int asus_xgm_init(struct hid_device *hdev, struct asus_drvdata *drvdata)
 
 	return 0;
 asus_xgm_init_err:
+	asus_wmi_egpu_set_vendor(0);
 	sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
 	drvdata->xgm_info = NULL;
 	drvdata->xgm_led = NULL;
@@ -6951,8 +6961,10 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
-	if (drvdata->xgm_info)
+	if (drvdata->xgm_info) {
+		asus_wmi_egpu_set_vendor(0);
 		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	}
 
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
@@ -6972,8 +6984,10 @@ static void asus_remove(struct hid_device *hdev)
 	if (drvdata->listener.brightness_set)
 		asus_hid_unregister_listener(&drvdata->listener);
 
-	if (drvdata->xgm_info)
+	if (drvdata->xgm_info) {
+		asus_wmi_egpu_set_vendor(0);
 		sysfs_remove_group(&hdev->dev.kobj, &asus_xgm_attr_group);
+	}
 
 	if (drvdata->xgm_led)
 		devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev);
author maintainer
#49 lore raw

PATCH v11 18/18 MAINTAINERS: add maintainer for the ASUS HID driver

In reply to Denis Benato

I already maintain the ASUS drivers in platform/x86, know these devices well, have contributed in reviewing and bugfixing and have a lot more work pending so I volunteer on helping making this driver
better: give hid-asus.c a dedicated entry and list me as its maintainer.

---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index 4a69da715c58..1a3cca5c5f5f 100644
@@ -4135,6 +4135,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/hwmon/asus-ec-sensors.c
 
+ASUS HID DRIVER
+M:	Denis Benato <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/hid/hid-asus.c
+
 ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS
 M:	Corentin Chary <[email protected]>
 M:	Luke D. Jones <[email protected]>
Signature · 1 line
2.47.3
maintainer
#50 lore raw
In reply to Denis Benato
Quoted 25 lines · Denis Benato

Hi all,

This patch series adds support for ROG Ally handhelds in the HID driver for ASUS devices.

The changes include reinitialization of the device after exiting a sleep state, gamepad configuration, vibration strength configuration, joysticks and triggers range configuration, anti-deadzone configuration, response curve support, force feedback support, gamepad mode support, turbo buttons support, and button remapping support.

This driver is based on the original Luke's work, which was a great starting point and I have reworked it to be upstreamable, while keeping the original functionality intact and extending hid-asus to avoid regressions in functionality such as the backlight control.

The ally support has been a surprisingly long task, spanning multiple years and being used in Steam OS and well as other distributions for quite a while, and I am happy to finally be submitting it.

At this time LEDs are not part of the patch series as I have work in progress to unify LEDs handling across all ASUS devices, and I will submit that in a separate patch series when the userspace interface will be ready to express capabilities of these devices, but that will take some more time.

Quoted 4 lines

This driver is the culmination of a lot of work, from many different people, and I want to thank Luke for his original work, as well as the many people that have helped me test and provide feedback on the driver: Khamunetri, Jonathan, Derek, Matthew and others that have helped during these years.

I've not read it mostly through.

I'm far from convinced when it comes to the locking. I always find it very suspicious when a lock is taken just to read/write a variabl, as immediately after releasing the lock, the protection is lost so the locks look either overkill (just a barrier would suffice for racing with init) or unsafe (racing with uninit/remove). My head hurts enough from all the readong so I don't want go figure out which one it is.

Code quality varies a lot, there are some fragments that seem almost braindead but then some other parts use modern things like cleanup.h helpers, so it's a mixed bag. My suggestion is would be for you to do a full self-review of the series so you could catch the bits I missed (I know it's a lot of lines, but hey, I've read it myself now so I know what it means to review it through(!)). I know you generally seem able to provide good review feedback for others and write clean looking patches so it's probably just some of the code originates from other people and you've not just looked enough lines to clean it up properly.

--
i.

Quoted 352 lines

Best regards,
Denis Benato

Link v1: https://lore.kernel.org/all/[email protected]/
Link v2: https://lore.kernel.org/all/[email protected]/
Link v3: https://lore.kernel.org/all/[email protected]/
Link v4: https://lore.kernel.org/all/[email protected]/
Link v5: https://lore.kernel.org/all/[email protected]/
Link v6: https://lore.kernel.org/all/[email protected]/
Link v7: https://lore.kernel.org/all/[email protected]/
Link v8: https://lore.kernel.org/all/[email protected]/
Link v9: https://lore.kernel.org/all/[email protected]/
Link v10: https://lore.kernel.org/all/[email protected]/

Version v11 has been more involved and I focused on two main things: extending the xg mobile (which the ROG ally is one of the few models that supports it) and properly handling hid packet sizes because it has been a constant source of issues and fight in the past and I want to put an end to both of those.

I kindly ask Rebecca and Paolo to try using the new asus_report_len() to see if its also suitable for theirs Zenbook Duo devices and if so to adopt it in theirs patches as well.

Link of a relevant patchset: https://lore.kernel.org/all/[email protected]/

Version v10 drops a patch already merged as part of XG mobile and applies the patchset on top of for-next/7.4.

With v8 the driver does sysfs_notify after successfully changing configuration attributes so that userspace can be notified of the changes immediately.

With v7 the series is rebased on top of the asus tree: the first patch of v6 has been applied upstream as 8099f9da59f1 ("HID: asus: do not send keyboard init reports to touchpads"), so this series is now 12 patches.

The probe paths of the ally interfaces now reserve the interface role while their initialization is running, the configuration attributes work from the moment their files exist and a failed initialization rolls the configuration back instead of leaving the created sysfs groups behind. The response curve is no longer configured entry by entry: a single attribute per joystick now takes the whole curve in one validated write, and a companion index file documents what each value is.

With v5 I returned to the original manual management of memory and sysfs groups as going devm did not play well with the general "plugin" architecture of the ally portion of the driver and has caused more bugs than it solved: sashiko-bot will have to come to terms with hand-managed memory this time.

Changelog:

(quoted diff) +0 -10
-v2
  - HID: asus: add support for ROG Ally handhelds
   - release all vendor buttons on resume
   - align arguments of hid_asus_ally_raw_event()
  - HID: asus: add gamepad configuration
   - clean up comments and kernel-doc
  - HID: asus: add vibration strength configuration
   - clean up comments and kernel-doc
  - HID: asus: add joysticks inner and outer range configuration
   - clean up comments and kernel-doc
  - HID: asus: add triggers inner and outer range configuration
   - clean up comments and kernel-doc
  - HID: asus: add joysticks anti-deadzone configuration
   - clean up comments and kernel-doc
  - HID: asus: add support for response curve
   - normalize kernel-doc comment
  - HID: asus: add support to force feedback
   - remove a stale comment
  - HID: asus: add support for gamepad mode
   - remove a stale comment, normalize kernel-doc
  - HID: asus: add support for turbo buttons
   - remove stale comments, normalize kernel-doc
  - HID: asus: add support for btn remapping
   - convert function comments to kernel-doc
 
-v3
  - HID: asus: add support for ROG Ally handhelds
   - take references on input devices to avoid use-after-free on unbind
   - reject probes from USB devices other than the recorded controller
   - add open/close callbacks to the gamepad input device
   - keyboard_input is populated after hid_hw_start(): issue does not apply
  - HID: asus: add gamepad configuration
   - restore cached Xbox controller mode after an MCU reset
   - convert remaining scoped_guard() users to guard()
   - avoid printing "(null)" for unnamed sysfs groups
  - HID: asus: add vibration strength configuration
   - send MCU commands through ally_gamepad_send_packet()
  - HID: asus: add joysticks inner and outer range configuration
   - send MCU commands through ally_gamepad_send_packet()
   - gate sysfs groups and callbacks on capabilities
  - HID: asus: add triggers inner and outer range configuration
   - send MCU commands through ally_gamepad_send_packet()
   - gate sysfs groups and callbacks on capabilities
  - HID: asus: add joysticks anti-deadzone configuration
   - send MCU commands through ally_gamepad_send_packet()
   - gate sysfs groups and callbacks on capabilities
  - HID: asus: add support for response curve
   - send MCU commands through ally_gamepad_send_packet()
   - check resp_curve_support in show callbacks too
  - HID: asus: add support to force feedback
   - read ally_x_hdev under ally_data_lock and take a reference on it
   - publish ally_x_hdev before registering the input device
  - HID: asus: add support for gamepad mode
   - convert remaining scoped_guard() users to guard()
  - HID: asus: add support for turbo buttons
   - pass the config pointer directly to ally_config_remove()
   - run ally_config_remove() outside ally_data_lock
   - restore cached values when the hardware rejects an update
   - check turbo_support in show callbacks too
   - reported scoped_guard warning verified as false positive
  - HID: asus: add support for btn remapping
   - look up default mappings by name instead of array index
   - resend the old mapping when a sequential update fails midway
   - allow macros regardless of the gamepad mode
   - rename PAD_* codes to proper input event names
   - convert remaining scoped_guard() users to guard()
 
- v4
  - HID: asus: do not send keyboard init reports to touchpads
    - Added to avoid regressting touchpads and as guidance for maintainers
  - HID: asus: reinitialize the device after exiting a sleep state
    - Follow the modified logic of the previous patch
  - Addressed issues of sashiko-bot albeit one was a false positive
  - Rework patches: I made some disasters rebasing in v3
 
- v5
  - HID: asus: add support for ROG Ally handhelds
    - Fix UAF due to inverted input device ownership in hid_asus_ally_remove()
    - Reject probes claiming an interface role that is already owned
  - HID: asus: add gamepad configuration
    - Keep the configuration allocated until module removal instead of
      devm-managing it: the sysfs callbacks must be able to outlive probe
    - Undo sysfs group creation manually on the error path and in
      ally_config_remove(): creation and removal are now symmetric
    - Add payloads size check in ally_alloc_cmd()
  - HID: asus: add vibration strength configuration
    - Restore the cached vibration intensity after an MCU reset
  - HID: asus: add joysticks inner and outer range configuration
    - Restore the cached joystick thresholds after an MCU reset
    - Remove the calibration sysfs groups manually like the other ones
  - HID: asus: add triggers inner and outer range configuration
    - Restore the cached trigger ranges after an MCU reset
  - HID: asus: add joysticks anti-deadzone configuration
    - Restore the cached anti-deadzone values after an MCU reset
  - HID: asus: add support for response curve
    - Restore the cached response curves after an MCU reset
    - Keep holding config_mutex until the curve packet has been sent
  - HID: asus: add support to force feedback
    - Serialize the cross-interface force-feedback sends with the gamepad
      interface removal by holding intf_mutex in the callers
  - HID: asus: add support for gamepad mode
    - Restore the recorded gamepad mode after an MCU reset
  - HID: asus: add support for turbo buttons
    - Fix UAF allocating the turbo button entries with kcalloc
    - Restore the cached turbo parameters after an MCU reset
  - HID: asus: add support for btn remapping
    - Keep the button mappings outside of the controller lifetime, so
      that the recorded configuration survives a re-probe
    - Re-apply the recorded mappings after an MCU reset
    - Fetch the configuration through ally_get_config()
 
- v6
  - HID: asus: add support for ROG Ally handhelds
    - Add a maximum size check in ally_alloc_cmd()
    - Drop the dead x_hdev snapshot taken in hid_asus_ally_raw_event()
    - Drop the unused hdev parameter of handle_ctrl_alt_del()
    - Drop the unused hdev/report parameters of ally_x_raw_event()
    - Turn the "// F20;" comment into a proper "/* F20 */"
  - HID: asus: add gamepad configuration
    - Publish the configuration (ally->config under ally_data_lock)
      before the sysfs groups are created and withdraw it on the error
      path: attributes could become visible while ally_get_config()
      still returned NULL and the restore path silently did nothing
    - Record the Xbox controller mode in the first-setup defaults and
      apply the recorded value from hid_asus_ally_init()
    - properly rebase ally_alloc_cmd(): make it no change from previous patch
  - HID: asus: add joysticks inner and outer range configuration
    - Drop the unused cfg parameter of ally_set_joystick_thresholds()
  - HID: asus: add triggers inner and outer range configuration
    - Drop the unused cfg parameter of ally_set_trigger_ranges()
    - Fix a commit message typo: "sensitivity"
  - HID: asus: add support for response curve
    - Add ally_resp_curve_is_valid() and use it in the init/resume
      restore path exactly like the apply path does
    - Drop the unused struct device * parameter of the four
      response-curve helpers
  - HID: asus: add support to force feedback
    - Drop the unused pointers from ally_x_send_ff_report() and ally_x_send_ff_off()
  - HID: asus: add support for gamepad mode
    - Apply the mode exactly once from hid_asus_ally_init()
  - HID: asus: add support for turbo buttons
    - Remove the calibration groups created before a sysfs failure
  - HID: asus: add support for btn remapping
    - Do not gate remapping by turbo
    - Reject NULL remap/macro pointers in ally_set_button_mapping()
    - Carry the ally pointer in struct button_remap_attr
    - Fix the "hypen" comment typo
 
- v7
  - The "HID: asus: do not send keyboard init reports to touchpads" patch
    is not part of this series anymore: it has been applied upstream as
    8099f9da59f1 and the series is rebased on top of it
  - HID: asus: add support for ROG Ally handhelds
    - Reserve the probed interface role for the whole duration of its
      sleeping initialization: a concurrent probe of the same role could
      pass the singleton checks before the first one published its pointer
  - HID: asus: add gamepad configuration
    - Publish drvdata->rog_ally before the configuration attributes are
      created: the callbacks fetched it before asus_probe() published it
      and returned -ENODEV in the meantime
    - Roll the configuration back with ally_config_remove() when
      hid_asus_ally_init() fails, instead of leaking the created sysfs
      groups and the button entries
  - HID: asus: add support for response curve
    - Replace response_curve_pct_1..4, response_curve_move_1..4 and the
      apply attributes with one response_curve attribute per joystick that
      takes the whole curve in a single validated all-or-nothing write:
      staged partial edits reaching the MCU on resume cannot happen anymore
    - Add a read-only response_curve_index attribute documenting the
      meaning of each value
    - Restore both curves unconditionally on init/resume: only validated
      curves are recorded now
  - HID: asus: add support for btn remapping
    - Drop the stale cfg->turbo_support gate in ally_config_create():
      remapping attributes are created for every device with button
      directories, not only turbo-capable ones
 
- v8
  - HID: asus: add support for ROG Ally handhelds
    - Release the probe reservation when the interface pointer is
      published: the flags were only cleared on failure, leaving them
      stuck set after the first bind and rejecting every later probe
      of that role
    - Reserve the keyboard interface role too: its check and its
      publication were two separate locked sections, so concurrent
      probes of the same role could both publish
    - Keep the recorded USB device while any probe is still in flight
  - HID: asus: add gamepad configuration
    - Report the missing Xbox controller capability with -EOPNOTSUPP
  - HID: asus: add vibration strength configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add joysticks inner and outer range configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add triggers inner and outer range configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add joysticks anti-deadzone configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add support for response curve
    - Wake pollers with sysfs_notify() after a successful curve write
  - HID: asus: add support to force feedback
    - Clear the rumble update latch on setup so a fresh interface
      cannot inherit one left over from a teardown race
  - HID: asus: add support for gamepad mode
    - Return -EIO for invalid gamepad modes stored in the device
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add support for turbo buttons
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add support for btn remapping
    - Return -EIO if a mapping is ever found unset instead of
      dereferencing it
    - Wake pollers with sysfs_notify() after remap and macro writes,
      and after a mode switch re-defaults the mappings
 
- v9
  - HID: asus: add support to force feedback
    - Hold intf_mutex while unpublishing the gamepad interface in the
      setup error path, like hid_asus_ally_remove() does
    - Improve gamepad interface device lock around the initialization
      force-feedback send
  - HID: asus: add support for btn remapping
    - Unpublish button_entries under config_mutex before removing the
      attributes and freeing the array
 
- v10
  - HID: asus: reinitialize the device after exiting a sleep state
    - Dropped as already merged in XG Mobile patchset
 
- v11
  - HID: asus: add support for ROG Ally handhelds
    - Split the chained data[1] = data[3] = 0x00 assignment into two
      statements
    - Align the hid_asus_ally_raw_event() continuation line with the
      opening parenthesis
  - HID: asus: add gamepad configuration
    - Add the missing blank line between struct hid_driver and
      asus_init()
  - HID: asus: add joysticks inner and outer range configuration
    - Align the sysfs_remove_group() and hid_warn() continuation lines
      with the opening parenthesis
  - HID: asus: add triggers inner and outer range configuration
    - Align the hid_warn() continuation lines with the opening
      parenthesis
  - HID: asus: add joysticks anti-deadzone configuration
    - Align the hid_warn() continuation lines with the opening
      parenthesis
  - HID: asus: add support for response curve
    - Drop the duplicate blank line before ally_config_attrs[]
  - HID: asus: add support to force feedback
    - Add the missing blank line before the static_assert
    - Align the hid_warn() continuation line with the opening
      parenthesis
  - HID: asus: add support for btn remapping
    - Align the hid_warn() and ally_set_button_mapping() continuation
      lines with the opening parenthesis
  - HID: asus: size feature reports from the HID report descriptor
    - New patch
  - HID: asus: identify XG Mobile stations and bind the LED to the
    reported model
    - New patch
  - HID: asus: expose XG Mobile identity and firmware information
    - New patch
  - HID: asus: size ally gamepad commands from the HID report descriptor
    - New patch
  - platform/x86: asus-armoury: pick the eGPU activation from the
    reported GPU
    - New patch
  - HID: asus: report the XG Mobile GPU vendor to asus-wmi
    - New patch
  - MAINTAINERS: add maintainer for the ASUS HID driver
    - New patch

Denis Benato (18):
HID: asus: add support for ROG Ally handhelds
HID: asus: add gamepad configuration
HID: asus: add vibration strength configuration
HID: asus: add joysticks inner and outer range configuration
HID: asus: add triggers inner and outer range configuration
HID: asus: add joysticks anti-deadzone configuration
HID: asus: add support for response curve
HID: asus: add support to force feedback
HID: asus: add support for gamepad mode
HID: asus: add support for turbo buttons
HID: asus: add support for btn remapping
HID: asus: size feature reports from the HID report descriptor
HID: asus: identify XG Mobile stations and bind the LED to the
reported model
HID: asus: expose XG Mobile identity and firmware information
HID: asus: size ally gamepad commands from the HID report descriptor platform/x86: asus-armoury: pick the eGPU activation from the reported
GPU
HID: asus: report the XG Mobile GPU vendor to asus-wmi
MAINTAINERS: add maintainer for the ASUS HID driver

 MAINTAINERS                                |    6 +
 drivers/hid/Kconfig                        |    1 +
 drivers/hid/hid-asus.c                     | 5457 +++++++++++++++++++-
 drivers/platform/x86/asus-armoury.c        |   53 +-
 drivers/platform/x86/asus-wmi.c            |   29 +
 include/linux/platform_data/x86/asus-wmi.h |   11 +
 6 files changed, 5474 insertions(+), 83 deletions(-)
Signature · 1 line
 i.
author maintainer
#51 lore raw
Quoted 31 lines · Ilpo Järvinen
Quoted 25 lines · Denis Benato

Hi all,

This patch series adds support for ROG Ally handhelds in the HID driver for ASUS devices.

The changes include reinitialization of the device after exiting a sleep state, gamepad configuration, vibration strength configuration, joysticks and triggers range configuration, anti-deadzone configuration, response curve support, force feedback support, gamepad mode support, turbo buttons support, and button remapping support.

This driver is based on the original Luke's work, which was a great starting point and I have reworked it to be upstreamable, while keeping the original functionality intact and extending hid-asus to avoid regressions in functionality such as the backlight control.

The ally support has been a surprisingly long task, spanning multiple years and being used in Steam OS and well as other distributions for quite a while, and I am happy to finally be submitting it.

At this time LEDs are not part of the patch series as I have work in progress to unify LEDs handling across all ASUS devices, and I will submit that in a separate patch series when the userspace interface will be ready to express capabilities of these devices, but that will take some more time.

Quoted 4 lines

This driver is the culmination of a lot of work, from many different people, and I want to thank Luke for his original work, as well as the many people that have helped me test and provide feedback on the driver: Khamunetri, Jonathan, Derek, Matthew and others that have helped during these years.

Quoted 8 lines

I've not read it mostly through.

I'm far from convinced when it comes to the locking. I always find it very suspicious when a lock is taken just to read/write a variabl, as immediately after releasing the lock, the protection is lost so the locks look either overkill (just a barrier would suffice for racing with init) or unsafe (racing with uninit/remove). My head hurts enough from all the readong so I don't want go figure out which one it is.

Ilpo and Sakari,

Thank you very much! It's very good to see an actual review after all this time! Well it has been 3-4 months but feels a very long time.

The first version of this was posted in the lkml in 2024 and after that only sashiko-bot provided more inputs so I followed that, perhaps too much.

It's very good to see humans!

Quoted 9 lines

Code quality varies a lot, there are some fragments that seem almost braindead but then some other parts use modern things like cleanup.h helpers, so it's a mixed bag. My suggestion is would be for you to do a full self-review of the series so you could catch the bits I missed (I know it's a lot of lines, but hey, I've read it myself now so I know what it means to review it through(!)). I know you generally seem able to provide good review feedback for others and write clean looking patches so it's probably just some of the code originates from other people and you've not just looked enough lines to clean it up properly.

Yeah... When I picked up Luke's work I took a lot of time (months) to modernize the source as much as possible, then sashiko-bot found problem and either me or glm fixed something, both of us reflecting how we woke up that morning, plus back and forth with issues and things changed one way and back when I realized the approach was going nowhere... And code that worked that was later changed leaving it suboptimal... Loads of changes from both humans and LLMs (albeit the main culprit is me hahahah).

The xgm code was put together in two days from captures I ran in windows while also fixing the MSI claw...

I'm not surprised this is a mixed bag. Oh well, I'm going to clean it up and make it very cool... And I am already having ideas on how to replace the complex probe machinery that prevents rogue devices with something more readable (and hopefully less long, because more than 5k lines of dense hid code is by far the longest modification I have ever attempted to linux).

I will take some days to properly review this and address comments over time! Thank you very much again!

Best regards,
Denis Benato

Quoted 357 lines

--
i.

Quoted 352 lines

Best regards,
Denis Benato

Link v1: https://lore.kernel.org/all/[email protected]/
Link v2: https://lore.kernel.org/all/[email protected]/
Link v3: https://lore.kernel.org/all/[email protected]/
Link v4: https://lore.kernel.org/all/[email protected]/
Link v5: https://lore.kernel.org/all/[email protected]/
Link v6: https://lore.kernel.org/all/[email protected]/
Link v7: https://lore.kernel.org/all/[email protected]/
Link v8: https://lore.kernel.org/all/[email protected]/
Link v9: https://lore.kernel.org/all/[email protected]/
Link v10: https://lore.kernel.org/all/[email protected]/

Version v11 has been more involved and I focused on two main things: extending the xg mobile (which the ROG ally is one of the few models that supports it) and properly handling hid packet sizes because it has been a constant source of issues and fight in the past and I want to put an end to both of those.

I kindly ask Rebecca and Paolo to try using the new asus_report_len() to see if its also suitable for theirs Zenbook Duo devices and if so to adopt it in theirs patches as well.

Link of a relevant patchset: https://lore.kernel.org/all/[email protected]/

Version v10 drops a patch already merged as part of XG mobile and applies the patchset on top of for-next/7.4.

With v8 the driver does sysfs_notify after successfully changing configuration attributes so that userspace can be notified of the changes immediately.

With v7 the series is rebased on top of the asus tree: the first patch of v6 has been applied upstream as 8099f9da59f1 ("HID: asus: do not send keyboard init reports to touchpads"), so this series is now 12 patches.

The probe paths of the ally interfaces now reserve the interface role while their initialization is running, the configuration attributes work from the moment their files exist and a failed initialization rolls the configuration back instead of leaving the created sysfs groups behind. The response curve is no longer configured entry by entry: a single attribute per joystick now takes the whole curve in one validated write, and a companion index file documents what each value is.

With v5 I returned to the original manual management of memory and sysfs groups as going devm did not play well with the general "plugin" architecture of the ally portion of the driver and has caused more bugs than it solved: sashiko-bot will have to come to terms with hand-managed memory this time.

Changelog:

(quoted diff) +0 -10
-v2
  - HID: asus: add support for ROG Ally handhelds
   - release all vendor buttons on resume
   - align arguments of hid_asus_ally_raw_event()
  - HID: asus: add gamepad configuration
   - clean up comments and kernel-doc
  - HID: asus: add vibration strength configuration
   - clean up comments and kernel-doc
  - HID: asus: add joysticks inner and outer range configuration
   - clean up comments and kernel-doc
  - HID: asus: add triggers inner and outer range configuration
   - clean up comments and kernel-doc
  - HID: asus: add joysticks anti-deadzone configuration
   - clean up comments and kernel-doc
  - HID: asus: add support for response curve
   - normalize kernel-doc comment
  - HID: asus: add support to force feedback
   - remove a stale comment
  - HID: asus: add support for gamepad mode
   - remove a stale comment, normalize kernel-doc
  - HID: asus: add support for turbo buttons
   - remove stale comments, normalize kernel-doc
  - HID: asus: add support for btn remapping
   - convert function comments to kernel-doc
 
-v3
  - HID: asus: add support for ROG Ally handhelds
   - take references on input devices to avoid use-after-free on unbind
   - reject probes from USB devices other than the recorded controller
   - add open/close callbacks to the gamepad input device
   - keyboard_input is populated after hid_hw_start(): issue does not apply
  - HID: asus: add gamepad configuration
   - restore cached Xbox controller mode after an MCU reset
   - convert remaining scoped_guard() users to guard()
   - avoid printing "(null)" for unnamed sysfs groups
  - HID: asus: add vibration strength configuration
   - send MCU commands through ally_gamepad_send_packet()
  - HID: asus: add joysticks inner and outer range configuration
   - send MCU commands through ally_gamepad_send_packet()
   - gate sysfs groups and callbacks on capabilities
  - HID: asus: add triggers inner and outer range configuration
   - send MCU commands through ally_gamepad_send_packet()
   - gate sysfs groups and callbacks on capabilities
  - HID: asus: add joysticks anti-deadzone configuration
   - send MCU commands through ally_gamepad_send_packet()
   - gate sysfs groups and callbacks on capabilities
  - HID: asus: add support for response curve
   - send MCU commands through ally_gamepad_send_packet()
   - check resp_curve_support in show callbacks too
  - HID: asus: add support to force feedback
   - read ally_x_hdev under ally_data_lock and take a reference on it
   - publish ally_x_hdev before registering the input device
  - HID: asus: add support for gamepad mode
   - convert remaining scoped_guard() users to guard()
  - HID: asus: add support for turbo buttons
   - pass the config pointer directly to ally_config_remove()
   - run ally_config_remove() outside ally_data_lock
   - restore cached values when the hardware rejects an update
   - check turbo_support in show callbacks too
   - reported scoped_guard warning verified as false positive
  - HID: asus: add support for btn remapping
   - look up default mappings by name instead of array index
   - resend the old mapping when a sequential update fails midway
   - allow macros regardless of the gamepad mode
   - rename PAD_* codes to proper input event names
   - convert remaining scoped_guard() users to guard()
 
- v4
  - HID: asus: do not send keyboard init reports to touchpads
    - Added to avoid regressting touchpads and as guidance for maintainers
  - HID: asus: reinitialize the device after exiting a sleep state
    - Follow the modified logic of the previous patch
  - Addressed issues of sashiko-bot albeit one was a false positive
  - Rework patches: I made some disasters rebasing in v3
 
- v5
  - HID: asus: add support for ROG Ally handhelds
    - Fix UAF due to inverted input device ownership in hid_asus_ally_remove()
    - Reject probes claiming an interface role that is already owned
  - HID: asus: add gamepad configuration
    - Keep the configuration allocated until module removal instead of
      devm-managing it: the sysfs callbacks must be able to outlive probe
    - Undo sysfs group creation manually on the error path and in
      ally_config_remove(): creation and removal are now symmetric
    - Add payloads size check in ally_alloc_cmd()
  - HID: asus: add vibration strength configuration
    - Restore the cached vibration intensity after an MCU reset
  - HID: asus: add joysticks inner and outer range configuration
    - Restore the cached joystick thresholds after an MCU reset
    - Remove the calibration sysfs groups manually like the other ones
  - HID: asus: add triggers inner and outer range configuration
    - Restore the cached trigger ranges after an MCU reset
  - HID: asus: add joysticks anti-deadzone configuration
    - Restore the cached anti-deadzone values after an MCU reset
  - HID: asus: add support for response curve
    - Restore the cached response curves after an MCU reset
    - Keep holding config_mutex until the curve packet has been sent
  - HID: asus: add support to force feedback
    - Serialize the cross-interface force-feedback sends with the gamepad
      interface removal by holding intf_mutex in the callers
  - HID: asus: add support for gamepad mode
    - Restore the recorded gamepad mode after an MCU reset
  - HID: asus: add support for turbo buttons
    - Fix UAF allocating the turbo button entries with kcalloc
    - Restore the cached turbo parameters after an MCU reset
  - HID: asus: add support for btn remapping
    - Keep the button mappings outside of the controller lifetime, so
      that the recorded configuration survives a re-probe
    - Re-apply the recorded mappings after an MCU reset
    - Fetch the configuration through ally_get_config()
 
- v6
  - HID: asus: add support for ROG Ally handhelds
    - Add a maximum size check in ally_alloc_cmd()
    - Drop the dead x_hdev snapshot taken in hid_asus_ally_raw_event()
    - Drop the unused hdev parameter of handle_ctrl_alt_del()
    - Drop the unused hdev/report parameters of ally_x_raw_event()
    - Turn the "// F20;" comment into a proper "/* F20 */"
  - HID: asus: add gamepad configuration
    - Publish the configuration (ally->config under ally_data_lock)
      before the sysfs groups are created and withdraw it on the error
      path: attributes could become visible while ally_get_config()
      still returned NULL and the restore path silently did nothing
    - Record the Xbox controller mode in the first-setup defaults and
      apply the recorded value from hid_asus_ally_init()
    - properly rebase ally_alloc_cmd(): make it no change from previous patch
  - HID: asus: add joysticks inner and outer range configuration
    - Drop the unused cfg parameter of ally_set_joystick_thresholds()
  - HID: asus: add triggers inner and outer range configuration
    - Drop the unused cfg parameter of ally_set_trigger_ranges()
    - Fix a commit message typo: "sensitivity"
  - HID: asus: add support for response curve
    - Add ally_resp_curve_is_valid() and use it in the init/resume
      restore path exactly like the apply path does
    - Drop the unused struct device * parameter of the four
      response-curve helpers
  - HID: asus: add support to force feedback
    - Drop the unused pointers from ally_x_send_ff_report() and ally_x_send_ff_off()
  - HID: asus: add support for gamepad mode
    - Apply the mode exactly once from hid_asus_ally_init()
  - HID: asus: add support for turbo buttons
    - Remove the calibration groups created before a sysfs failure
  - HID: asus: add support for btn remapping
    - Do not gate remapping by turbo
    - Reject NULL remap/macro pointers in ally_set_button_mapping()
    - Carry the ally pointer in struct button_remap_attr
    - Fix the "hypen" comment typo
 
- v7
  - The "HID: asus: do not send keyboard init reports to touchpads" patch
    is not part of this series anymore: it has been applied upstream as
    8099f9da59f1 and the series is rebased on top of it
  - HID: asus: add support for ROG Ally handhelds
    - Reserve the probed interface role for the whole duration of its
      sleeping initialization: a concurrent probe of the same role could
      pass the singleton checks before the first one published its pointer
  - HID: asus: add gamepad configuration
    - Publish drvdata->rog_ally before the configuration attributes are
      created: the callbacks fetched it before asus_probe() published it
      and returned -ENODEV in the meantime
    - Roll the configuration back with ally_config_remove() when
      hid_asus_ally_init() fails, instead of leaking the created sysfs
      groups and the button entries
  - HID: asus: add support for response curve
    - Replace response_curve_pct_1..4, response_curve_move_1..4 and the
      apply attributes with one response_curve attribute per joystick that
      takes the whole curve in a single validated all-or-nothing write:
      staged partial edits reaching the MCU on resume cannot happen anymore
    - Add a read-only response_curve_index attribute documenting the
      meaning of each value
    - Restore both curves unconditionally on init/resume: only validated
      curves are recorded now
  - HID: asus: add support for btn remapping
    - Drop the stale cfg->turbo_support gate in ally_config_create():
      remapping attributes are created for every device with button
      directories, not only turbo-capable ones
 
- v8
  - HID: asus: add support for ROG Ally handhelds
    - Release the probe reservation when the interface pointer is
      published: the flags were only cleared on failure, leaving them
      stuck set after the first bind and rejecting every later probe
      of that role
    - Reserve the keyboard interface role too: its check and its
      publication were two separate locked sections, so concurrent
      probes of the same role could both publish
    - Keep the recorded USB device while any probe is still in flight
  - HID: asus: add gamepad configuration
    - Report the missing Xbox controller capability with -EOPNOTSUPP
  - HID: asus: add vibration strength configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add joysticks inner and outer range configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add triggers inner and outer range configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add joysticks anti-deadzone configuration
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add support for response curve
    - Wake pollers with sysfs_notify() after a successful curve write
  - HID: asus: add support to force feedback
    - Clear the rumble update latch on setup so a fresh interface
      cannot inherit one left over from a teardown race
  - HID: asus: add support for gamepad mode
    - Return -EIO for invalid gamepad modes stored in the device
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add support for turbo buttons
    - Wake pollers with sysfs_notify() after a successful write
  - HID: asus: add support for btn remapping
    - Return -EIO if a mapping is ever found unset instead of
      dereferencing it
    - Wake pollers with sysfs_notify() after remap and macro writes,
      and after a mode switch re-defaults the mappings
 
- v9
  - HID: asus: add support to force feedback
    - Hold intf_mutex while unpublishing the gamepad interface in the
      setup error path, like hid_asus_ally_remove() does
    - Improve gamepad interface device lock around the initialization
      force-feedback send
  - HID: asus: add support for btn remapping
    - Unpublish button_entries under config_mutex before removing the
      attributes and freeing the array
 
- v10
  - HID: asus: reinitialize the device after exiting a sleep state
    - Dropped as already merged in XG Mobile patchset
 
- v11
  - HID: asus: add support for ROG Ally handhelds
    - Split the chained data[1] = data[3] = 0x00 assignment into two
      statements
    - Align the hid_asus_ally_raw_event() continuation line with the
      opening parenthesis
  - HID: asus: add gamepad configuration
    - Add the missing blank line between struct hid_driver and
      asus_init()
  - HID: asus: add joysticks inner and outer range configuration
    - Align the sysfs_remove_group() and hid_warn() continuation lines
      with the opening parenthesis
  - HID: asus: add triggers inner and outer range configuration
    - Align the hid_warn() continuation lines with the opening
      parenthesis
  - HID: asus: add joysticks anti-deadzone configuration
    - Align the hid_warn() continuation lines with the opening
      parenthesis
  - HID: asus: add support for response curve
    - Drop the duplicate blank line before ally_config_attrs[]
  - HID: asus: add support to force feedback
    - Add the missing blank line before the static_assert
    - Align the hid_warn() continuation line with the opening
      parenthesis
  - HID: asus: add support for btn remapping
    - Align the hid_warn() and ally_set_button_mapping() continuation
      lines with the opening parenthesis
  - HID: asus: size feature reports from the HID report descriptor
    - New patch
  - HID: asus: identify XG Mobile stations and bind the LED to the
    reported model
    - New patch
  - HID: asus: expose XG Mobile identity and firmware information
    - New patch
  - HID: asus: size ally gamepad commands from the HID report descriptor
    - New patch
  - platform/x86: asus-armoury: pick the eGPU activation from the
    reported GPU
    - New patch
  - HID: asus: report the XG Mobile GPU vendor to asus-wmi
    - New patch
  - MAINTAINERS: add maintainer for the ASUS HID driver
    - New patch

Denis Benato (18):
HID: asus: add support for ROG Ally handhelds
HID: asus: add gamepad configuration
HID: asus: add vibration strength configuration
HID: asus: add joysticks inner and outer range configuration
HID: asus: add triggers inner and outer range configuration
HID: asus: add joysticks anti-deadzone configuration
HID: asus: add support for response curve
HID: asus: add support to force feedback
HID: asus: add support for gamepad mode
HID: asus: add support for turbo buttons
HID: asus: add support for btn remapping
HID: asus: size feature reports from the HID report descriptor
HID: asus: identify XG Mobile stations and bind the LED to the
reported model
HID: asus: expose XG Mobile identity and firmware information
HID: asus: size ally gamepad commands from the HID report descriptor platform/x86: asus-armoury: pick the eGPU activation from the reported
GPU
HID: asus: report the XG Mobile GPU vendor to asus-wmi
MAINTAINERS: add maintainer for the ASUS HID driver

 MAINTAINERS                                |    6 +
 drivers/hid/Kconfig                        |    1 +
 drivers/hid/hid-asus.c                     | 5457 +++++++++++++++++++-
 drivers/platform/x86/asus-armoury.c        |   53 +-
 drivers/platform/x86/asus-wmi.c            |   29 +
 include/linux/platform_data/x86/asus-wmi.h |   11 +
 6 files changed, 5474 insertions(+), 83 deletions(-)