clk: Rework initialization of i2c_device_ids
Subsystems (4)
cover clk: Rework initialization of i2c_device_ids
Hello,
this series is a preparation for
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 23ff24080dfd..aebd3a5e90af 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -477,7 +477,11 @@ struct rpmsg_device_id {
struct i2c_device_id {
char name[I2C_NAME_SIZE];
- kernel_ulong_t driver_data; /* Data private to the driver */
+ union {
+ /* Data private to the driver */
+ kernel_ulong_t driver_data;
+ const void *driver_data_ptr;
+ };
};
/* pci_epf */and this requires that .driver_data is assigned via a named initializer for static data. This requirement isn't a bad one because named initializers are also much better readable than list initializers.
The union added to struct i2c_device_id enables further cleanups like:
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index 0123ca8157a8..84272ba65d08 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -207,8 +207,8 @@ struct ad5398_current_data_format {
static const struct ad5398_current_data_format df_10_4_120 = {10, 4, 0, 120000};
static const struct i2c_device_id ad5398_id[] = {
- { .name = "ad5398", .driver_data = (kernel_ulong_t)&df_10_4_120 },
- { .name = "ad5821", .driver_data = (kernel_ulong_t)&df_10_4_120 },
+ { .name = "ad5398", .driver_data_ptr = &df_10_4_120 },
+ { .name = "ad5821", .driver_data_ptr = &df_10_4_120 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ad5398_id);
@@ -219,8 +219,7 @@ static int ad5398_probe(struct i2c_client *client)
struct regulator_init_data *init_data = dev_get_platdata(&client->dev);
struct regulator_config config = { };
struct ad5398_chip_info *chip;
- const struct ad5398_current_data_format *df =
- (struct ad5398_current_data_format *)id->driver_data;
+ const struct ad5398_current_data_format *df = id->driver_data_ptr;
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)that are an improvement for readability (again!) and it keeps some properties of the pointers (here: being const) without having to pay attention for that. (I didn't find a good example in drivers/clk, so an regulator driver was used to demonstrate the gain.)
My additional motivation for this effort is CHERI[1]. This is a hardware extension that uses 128 bit pointers but unsigned long is still 64 bit. So with CHERI you cannot store pointers in unsigned long variables.
The first patch drops unused assignments to .driver_data in one driver. The second converts all clk drivers to use named initializers for i2c_device_id.
Best regards
Uwe
Uwe Kleine-König (The Capable Hub) (2):
clk: si5341: Drop unused i2c driver_data
clk: Use named initializers for arrays of i2c_device_data
drivers/clk/clk-cdce706.c | 2 +- drivers/clk/clk-cdce925.c | 8 ++++---- drivers/clk/clk-cs2000-cp.c | 4 ++-- drivers/clk/clk-renesas-pcie.c | 6 +++--- drivers/clk/clk-si514.c | 2 +- drivers/clk/clk-si521xx.c | 6 +++--- drivers/clk/clk-si5341.c | 10 +++++----- drivers/clk/clk-si5351.c | 8 ++++---- drivers/clk/clk-si544.c | 6 +++--- drivers/clk/clk-si570.c | 8 ++++---- drivers/clk/clk-versaclock5.c | 16 ++++++++-------- drivers/clk/clk-versaclock7.c | 4 ++-- 12 files changed, 40 insertions(+), 40 deletions(-)
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
Signature · 1 line
2.47.3
PATCH 1/2 clk: si5341: Drop unused i2c driver_data
The driver doesn't make use of the value that was explicitly assigned to the .driver_data member. Drop the assignment.
--- drivers/clk/clk-si5341.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clk/clk-si5341.c +5 -5
@@ -1825,11 +1825,11 @@ static void si5341_remove(struct i2c_client *client) }static const struct i2c_device_id si5341_id[] = { - {"si5340" ,0 }, - {"si5341" ,1 }, - {"si5342" ,2 }, - {"si5344" ,4 }, - {"si5345" ,5 }, + { .name ="si5340" }, + { .name ="si5341" }, + { .name ="si5342" }, + { .name ="si5344" }, + { .name ="si5345" }, { } };MODULE_DEVICE_TABLE (i2c, si5341_id);
Signature · 1 line
2.47.3
Re: [PATCH v1 1/2] clk: si5341: Drop unused i2c driver_data
Quoted 4 lines · Uwe Kleine-König (The Capable Hub)
The driver doesn't make use of the value that was explicitly assigned to the .driver_data member. Drop the assignment.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
PATCH 2/2 clk: Use named initializers for arrays of i2c_device_data
In reply to Uwe Kleine-König (The Capable Hub)While being less compact, using named initializers allows to more easily see which members of the structs are assigned which value without having to lookup the declaration of the struct. And it's also more robust against changes to the struct definition.
The mentioned robustness is relevant for a planned change to struct i2c_device_id that replaces .driver_data by an anonymous union.
While touching all these arrays, unify usage of whitespace and commas.
This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds.
--- drivers/clk/clk-cdce706.c | 2 +- drivers/clk/clk-cdce925.c | 8 ++++---- drivers/clk/clk-cs2000-cp.c | 4 ++-- drivers/clk/clk-renesas-pcie.c | 6 +++--- drivers/clk/clk-si514.c | 2 +- drivers/clk/clk-si521xx.c | 6 +++--- drivers/clk/clk-si5351.c | 8 ++++---- drivers/clk/clk-si544.c | 6 +++--- drivers/clk/clk-si570.c | 8 ++++---- drivers/clk/clk-versaclock5.c | 16 ++++++++-------- drivers/clk/clk-versaclock7.c | 4 ++-- 11 files changed, 35 insertions(+), 35 deletions(-)
drivers/clk/clk-cdce706.c +1 -1
@@ -680,7 +680,7 @@ MODULE_DEVICE_TABLE(of, cdce706_dt_match);#endif static const struct i2c_device_id cdce706_id[] = { - {"cdce706" }, + { .name ="cdce706" }, { } };MODULE_DEVICE_TABLE (i2c, cdce706_id);
drivers/clk/clk-cdce925.c +4 -4
@@ -826,10 +826,10 @@ static const struct clk_cdce925_chip_info clk_cdce949_info = { };static const struct i2c_device_id cdce925_id[] = { - {"cdce913" , (kernel_ulong_t)&clk_cdce913_info }, - {"cdce925" , (kernel_ulong_t)&clk_cdce925_info }, - {"cdce937" , (kernel_ulong_t)&clk_cdce937_info }, - {"cdce949" , (kernel_ulong_t)&clk_cdce949_info }, + { .name ="cdce913" , .driver_data = (kernel_ulong_t)&clk_cdce913_info }, + { .name ="cdce925" , .driver_data = (kernel_ulong_t)&clk_cdce925_info }, + { .name ="cdce937" , .driver_data = (kernel_ulong_t)&clk_cdce937_info }, + { .name ="cdce949" , .driver_data = (kernel_ulong_t)&clk_cdce949_info }, { } };MODULE_DEVICE_TABLE (i2c, cdce925_id);
drivers/clk/clk-cs2000-cp.c +2 -2
@@ -122,8 +122,8 @@ static const struct of_device_id cs2000_of_match[] = {MODULE_DEVICE_TABLE (of, cs2000_of_match);static const struct i2c_device_id cs2000_id[] = { - {"cs2000-cp" , }, - {} + { .name ="cs2000-cp" }, + { } };MODULE_DEVICE_TABLE (i2c, cs2000_id);
drivers/clk/clk-renesas-pcie.c +3 -3
@@ -395,9 +395,9 @@ static const struct rs9_chip_info renesas_9fgv0841_info = { };static const struct i2c_device_id rs9_id[] = { - {"9fgv0241" , .driver_data = (kernel_ulong_t)&renesas_9fgv0241_info }, - {"9fgv0441" , .driver_data = (kernel_ulong_t)&renesas_9fgv0441_info }, - {"9fgv0841" , .driver_data = (kernel_ulong_t)&renesas_9fgv0841_info }, + { .name ="9fgv0241" , .driver_data = (kernel_ulong_t)&renesas_9fgv0241_info }, + { .name ="9fgv0441" , .driver_data = (kernel_ulong_t)&renesas_9fgv0441_info }, + { .name ="9fgv0841" , .driver_data = (kernel_ulong_t)&renesas_9fgv0841_info }, { } };MODULE_DEVICE_TABLE (i2c, rs9_id);
drivers/clk/clk-si514.c +1 -1
@@ -379,7 +379,7 @@ static int si514_probe(struct i2c_client *client) }static const struct i2c_device_id si514_id[] = { - {"si514" }, + { .name ="si514" }, { } };MODULE_DEVICE_TABLE (i2c, si514_id);
drivers/clk/clk-si521xx.c +3 -3
@@ -365,9 +365,9 @@ static int __maybe_unused si521xx_resume(struct device *dev) }static const struct i2c_device_id si521xx_id[] = { - {"si52144" , .driver_data =SI521XX_OE_MAP (0x5 ,0xc0 ) }, - {"si52146" , .driver_data =SI521XX_OE_MAP (0x15 ,0xe0 ) }, - {"si52147" , .driver_data =SI521XX_OE_MAP (0x17 ,0xf8 ) }, + { .name ="si52144" , .driver_data =SI521XX_OE_MAP (0x5 ,0xc0 ) }, + { .name ="si52146" , .driver_data =SI521XX_OE_MAP (0x15 ,0xe0 ) }, + { .name ="si52147" , .driver_data =SI521XX_OE_MAP (0x17 ,0xf8 ) }, { } };MODULE_DEVICE_TABLE (i2c, si521xx_id);
drivers/clk/clk-si5351.c +4 -4
@@ -1425,10 +1425,10 @@ si53351_of_clk_get(struct of_phandle_args *clkspec, void *data)#endif /* CONFIG_OF */ static const struct i2c_device_id si5351_i2c_ids[] = { - {"si5351a" ,SI5351_VARIANT_A }, - {"si5351a-msop" ,SI5351_VARIANT_A3 }, - {"si5351b" ,SI5351_VARIANT_B }, - {"si5351c" ,SI5351_VARIANT_C }, + { .name ="si5351a" , .driver_data =SI5351_VARIANT_A }, + { .name ="si5351a-msop" , .driver_data =SI5351_VARIANT_A3 }, + { .name ="si5351b" , .driver_data =SI5351_VARIANT_B }, + { .name ="si5351c" , .driver_data =SI5351_VARIANT_C }, { } };MODULE_DEVICE_TABLE (i2c, si5351_i2c_ids);
drivers/clk/clk-si544.c +3 -3
@@ -479,9 +479,9 @@ static int si544_probe(struct i2c_client *client) }static const struct i2c_device_id si544_id[] = { - {"si544a" ,1500000000 }, - {"si544b" ,800000000 }, - {"si544c" ,350000000 }, + { .name ="si544a" , .driver_data =1500000000 }, + { .name ="si544b" , .driver_data =800000000 }, + { .name ="si544c" , .driver_data =350000000 }, { } };MODULE_DEVICE_TABLE (i2c, si544_id);
drivers/clk/clk-si570.c +4 -4
@@ -503,10 +503,10 @@ static const struct clk_si570_info clk_si590_info = { };static const struct i2c_device_id si570_id[] = { - {"si570" , (kernel_ulong_t)&clk_si570_info }, - {"si571" , (kernel_ulong_t)&clk_si570_info }, - {"si598" , (kernel_ulong_t)&clk_si590_info }, - {"si599" , (kernel_ulong_t)&clk_si590_info }, + { .name ="si570" , .driver_data = (kernel_ulong_t)&clk_si570_info }, + { .name ="si571" , .driver_data = (kernel_ulong_t)&clk_si570_info }, + { .name ="si598" , .driver_data = (kernel_ulong_t)&clk_si590_info }, + { .name ="si599" , .driver_data = (kernel_ulong_t)&clk_si590_info }, { } };MODULE_DEVICE_TABLE (i2c, si570_id);
drivers/clk/clk-versaclock5.c +8 -8
@@ -1311,14 +1311,14 @@ static const struct vc5_chip_info idt_5p49v6975_info = { };static const struct i2c_device_id vc5_id[] = { - {"5p49v5923" , .driver_data = (kernel_ulong_t)&idt_5p49v5923_info }, - {"5p49v5925" , .driver_data = (kernel_ulong_t)&idt_5p49v5925_info }, - {"5p49v5933" , .driver_data = (kernel_ulong_t)&idt_5p49v5933_info }, - {"5p49v5935" , .driver_data = (kernel_ulong_t)&idt_5p49v5935_info }, - {"5p49v60" , .driver_data = (kernel_ulong_t)&idt_5p49v60_info }, - {"5p49v6901" , .driver_data = (kernel_ulong_t)&idt_5p49v6901_info }, - {"5p49v6965" , .driver_data = (kernel_ulong_t)&idt_5p49v6965_info }, - {"5p49v6975" , .driver_data = (kernel_ulong_t)&idt_5p49v6975_info }, + { .name ="5p49v5923" , .driver_data = (kernel_ulong_t)&idt_5p49v5923_info }, + { .name ="5p49v5925" , .driver_data = (kernel_ulong_t)&idt_5p49v5925_info }, + { .name ="5p49v5933" , .driver_data = (kernel_ulong_t)&idt_5p49v5933_info }, + { .name ="5p49v5935" , .driver_data = (kernel_ulong_t)&idt_5p49v5935_info }, + { .name ="5p49v60" , .driver_data = (kernel_ulong_t)&idt_5p49v60_info }, + { .name ="5p49v6901" , .driver_data = (kernel_ulong_t)&idt_5p49v6901_info }, + { .name ="5p49v6965" , .driver_data = (kernel_ulong_t)&idt_5p49v6965_info }, + { .name ="5p49v6975" , .driver_data = (kernel_ulong_t)&idt_5p49v6975_info }, { } };MODULE_DEVICE_TABLE (i2c, vc5_id);
drivers/clk/clk-versaclock7.c +2 -2
@@ -1288,8 +1288,8 @@ static const struct regmap_config vc7_regmap_config = { };static const struct i2c_device_id vc7_i2c_id[] = { - {"rc21008a" , .driver_data = (kernel_ulong_t)&vc7_rc21008a_info }, - {} + { .name ="rc21008a" , .driver_data = (kernel_ulong_t)&vc7_rc21008a_info }, + { } };MODULE_DEVICE_TABLE (i2c, vc7_i2c_id);
Signature · 1 line
2.47.3
Re: [PATCH v1 2/2] clk: Use named initializers for arrays of i2c_device_data
Quoted 8 lines · Uwe Kleine-König (The Capable Hub)
While being less compact, using named initializers allows to more easily see which members of the structs are assigned which value without having to lookup the declaration of the struct. And it's also more robust against changes to the struct definition.
The mentioned robustness is relevant for a planned change to struct
i2c_device_idthat replaces .driver_data by an anonymous union.
Quoted 7 lines
While touching all these arrays, unify usage of whitespace and commas.
This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
Re: [PATCH v1 2/2] clk: Use named initializers for arrays of i2c_device_data
In reply to Uwe Kleine-König (The Capable Hub)Quoted 8 lines · Uwe Kleine-König (The Capable Hub)
While being less compact, using named initializers allows to more easily see which members of the structs are assigned which value without having to lookup the declaration of the struct. And it's also more robust against changes to the struct definition.
The mentioned robustness is relevant for a planned change to struct
i2c_device_idthat replaces .driver_data by an anonymous union.
Quoted 7 lines
While touching all these arrays, unify usage of whitespace and commas.
This patch doesn't modify the compiled arrays, only their representation in source form benefits. The former was confirmed with x86 and arm64 builds.
Signed-off-by Uwe Kleine-König (The Capable Hub) <[email protected]>
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Hello,
Quoted 52 lines · Uwe Kleine-König (The Capable Hub)
this series is a preparation for
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 23ff24080dfd..aebd3a5e90af 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -477,7 +477,11 @@ struct rpmsg_device_id { struct i2c_device_id { char name[I2C_NAME_SIZE]; - kernel_ulong_t driver_data; /* Data private to the driver */ + union { + /* Data private to the driver */ + kernel_ulong_t driver_data; + const void *driver_data_ptr; + }; }; /* pci_epf */and this requires that .driver_data is assigned via a named initializer for static data. This requirement isn't a bad one because named initializers are also much better readable than list initializers.
The union added to struct
i2c_device_idenables further cleanups like:diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 0123ca8157a8..84272ba65d08 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c @@ -207,8 +207,8 @@ struct ad5398_current_data_format { static const struct ad5398_current_data_format df_10_4_120 = {10, 4, 0, 120000}; static const struct i2c_device_id ad5398_id[] = { - { .name = "ad5398", .driver_data = (kernel_ulong_t)&df_10_4_120 }, - { .name = "ad5821", .driver_data = (kernel_ulong_t)&df_10_4_120 }, + { .name = "ad5398", .driver_data_ptr = &df_10_4_120 }, + { .name = "ad5821", .driver_data_ptr = &df_10_4_120 }, { } }; MODULE_DEVICE_TABLE(i2c, ad5398_id); @@ -219,8 +219,7 @@ static int ad5398_probe(struct i2c_client *client) struct regulator_init_data *init_data = dev_get_platdata(&client->dev); struct regulator_config config = { }; struct ad5398_chip_info *chip; - const struct ad5398_current_data_format *df = - (struct ad5398_current_data_format *)id->driver_data; + const struct ad5398_current_data_format *df = id->driver_data_ptr; chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); if (!chip)
Quoted 4 lines
that are an improvement for readability (again!) and it keeps some properties of the pointers (here: being const) without having to pay attention for that. (I didn't find a good example in
drivers/clk, so an regulator driver was used to demonstrate the gain.)
I wonder if you still have this series on your radar, it would be great to get it into 7.2-rc1.
Best regards
Uwe