[PATCH 0/3] HID: use designated initializers for acpi_device_id

COOLING13d

6 messages, 3 authors, 13d ago · open the first message on its own page

[PATCH 0/3] HID: use designated initializers for acpi_device_id

From: Pawel Zalewski <hidden>
Date: 2026-09-08 09:19:11

This series is converting lists that contain the acpi_device_id struct,
which is defined in the include/linux/device-id/acpi.h to make use of named
initializers (which they do not use currently). This work is part of the on
going effort in the kernel associated with device-ids [1]

The plan is to convert acpi_device_id::driver_data to have an anonymous
union, similarly to what was introduced for PCI and I2C device ID tables.
The goal is to increase type-safety (most of the existing casts are gone),
to improve readability and to make use intent a bit more clear:
union {
	kernel_ulong_t driver_data;
	const void *driver_data_ptr;
}
But for that to work all lists containing the structs need to use named
initializers first to avoid triggering -Wmissing-braces. I already have
patches that implement this and touching a lot of kernel subsystmes that
use the acpi_device_id struct and that list keeps on growing. Therefore,
I have decided to split the series per every subsystem into:
- pre-clean-ups that convert the lists to use named initializers
  (which is this series)
- actual implementations that make some of the modules use the new
  driver_data_ptr member (does not apply here in the HID subsystem).

That way the task can be fragmented into manageable and independent chunks
of work and makes this effort easier to review.

Tested builds on x86-64 and a64 in Yocto using 7.3-rc2.

[1] https://lore.kernel.org/all/cover.1780048925.git.u.kleine-koenig@baylibre.com/

Signed-off-by: Pawel Zalewski <redacted>
---
Pawel Zalewski (3):
      HID: hid-google-hammer: use named initializers for acpi_device_id
      HID: i2c-hid: use named initializers for acpi_device_id
      HID: surface-hid: use named initializers for acpi_device_id

 drivers/hid/hid-google-hammer.c       | 2 +-
 drivers/hid/i2c-hid/i2c-hid-acpi.c    | 8 ++++----
 drivers/hid/surface-hid/surface_kbd.c | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
---
base-commit: 28924df2a08f440c73991b83028032c901de2ae4
change-id: 20260908-acpi-hid-4305ca77f0a6

Best regards,
--  
Pawel Zalewski [off-list ref]

[PATCH 1/3] HID: hid-google-hammer: use named initializers for acpi_device_id

From: Pawel Zalewski <hidden>
Date: 2026-09-08 09:19:13

Use a designated initializer for the acpi_device_id fields which makes the
code more readable and consistent with how lists are initialized in the
rest of the kernel code base. Also drop explicitly setting fields to 0
where it is redundant.

Signed-off-by: Pawel Zalewski <redacted>
---
 drivers/hid/hid-google-hammer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c
index c99c3c0d442e..847b1ddefeec 100644
--- a/drivers/hid/hid-google-hammer.c
+++ b/drivers/hid/hid-google-hammer.c
@@ -268,7 +268,7 @@ static void cbas_ec_remove(struct platform_device *pdev)
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id cbas_ec_acpi_ids[] = {
-	{ "GOOG000B", 0 },
+	{ .id = "GOOG000B" },
 	{ }
 };
 MODULE_DEVICE_TABLE(acpi, cbas_ec_acpi_ids);
-- 
2.43.0

[PATCH 2/3] HID: i2c-hid: use named initializers for acpi_device_id

From: Pawel Zalewski <hidden>
Date: 2026-09-08 09:19:16

Use a named initializer for the acpi_device_id fields which makes the code
more readable and consistent with how lists are initialized in the rest of
the kernel code base.

Signed-off-by: Pawel Zalewski <redacted>
---
 drivers/hid/i2c-hid/i2c-hid-acpi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-acpi.c b/drivers/hid/i2c-hid/i2c-hid-acpi.c
index 13f977d6aab6..9371db200fc4 100644
--- a/drivers/hid/i2c-hid/i2c-hid-acpi.c
+++ b/drivers/hid/i2c-hid/i2c-hid-acpi.c
@@ -39,12 +39,12 @@ static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
 	 * The CHPN0001 ACPI device, which is used to describe the Chipone
 	 * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible.
 	 */
-	{ "CHPN0001" },
+	{ .id = "CHPN0001" },
 	/*
 	 * The IDEA5002 ACPI device causes high interrupt usage and spurious
 	 * wakeups from suspend.
 	 */
-	{ "IDEA5002" },
+	{ .id = "IDEA5002" },
 	{ }
 };
 
@@ -93,8 +93,8 @@ static int i2c_hid_acpi_probe(struct i2c_client *client)
 }
 
 static const struct acpi_device_id i2c_hid_acpi_match[] = {
-	{ "ACPI0C50" },
-	{ "PNP0C50" },
+	{ .id = "ACPI0C50" },
+	{ .id = "PNP0C50" },
 	{ }
 };
 MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
-- 
2.43.0

[PATCH 3/3] HID: surface-hid: use named initializers for acpi_device_id

From: Pawel Zalewski <hidden>
Date: 2026-09-08 09:19:18

Use a named initializer for the acpi_device_id fields which makes the code
more readable and consistent with how lists are initialized in the rest of
the kernel code base.

Unify the list terminator to have a single space between the brackets and
no trailing comma.

Signed-off-by: Pawel Zalewski <redacted>
---
 drivers/hid/surface-hid/surface_kbd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/surface-hid/surface_kbd.c b/drivers/hid/surface-hid/surface_kbd.c
index 0be01b5e74258..036829ba47d42 100644
--- a/drivers/hid/surface-hid/surface_kbd.c
+++ b/drivers/hid/surface-hid/surface_kbd.c
@@ -277,8 +277,8 @@ static void surface_kbd_remove(struct platform_device *pdev)
 }
 
 static const struct acpi_device_id surface_kbd_match[] = {
-	{ "MSHW0096" },
-	{ },
+	{ .id = "MSHW0096" },
+	{ }
 };
 MODULE_DEVICE_TABLE(acpi, surface_kbd_match);
 
-- 
2.43.0

Re: [PATCH 1/3] HID: hid-google-hammer: use named initializers for acpi_device_id

From: sashiko-bot@kernel.org
Date: 2026-09-08 09:24:26

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing validation of `field->maxusage` before accessing `field->usage->hid`.
--

commit f7c0a66497368221036f024200ddbda2e9fb80a9
Author: Pawel Zalewski [off-list ref]

HID: hid-google-hammer: use named initializers for acpi_device_id

Use a designated initializer for the acpi_device_id fields which makes the
code more readable and consistent with how lists are initialized in the
rest of the kernel code base. Also drop explicitly setting fields to 0
where it is redundant.
quoted hunk
diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c
index c99c3c0d442e1..847b1ddefeeca 100644
--- a/drivers/hid/hid-google-hammer.c
+++ b/drivers/hid/hid-google-hammer.c
@@ -268,7 +268,7 @@ static void cbas_ec_remove(struct platform_device *pdev)
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id cbas_ec_acpi_ids[] = {
-	{ "GOOG000B", 0 },
+	{ .id = "GOOG000B" },
 	{ }
 };
 MODULE_DEVICE_TABLE(acpi, cbas_ec_acpi_ids);
[Severity: High]
This is a pre-existing issue, but does hammer_get_folded_state() lack validation
for the number of usages before accessing the usage array?

Looking at drivers/hid/hid-google-hammer.c:hammer_get_folded_state():

	for (a = 0; a < report->maxfield; a++) {
		struct hid_field *field = report->field[a];

		if (field->usage->hid == HID_USAGE_KBD_FOLDED) {
			u32 value = hid_field_extract(hdev, buf+1,
					field->report_offset, field->report_size);

			hammer_folded_event(hdev, value);
			break;
		}
	}

If a maliciously crafted HID descriptor declares a field with 0 usages
(where field->maxusage == 0), will accessing field->usage->hid
(equivalent to field->usage[0].hid) cause an out-of-bounds memory read?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908-acpi-hid-v1-0-08df24c4b139@thegoodpenguin.co.uk?part=1

Re: [PATCH 0/3] HID: use designated initializers for acpi_device_id

From: Jiri Kosina <jikos@kernel.org>
Date: 2026-09-11 15:40:30

On Tue, 8 Sep 2026, Pawel Zalewski wrote:
This series is converting lists that contain the acpi_device_id struct,
which is defined in the include/linux/device-id/acpi.h to make use of named
initializers (which they do not use currently). This work is part of the on
going effort in the kernel associated with device-ids [1]

The plan is to convert acpi_device_id::driver_data to have an anonymous
union, similarly to what was introduced for PCI and I2C device ID tables.
The goal is to increase type-safety (most of the existing casts are gone),
to improve readability and to make use intent a bit more clear:
union {
	kernel_ulong_t driver_data;
	const void *driver_data_ptr;
}
But for that to work all lists containing the structs need to use named
initializers first to avoid triggering -Wmissing-braces. I already have
patches that implement this and touching a lot of kernel subsystmes that
use the acpi_device_id struct and that list keeps on growing. Therefore,
I have decided to split the series per every subsystem into:
- pre-clean-ups that convert the lists to use named initializers
  (which is this series)
- actual implementations that make some of the modules use the new
  driver_data_ptr member (does not apply here in the HID subsystem).

That way the task can be fragmented into manageable and independent chunks
of work and makes this effort easier to review.

Tested builds on x86-64 and a64 in Yocto using 7.3-rc2.

[1] https://lore.kernel.org/all/cover.1780048925.git.u.kleine-koenig@baylibre.com/

Signed-off-by: Pawel Zalewski <redacted>
---
Pawel Zalewski (3):
      HID: hid-google-hammer: use named initializers for acpi_device_id
      HID: i2c-hid: use named initializers for acpi_device_id
      HID: surface-hid: use named initializers for acpi_device_id
Applied, thank you.

-- 
Jiri Kosina
SUSE Labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help