From 4de4b8a5ddc2c5a2e0f62c72864caab7027ea67a Mon Sep 17 00:00:00 2001 From: "Pawel Zalewski (The Capable Hub)" Date: Mon, 18 May 2026 17:06:24 +0100 Subject: [PATCH 1/4] HID: hid-belkin: clean up usage of 'driver_data' The module is storing an integer inside the drvdata pointer, which is confusing, lets fix this and set the whole of 'hid_device_id' struct as the drvdata and then simply use its integer 'driver_data' field for quirks, which shall make the code cleaner, type-safe, consistent and more readable. This makes the cast to (void *) during storage a bit safer (just to suppress the const qualifier warning) and the cast to (unsigned long) during retrieval is removed. Signed-off-by: Pawel Zalewski (The Capable Hub) Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-belkin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-belkin.c b/drivers/hid/hid-belkin.c index 75aaed35ee9f..84695115d37b 100644 --- a/drivers/hid/hid-belkin.c +++ b/drivers/hid/hid-belkin.c @@ -27,7 +27,8 @@ static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + const struct hid_device_id *id = hid_get_drvdata(hdev); + unsigned long quirks = id->driver_data; if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER || !(quirks & BELKIN_WKBD)) @@ -48,7 +49,7 @@ static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id) unsigned long quirks = id->driver_data; int ret; - hid_set_drvdata(hdev, (void *)quirks); + hid_set_drvdata(hdev, (void *)id); ret = hid_parse(hdev); if (ret) { From 73e784ddf895416ec03d3760300f6050324cfe52 Mon Sep 17 00:00:00 2001 From: "Pawel Zalewski (The Capable Hub)" Date: Mon, 18 May 2026 17:06:25 +0100 Subject: [PATCH 2/4] HID: hid-cypress: clean up usage of 'driver_data' The module is storing an integer inside the drvdata pointer, which is confusing - furthermore this integer is mutable. When its value is changed it is set again using the 'hid_set_drvdata' API within the 'cp_event' function. Let's fix this, create and allocate the 'cp_device' struct that is then set as the drvdata and then simply use its integer 'quirks' field for storing the quirks, which shall make the code cleaner, type-safe, consistent and more readable. This makes the cast to (void *) during storage unnecessary and the cast to (unsigned long) during retrieval is also removed. Signed-off-by: Pawel Zalewski (The Capable Hub) Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-cypress.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c index 98548201feec..f18fddc176d0 100644 --- a/drivers/hid/hid-cypress.c +++ b/drivers/hid/hid-cypress.c @@ -25,6 +25,10 @@ #define VA_INVAL_LOGICAL_BOUNDARY 0x08 +struct cp_device { + unsigned long quirks; +}; + /* * Some USB barcode readers from cypress have usage min and usage max in * the wrong order @@ -70,7 +74,8 @@ static __u8 *va_logical_boundary_fixup(struct hid_device *hdev, __u8 *rdesc, static const __u8 *cp_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + const struct cp_device *cp_device = hid_get_drvdata(hdev); + unsigned long quirks = cp_device->quirks; if (quirks & CP_RDESC_SWAPPED_MIN_MAX) rdesc = cp_rdesc_fixup(hdev, rdesc, rsize); @@ -84,7 +89,8 @@ static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + const struct cp_device *cp_device = hid_get_drvdata(hdev); + unsigned long quirks = cp_device->quirks; if (!(quirks & CP_2WHEEL_MOUSE_HACK)) return 0; @@ -100,22 +106,21 @@ static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi, static int cp_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + struct cp_device *cp_device = hid_get_drvdata(hdev); if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || - !usage->type || !(quirks & CP_2WHEEL_MOUSE_HACK)) + !usage->type || !(cp_device->quirks & CP_2WHEEL_MOUSE_HACK)) return 0; if (usage->hid == 0x00090005) { if (value) - quirks |= CP_2WHEEL_MOUSE_HACK_ON; + cp_device->quirks |= CP_2WHEEL_MOUSE_HACK_ON; else - quirks &= ~CP_2WHEEL_MOUSE_HACK_ON; - hid_set_drvdata(hdev, (void *)quirks); + cp_device->quirks &= ~CP_2WHEEL_MOUSE_HACK_ON; return 1; } - if (usage->code == REL_WHEEL && (quirks & CP_2WHEEL_MOUSE_HACK_ON)) { + if (usage->code == REL_WHEEL && (cp_device->quirks & CP_2WHEEL_MOUSE_HACK_ON)) { struct input_dev *input = field->hidinput->input; input_event(input, usage->type, REL_HWHEEL, value); @@ -127,10 +132,17 @@ static int cp_event(struct hid_device *hdev, struct hid_field *field, static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id) { - unsigned long quirks = id->driver_data; int ret; + struct cp_device *cp_device; - hid_set_drvdata(hdev, (void *)quirks); + cp_device = devm_kzalloc(&hdev->dev, sizeof(*cp_device), GFP_KERNEL); + + if (!cp_device) + return -ENOMEM; + + cp_device->quirks = id->driver_data; + + hid_set_drvdata(hdev, cp_device); ret = hid_parse(hdev); if (ret) { From 0b8bb8c3c913b11bb1d4d34603212b531ecd8354 Mon Sep 17 00:00:00 2001 From: "Pawel Zalewski (The Capable Hub)" Date: Mon, 18 May 2026 17:06:26 +0100 Subject: [PATCH 3/4] HID: hid-gfrm: clean up usage of 'driver_data' The module is storing an integer inside the drvdata pointer, which is confusing, lets fix this and set the whole of 'hid_device_id' struct as the drvdata and then simply use its integer 'driver_data' field for quirks, which shall make the code cleaner, type-safe, consistent and more readable. This makes the cast to (void *) during storage a bit safer (just to suppress the const qualifier warning) and the cast to (unsigned long) during retrieval is removed. Signed-off-by: Pawel Zalewski (The Capable Hub) Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-gfrm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-gfrm.c b/drivers/hid/hid-gfrm.c index d2a56bf92b41..f7cc754de84e 100644 --- a/drivers/hid/hid-gfrm.c +++ b/drivers/hid/hid-gfrm.c @@ -28,7 +28,8 @@ static int gfrm_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { - unsigned long hdev_type = (unsigned long) hid_get_drvdata(hdev); + const struct hid_device_id *id = hid_get_drvdata(hdev); + unsigned long hdev_type = id->driver_data; if (hdev_type == GFRM100) { if (usage->hid == (HID_UP_CONSUMER | 0x4)) { @@ -50,7 +51,8 @@ static int gfrm_input_mapping(struct hid_device *hdev, struct hid_input *hi, static int gfrm_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size) { - unsigned long hdev_type = (unsigned long) hid_get_drvdata(hdev); + const struct hid_device_id *id = hid_get_drvdata(hdev); + unsigned long hdev_type = id->driver_data; int ret = 0; if (hdev_type != GFRM100) @@ -99,7 +101,7 @@ static int gfrm_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret; - hid_set_drvdata(hdev, (void *) id->driver_data); + hid_set_drvdata(hdev, (void *)id); ret = hid_parse(hdev); if (ret) From b11dfa6cc3c8dcbe2687c74fe4de9a39a8123d74 Mon Sep 17 00:00:00 2001 From: "Pawel Zalewski (The Capable Hub)" Date: Mon, 18 May 2026 17:06:27 +0100 Subject: [PATCH 4/4] HID: hid-ite: clean up usage of 'driver_data' The module is storing an integer inside the drvdata pointer, which is confusing, lets fix this and set the whole of 'hid_device_id' struct as the drvdata and then simply use its integer 'driver_data' field for quirks, which shall make the code cleaner, type-safe, consistent and more readable. This makes the cast to (void *) during storage a bit safer (just to suppress the const qualifier warning) and the cast to (unsigned long) during retrieval is removed. Signed-off-by: Pawel Zalewski (The Capable Hub) Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-ite.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-ite.c b/drivers/hid/hid-ite.c index 8e42780a2663..63908f24b524 100644 --- a/drivers/hid/hid-ite.c +++ b/drivers/hid/hid-ite.c @@ -15,7 +15,9 @@ static const __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + + const struct hid_device_id *id = hid_get_drvdata(hdev); + unsigned long quirks = id->driver_data; if (quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) { /* For Acer Aspire Switch 10 SW5-012 keyboard-dock */ @@ -44,7 +46,8 @@ static int ite_input_mapping(struct hid_device *hdev, int *max) { - unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + const struct hid_device_id *id = hid_get_drvdata(hdev); + unsigned long quirks = id->driver_data; if ((quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) && (usage->hid & HID_USAGE_PAGE) == 0x00880000) { @@ -94,7 +97,7 @@ static int ite_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret; - hid_set_drvdata(hdev, (void *)id->driver_data); + hid_set_drvdata(hdev, (void *)id); ret = hid_open_report(hdev); if (ret)