Skip to content

HID: Make driver_data in hid_device_id a union

Uwe Kleine-König linux-hwmon linux-input lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9HID: asus: Use designated initializer for hid_device_iddrivers/hid/hid-asus.c+119 -800 replies
2/9HID: i2c-hid: Use designated initializer for hid_device_iddrivers/hid/i2c-hid/i2c-hid-dmi-quirks.c+1 -10 replies
3/9HID: input: Use designated initializer for hid_device_iddrivers/hid/hid-input.c+68 -460 replies
4/9HID: quirks: Use designated initializer for hid_device_iddrivers/hid/hid-quirks.c+200 -2000 replies
5/9HID: core: Make driver_data in hid_device_id a unioninclude/linux/device-id/hid.h+4 -10 replies
6/9HID: steelseries: Benefit from pointer typed driver_data in hid_device_iddrivers/hid/hid-steelseries-arctis.c+19 -200 replies
7/9HID: tmff: Benefit from pointer typed driver_data in hid_device_iddrivers/hid/hid-tmff.c+11 -110 replies
8/9HID: wacom: Benefit from pointer typed driver_data in hid_device_iddrivers/hid/wacom_sys.c drivers/hid/wacom_wac.c+9 -90 replies
9/9hwmon: (asus_rog_ryujin) Benefit from pointer typed driver_data in hid_device_iddrivers/hwmon/asus_rog_ryujin.c+7 -70 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

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

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

Signature · 1 line
2.47.3