drivers/pinctrl/pinctrl-aw9523.c | 2 +- drivers/pinctrl/pinctrl-cy8c95x0.c | 6 +++--- drivers/pinctrl/pinctrl-mcp23s08_i2c.c | 6 +++--- drivers/pinctrl/pinctrl-sx150x.c | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-)
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 in the list
terminator.
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) <u.kleine-koenig@baylibre.com>
---
Hello,
the mentioned change to i2c_device_id is the following:
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/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 8a082ff034dd..b2aac7348d22 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -1429,7 +1429,7 @@ static int kxcjk1013_probe(struct i2c_client *client)
if (id) {
name = id->name;
- data->info = (const struct kx_chipset_info *)(id->driver_data);
+ data->info = id->driver_data_ptr;
} else {
name = iio_get_acpi_device_name_and_data(&client->dev, &ddata);
data->info = ddata;
@@ -1630,11 +1630,11 @@ static const struct dev_pm_ops kxcjk1013_pm_ops = {
};
static const struct i2c_device_id kxcjk1013_id[] = {
- { .name = "kxcjk1013", .driver_data = (kernel_ulong_t)&kxcjk1013_info },
- { .name = "kxcj91008", .driver_data = (kernel_ulong_t)&kxcj91008_info },
- { .name = "kxtj21009", .driver_data = (kernel_ulong_t)&kxtj21009_info },
- { .name = "kxtf9", .driver_data = (kernel_ulong_t)&kxtf9_info },
- { .name = "kx023-1025", .driver_data = (kernel_ulong_t)&kx0231025_info },
+ { .name = "kxcjk1013", .driver_data_ptr = &kxcjk1013_info },
+ { .name = "kxcj91008", .driver_data_ptr = &kxcj91008_info },
+ { .name = "kxtj21009", .driver_data_ptr = &kxtj21009_info },
+ { .name = "kxtf9", .driver_data_ptr = &kxtf9_info },
+ { .name = "kx023-1025", .driver_data_ptr = &kx0231025_info },
{ }
};
MODULE_DEVICE_TABLE(i2c, kxcjk1013_id);
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/pinctrl, so
an iio 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.
Best regards
Uwe
[1] https://cheri-alliance.org/discover-cheri/
https://lwn.net/Articles/1037974/
drivers/pinctrl/pinctrl-aw9523.c | 2 +-
drivers/pinctrl/pinctrl-cy8c95x0.c | 6 +++---
drivers/pinctrl/pinctrl-mcp23s08_i2c.c | 6 +++---
drivers/pinctrl/pinctrl-sx150x.c | 20 ++++++++++----------
4 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-aw9523.c b/drivers/pinctrl/pinctrl-aw9523.c
index 02a24ac87ea4..bc94003512cf 100644
--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -1033,7 +1033,7 @@ static void aw9523_remove(struct i2c_client *client)
}
static const struct i2c_device_id aw9523_i2c_id_table[] = {
- { "aw9523_i2c" },
+ { .name = "aw9523_i2c" },
{ }
};
MODULE_DEVICE_TABLE(i2c, aw9523_i2c_id_table);
diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c
index ace0be5ec679..093ae7c1dae5 100644
--- a/drivers/pinctrl/pinctrl-cy8c95x0.c
+++ b/drivers/pinctrl/pinctrl-cy8c95x0.c
@@ -1461,9 +1461,9 @@ static int cy8c95x0_probe(struct i2c_client *client)
}
static const struct i2c_device_id cy8c95x0_id[] = {
- { "cy8c9520", 20 },
- { "cy8c9540", 40 },
- { "cy8c9560", 60 },
+ { .name = "cy8c9520", .driver_data = 20 },
+ { .name = "cy8c9540", .driver_data = 40 },
+ { .name = "cy8c9560", .driver_data = 60 },
{ }
};
MODULE_DEVICE_TABLE(i2c, cy8c95x0_id);
diff --git a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
index 94e1add6ddd7..f3dffa3c74d3 100644
--- a/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
+++ b/drivers/pinctrl/pinctrl-mcp23s08_i2c.c
@@ -67,9 +67,9 @@ static const struct mcp23s08_info mcp23018_i2c = {
};
static const struct i2c_device_id mcp230xx_id[] = {
- { "mcp23008", (kernel_ulong_t)&mcp23008_i2c },
- { "mcp23017", (kernel_ulong_t)&mcp23017_i2c },
- { "mcp23018", (kernel_ulong_t)&mcp23018_i2c },
+ { .name = "mcp23008", .driver_data = (kernel_ulong_t)&mcp23008_i2c },
+ { .name = "mcp23017", .driver_data = (kernel_ulong_t)&mcp23017_i2c },
+ { .name = "mcp23018", .driver_data = (kernel_ulong_t)&mcp23018_i2c },
{ }
};
MODULE_DEVICE_TABLE(i2c, mcp230xx_id);
diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index 1d6760ffe809..b59d913513d5 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -839,16 +839,16 @@ static const struct pinconf_ops sx150x_pinconf_ops = {
};
static const struct i2c_device_id sx150x_id[] = {
- {"sx1501q", (kernel_ulong_t) &sx1501q_device_data },
- {"sx1502q", (kernel_ulong_t) &sx1502q_device_data },
- {"sx1503q", (kernel_ulong_t) &sx1503q_device_data },
- {"sx1504q", (kernel_ulong_t) &sx1504q_device_data },
- {"sx1505q", (kernel_ulong_t) &sx1505q_device_data },
- {"sx1506q", (kernel_ulong_t) &sx1506q_device_data },
- {"sx1507q", (kernel_ulong_t) &sx1507q_device_data },
- {"sx1508q", (kernel_ulong_t) &sx1508q_device_data },
- {"sx1509q", (kernel_ulong_t) &sx1509q_device_data },
- {}
+ { .name = "sx1501q", .driver_data = (kernel_ulong_t)&sx1501q_device_data },
+ { .name = "sx1502q", .driver_data = (kernel_ulong_t)&sx1502q_device_data },
+ { .name = "sx1503q", .driver_data = (kernel_ulong_t)&sx1503q_device_data },
+ { .name = "sx1504q", .driver_data = (kernel_ulong_t)&sx1504q_device_data },
+ { .name = "sx1505q", .driver_data = (kernel_ulong_t)&sx1505q_device_data },
+ { .name = "sx1506q", .driver_data = (kernel_ulong_t)&sx1506q_device_data },
+ { .name = "sx1507q", .driver_data = (kernel_ulong_t)&sx1507q_device_data },
+ { .name = "sx1508q", .driver_data = (kernel_ulong_t)&sx1508q_device_data },
+ { .name = "sx1509q", .driver_data = (kernel_ulong_t)&sx1509q_device_data },
+ { }
};
static const struct of_device_id sx150x_of_match[] = {
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
--
2.47.3
© 2016 - 2026 Red Hat, Inc.