[PATCH v1 0/9] HID: Make driver_data in hid_device_id a union

From: Uwe Kleine-König

Date: Wed Nov 25 2026 - 02:22:20 EST


Hello,

the 5th patch of this series replaces .driver_data of struct
hid_device_id by an anonymous union. Drivers that store pointers in
.driver_data can benefit from that by less casting and still more
implicit type safety as something like:

struct sometype *driver_data = id->driver_data_ptr;

is catched by the compiler to lack a `const`.

The (IMHO tiny) downside is that with that union initialisations must be
done using designated (i.e. named) initializers. The first four patches
implement that for the few drivers that don't do that yet, which IMHO
could stand as improvements on its own. Patches #6 and later convert
drivers that store pointers in .driver_data to the new .driver_data_ptr.
All patches intend to have no effect on the build result, so this is
only about easier source code and tighter compiler checks.

My original motivation to work on this is that the result also works on
machines with CHERI support that have sizeof(unsigned long) <
sizeof(void *). It's still a long way to get these running mainline
Linux but the nice thing about this series is that it works towards such
a future and improves the code for non-CHERI architectures, too.

Some of the existing initializers use an unusual coding style. In the
first patch I converted that to a more common indentation while updating
to designated initializers, in the quirks patch I mostly kept the
existing style. If you have a strong opinion there or think the
opportunity should be taken to convert all such arrays, I can do that.
This conversion is also the main reason that this series doesn't have a
diffstat with nearly an equal number of insertions and deletions.

The dependencies are as follows:

- patch #5 (HID: core: Make driver_data in hid_device_id a union)
depends on patches #1 - #4
- patches #6 and later (...: Benefit from pointer typed driver_data in
hid_device_id) depend on patch #5.

I would expect that all but maybe the last patch go in via the HID tree.
I can resend patch #9 to hwmon when its dependencies landed in the
mainline.

I build tested this series on top of next-20261123 using allmodconfig on
arc, sh, alpha, arm64, x86_64, s390, riscv, mips, powerpc, loongarch,
sparc, m68k and parisc and there were no build regressions.

Best regards
Uwe

Uwe Kleine-König (9):
HID: asus: Use designated initializer for hid_device_id
HID: i2c-hid: Use designated initializer for hid_device_id
HID: input: Use designated initializer for hid_device_id
HID: quirks: Use designated initializer for hid_device_id
HID: core: Make driver_data in hid_device_id a union
HID: steelseries: Benefit from pointer typed driver_data in
hid_device_id
HID: tmff: Benefit from pointer typed driver_data in hid_device_id
HID: wacom: Benefit from pointer typed driver_data in hid_device_id
hwmon: (asus_rog_ryujin) Benefit from pointer typed driver_data in
hid_device_id

drivers/hid/hid-asus.c | 199 ++++++-----
drivers/hid/hid-input.c | 114 ++++---
drivers/hid/hid-quirks.c | 400 +++++++++++------------
drivers/hid/hid-steelseries-arctis.c | 39 ++-
drivers/hid/hid-tmff.c | 22 +-
drivers/hid/i2c-hid/i2c-hid-dmi-quirks.c | 2 +-
drivers/hid/wacom_sys.c | 8 +-
drivers/hid/wacom_wac.c | 10 +-
drivers/hwmon/asus_rog_ryujin.c | 14 +-
include/linux/device-id/hid.h | 5 +-
10 files changed, 438 insertions(+), 375 deletions(-)


base-commit: 3191063649dbf7c0d0b768e1f3655e4c5fc6edb5
--
2.47.3