hwmon:
cover hwmon:
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. (There is no hwmon driver that benefits from this change, so a driver from a different subsystem was used to show the benefit.)
Best regards
Uwe
Uwe Kleine-König (The Capable Hub) (2):
hwmon: cros_ec: Drop unused assignment of platform_device_id driver
data
hwmon: Use named initializers for platform_device_id arrays
drivers/hwmon/cros_ec_hwmon.c | 4 ++-- drivers/hwmon/max197.c | 4 ++-- drivers/hwmon/ntc_thermistor.c | 24 ++++++++++++------------ drivers/hwmon/sht15.c | 10 +++++----- 4 files changed, 21 insertions(+), 21 deletions(-)
base-commit: e7e28506af98ce4e1059e5ec59334b335c00a246
Signature · 1 line
2.47.3
PATCH 1/2 hwmon: cros_ec: Drop unused assignment of platform_device_id driver data
The driver explicitly set the .driver_data member of struct platform_device_id to zero without relying on that value. Drop this unused assignments.
While touching this array unify spacing and use named initializers for .name.
--- drivers/hwmon/cros_ec_hwmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/cros_ec_hwmon.c +2 -2
@@ -654,8 +654,8 @@ static int cros_ec_hwmon_resume(struct platform_device *pdev) }static const struct platform_device_id cros_ec_hwmon_id[] = { - {DRV_NAME ,0 }, - {} + { .name =DRV_NAME }, + { } };MODULE_DEVICE_TABLE (platform, cros_ec_hwmon_id);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v1 1/2] hwmon: cros_ec: Drop unused assignment of platform_device_id driver data
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
The driver explicitly set the .driver_data member of struct
platform_device_idto zero without relying on that value. Drop this unused assignments.While touching this array unify spacing and use named initializers for .name.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v1 1/2] hwmon: cros_ec: Drop unused assignment of platform_device_id driver data
In reply to Uwe Kleine-König (The Capable Hub)Quoted 8 lines · Uwe Kleine-König (The Capable Hub)
The driver explicitly set the .driver_data member of struct
platform_device_idto zero without relying on that value. Drop this unused assignments.While touching this array unify spacing and use named initializers for .name.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
Re: [PATCH v1 1/2] hwmon: cros_ec: Drop unused assignment of platform_device_id driver data
In reply to Uwe Kleine-König (The Capable Hub)Quoted 7 lines · Uwe Kleine-König (The Capable Hub)
The driver explicitly set the .driver_data member of struct
platform_device_idto zero without relying on that value. Drop this unused assignments.While touching this array unify spacing and
use named initializers for .name.
Not sure why this is better.
Quoted 1 line
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
... but it doesn't really matter, so:
Quoted 22 lines
--- drivers/hwmon/cros_ec_hwmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/hwmon/cros_ec_hwmon.c +2
-2@@ -654,8 +654,8 @@ static int cros_ec_hwmon_resume(struct platform_device *pdev) }static const struct platform_device_id cros_ec_hwmon_id[] = { - {DRV_NAME ,0 }, - {} + { .name =DRV_NAME }, + { } };MODULE_DEVICE_TABLE (platform, cros_ec_hwmon_id);Signature · 1 line
2.47.3
Re: [PATCH v1 1/2] hwmon: cros_ec: Drop unused assignment of platform_device_id driver data
In reply to Uwe Kleine-König (The Capable Hub)Quoted 10 lines · Uwe Kleine-König (The Capable Hub)
The driver explicitly set the .driver_data member of struct
platform_device_idto zero without relying on that value. Drop this unused assignments.While touching this array unify spacing and use named initializers for .name.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>Reviewed-by Tzung-Bi Shih <[email protected]>Acked-by Thomas Weißschuh <[email protected]>
Applied.
Thanks,
Guenter
PATCH 2/2 hwmon: Use named initializers for platform_device_id arrays
In reply to Uwe Kleine-König (The Capable Hub)Named initializers are better readable and more robust to changes of the struct definition. This robustness is relevant for a planned change to struct platform_device_id replacing .driver_data by an anonymous unit.
While touching these arrays usage of commas.
--- drivers/hwmon/max197.c | 4 ++-- drivers/hwmon/ntc_thermistor.c | 24 ++++++++++++------------ drivers/hwmon/sht15.c | 10 +++++----- 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/hwmon/max197.c +2 -2
@@ -321,8 +321,8 @@ static void max197_remove(struct platform_device *pdev) }static const struct platform_device_id max197_device_ids[] = { - {"max197" , max197 }, - {"max199" , max199 }, + { .name ="max197" , .driver_data = max197 }, + { .name ="max199" , .driver_data = max199 }, { } };MODULE_DEVICE_TABLE (platform, max197_device_ids);
drivers/hwmon/ntc_thermistor.c +12 -12
@@ -52,18 +52,18 @@ enum { };static const struct platform_device_id ntc_thermistor_id[] = { - [NTC_B57330V2103 ] = {"b57330v2103" ,TYPE_B57330V2103 }, - [NTC_B57891S0103 ] = {"b57891s0103" ,TYPE_B57891S0103 }, - [NTC_NCP03WB473 ] = {"ncp03wb473" ,TYPE_NCPXXWB473 }, - [NTC_NCP03WF104 ] = {"ncp03wf104" ,TYPE_NCPXXWF104 }, - [NTC_NCP15WB473 ] = {"ncp15wb473" ,TYPE_NCPXXWB473 }, - [NTC_NCP15WL333 ] = {"ncp15wl333" ,TYPE_NCPXXWL333 }, - [NTC_NCP15XH103 ] = {"ncp15xh103" ,TYPE_NCPXXXH103 }, - [NTC_NCP18WB473 ] = {"ncp18wb473" ,TYPE_NCPXXWB473 }, - [NTC_NCP21WB473 ] = {"ncp21wb473" ,TYPE_NCPXXWB473 }, - [NTC_SSG1404001221 ] = {"ssg1404_001221" ,TYPE_NCPXXWB473 }, - [NTC_NCP18WM474 ] = {"ncp18wm474" ,TYPE_NCPXXWM474 }, - [NTC_LAST ] = { }, + [NTC_B57330V2103 ] = { .name ="b57330v2103" , .driver_data =TYPE_B57330V2103 }, + [NTC_B57891S0103 ] = { .name ="b57891s0103" , .driver_data =TYPE_B57891S0103 }, + [NTC_NCP03WB473 ] = { .name ="ncp03wb473" , .driver_data =TYPE_NCPXXWB473 }, + [NTC_NCP03WF104 ] = { .name ="ncp03wf104" , .driver_data =TYPE_NCPXXWF104 }, + [NTC_NCP15WB473 ] = { .name ="ncp15wb473" , .driver_data =TYPE_NCPXXWB473 }, + [NTC_NCP15WL333 ] = { .name ="ncp15wl333" , .driver_data =TYPE_NCPXXWL333 }, + [NTC_NCP15XH103 ] = { .name ="ncp15xh103" , .driver_data =TYPE_NCPXXXH103 }, + [NTC_NCP18WB473 ] = { .name ="ncp18wb473" , .driver_data =TYPE_NCPXXWB473 }, + [NTC_NCP21WB473 ] = { .name ="ncp21wb473" , .driver_data =TYPE_NCPXXWB473 }, + [NTC_SSG1404001221 ] = { .name ="ssg1404_001221" , .driver_data =TYPE_NCPXXWB473 }, + [NTC_NCP18WM474 ] = { .name ="ncp18wm474" , .driver_data =TYPE_NCPXXWM474 }, + [NTC_LAST ] = { } };MODULE_DEVICE_TABLE (platform, ntc_thermistor_id);
drivers/hwmon/sht15.c +5 -5
@@ -1036,11 +1036,11 @@ static void sht15_remove(struct platform_device *pdev) }static const struct platform_device_id sht15_device_ids[] = { - {"sht10" , sht10 }, - {"sht11" , sht11 }, - {"sht15" , sht15 }, - {"sht71" , sht71 }, - {"sht75" , sht75 }, + { .name ="sht10" , .driver_data = sht10 }, + { .name ="sht11" , .driver_data = sht11 }, + { .name ="sht15" , .driver_data = sht15 }, + { .name ="sht71" , .driver_data = sht71 }, + { .name ="sht75" , .driver_data = sht75 }, { } };MODULE_DEVICE_TABLE (platform, sht15_device_ids);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v1 2/2] hwmon: Use named initializers for platform_device_id arrays
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The commit message contains an incomplete sentence and a typo. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The commit message contains an incomplete sentence and a typo.
--
commit e80f82a6fd801f1724dea71e8261da2d0d65c1f4
Author: Uwe Kleine-König (The Capable Hub) <[email protected]>
hwmon: Use named initializers for platform_device_id arrays
This commit updates platform_device_id arrays in several hwmon drivers to use named initializers for better readability and robustness. This prepares the code for a planned change to struct platform_device_id.
Quoted 5 lines
hwmon: Use named initializers for
platform_device_idarraysNamed initializers are better readable and more robust to changes of the struct definition. This robustness is relevant for a planned change to struct
platform_device_idreplacing .driver_data by an anonymous unit.
[Severity: Low]
This isn't a bug, but there is a typo in the description. Did you mean "anonymous union" instead of "anonymous unit"?
Quoted 1 line
While touching these arrays usage of commas.
[Severity: Low]
This isn't a bug, but this sentence appears to be incomplete. Could the commit message be updated to clarify the intent regarding trailing commas?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v1 2/2] hwmon: Use named initializers for platform_device_id arrays
In reply to Uwe Kleine-König (The Capable Hub)Quoted 5 lines · Uwe Kleine-König (The Capable Hub)
Named initializers are better readable and more robust to changes of the struct definition. This robustness is relevant for a planned change to struct
platform_device_idreplacing .driver_data by an anonymous unit.While touching these arrays usage of commas.
^
Here is a word missing ------', please add "unify" here if you apply this version. I fixed that in my tree, so if it comes to a v2 this will be fixed there, too.
Best regards
Uwe
Guenter Roeck
maintainerRe: [PATCH v1 2/2] hwmon: Use named initializers for platform_device_id arrays
In reply to Uwe Kleine-König (The Capable Hub)Quoted 7 lines · Uwe Kleine-König (The Capable Hub)
Named initializers are better readable and more robust to changes of the struct definition. This robustness is relevant for a planned change to struct
platform_device_idreplacing .driver_data by an anonymous unit.While touching these arrays usage of commas.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
Applied (and updated description).
Thanks,
Guenter