[PATCH v1 0/6] power: Use named initializers for platform_device_id arrays

From: Uwe Kleine-König (The Capable Hub)

Date: Fri May 29 2026 - 06:18:50 EST


Hello,

this series targets to use named initializers for platform_device_id
arrays. In general these are better readable for humans and more robust
to changes in the respective struct definition.

This robustness is needed as I want to do

diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -610,4 +610,7 @@ struct dmi_system_id {
struct platform_device_id {
char name[PLATFORM_NAME_SIZE];
- kernel_ulong_t driver_data;
+ union {
+ kernel_ulong_t driver_data;
+ const void *driver_data_ptr;
+ };
};

which allows dropping several casts and eases porting CHERI to mainline
linux. A possible follow-up change is the following example:

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 5d61053e0596..03bc8e859d73 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -534,7 +534,7 @@ static struct irq_chip pxa_muxed_gpio_chip = {
static int pxa_gpio_nums(struct platform_device *pdev)
{
const struct platform_device_id *id = platform_get_device_id(pdev);
- struct pxa_gpio_id *pxa_id = (struct pxa_gpio_id *)id->driver_data;
+ struct pxa_gpio_id *pxa_id = id->driver_data_ptr;
int count = 0;

switch (pxa_id->type) {
@@ -708,14 +708,14 @@ static int pxa_gpio_probe(struct platform_device *pdev)
}

static const struct platform_device_id gpio_id_table[] = {
- { .name = "pxa25x-gpio", .driver_data = (unsigned long)&pxa25x_id },
- { .name = "pxa26x-gpio", .driver_data = (unsigned long)&pxa26x_id },
- { .name = "pxa27x-gpio", .driver_data = (unsigned long)&pxa27x_id },
- { .name = "pxa3xx-gpio", .driver_data = (unsigned long)&pxa3xx_id },
- { .name = "pxa93x-gpio", .driver_data = (unsigned long)&pxa93x_id },
- { .name = "mmp-gpio", .driver_data = (unsigned long)&mmp_id },
- { .name = "mmp2-gpio", .driver_data = (unsigned long)&mmp2_id },
- { .name = "pxa1928-gpio", .driver_data = (unsigned long)&pxa1928_id },
+ { .name = "pxa25x-gpio", .driver_data_ptr = &pxa25x_id },
+ { .name = "pxa26x-gpio", .driver_data_ptr = &pxa26x_id },
+ { .name = "pxa27x-gpio", .driver_data_ptr = &pxa27x_id },
+ { .name = "pxa3xx-gpio", .driver_data_ptr = &pxa3xx_id },
+ { .name = "pxa93x-gpio", .driver_data_ptr = &pxa93x_id },
+ { .name = "mmp-gpio", .driver_data_ptr = &mmp_id },
+ { .name = "mmp2-gpio", .driver_data_ptr = &mmp2_id },
+ { .name = "pxa1928-gpio", .driver_data_ptr = &pxa1928_id },
{ }
};

increasing readability due to less casting. Also this results in the
compiler warning:

drivers/gpio/gpio-pxa.c: In function ‘pxa_gpio_nums’:
drivers/gpio/gpio-pxa.c:537:38: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
537 | struct pxa_gpio_id *pxa_id = id->driver_data_ptr;
| ^~

which is a good thing as adding the needed const to fix this warning
improves type safety. (Sorry, no driver below drivers/power benefits
here, so the example is from a different subsystem.)

Patch #5 is just an unrelated change where I spotted the patch
opportunity while preparing this series. It's included here just for my
convenience and could be applied independently.

If you consider the last patch mostly churn, just drop it.

There are no dependencies between the patches, the only file that is
touched in more than one patch is drivers/power/supply/mt6360_charger.c
and even if these (i.e. patches #1 and #5) are reordered, git should be
able to cope with that without conflicts.

Note that this series is only build tested, and there is the possibility
that I failed to spot driver data usage that render patches #2 and/or #3
wrong. So a deeper look on at least those two won't hurt.

Best regards
Uwe

Uwe Kleine-König (The Capable Hub) (6):
power: Drop unused assignment of platform_device_id driver data
power: supply: max14577: Drop driver data in of and platform device id
arrays
power: supply: max17042: Drop driver data in of and platform device id
arrays
power: Use named initializers for platform_device_id arrays
power: supply: mt6360_charger: Use of match table unconditionally
power: Unify code style for platform_device_id arrays

drivers/power/reset/qemu-virt-ctrl.c | 2 +-
drivers/power/reset/spacemit-p1-reboot.c | 4 ++--
drivers/power/reset/tps65086-restart.c | 2 +-
drivers/power/supply/axp288_charger.c | 2 +-
drivers/power/supply/axp288_fuel_gauge.c | 2 +-
drivers/power/supply/bd71828-power.c | 8 ++++----
drivers/power/supply/charger-manager.c | 4 ++--
drivers/power/supply/cros_charge-control.c | 4 ++--
drivers/power/supply/cros_peripheral_charger.c | 4 ++--
drivers/power/supply/cros_usbpd-charger.c | 4 ++--
drivers/power/supply/macsmc-power.c | 2 +-
drivers/power/supply/max14577_charger.c | 12 +++++-------
drivers/power/supply/max17042_battery.c | 14 +++++++-------
drivers/power/supply/max77693_charger.c | 2 +-
drivers/power/supply/max77759_charger.c | 2 +-
drivers/power/supply/max8997_charger.c | 2 +-
drivers/power/supply/max8998_charger.c | 2 +-
drivers/power/supply/mt6360_charger.c | 6 +++---
drivers/power/supply/pf1550-charger.c | 2 +-
drivers/power/supply/rt5033_charger.c | 2 +-
20 files changed, 40 insertions(+), 42 deletions(-)


base-commit: f7af91adc230aa99e23330ecf85bc9badd9780ad
--
2.47.3