Skip to contentSkip to conversation

mfd: Initialize spi_device_id arrays using member names

PATCH Applied Uwe Kleine-König (The Capable Hub) 3 participants 6 messages Jul 2 – Jul 9

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

cover mfd: Initialize spi_device_id arrays using member names

Hello,

this series targets to use named initializers for spi_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/device-id/spi.h b/include/linux/device-id/spi.h
	index 812e7c3854a7..93d9cd45569a 100644
	--- a/include/linux/device-id/spi.h
	+++ b/include/linux/device-id/spi.h
	@@ -13,7 +13,11 @@ typedef unsigned long kernel_ulong_t;
	 
	 struct spi_device_id {
		char name[SPI_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;
	+	};
	 };
	 
	 #endif /* ifndef LINUX_MOD_DEVICE_ID_SPI_H */

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/mfd/intel-m10-bmc-spi.c b/drivers/mfd/intel-m10-bmc-spi.c
	index 94b9c99bb4f8..28a3cc84b778 100644
	--- a/drivers/mfd/intel-m10-bmc-spi.c
	+++ b/drivers/mfd/intel-m10-bmc-spi.c
	@@ -70,7 +70,7 @@ static int intel_m10_bmc_spi_probe(struct spi_device *spi)
		if (!ddata)
			return -ENOMEM;
	 
	-	info = (struct intel_m10bmc_platform_info *)id->driver_data;
	+	info = id->driver_data_ptr;
		ddata->dev = dev;
	 
		ddata->regmap = devm_regmap_init_spi_avmm(spi, &intel_m10bmc_regmap_config);
	@@ -160,9 +160,9 @@ static const struct intel_m10bmc_platform_info m10bmc_spi_n5010 = {
	 };
	 
	 static const struct spi_device_id m10bmc_spi_id[] = {
	-	{ .name = "m10-n3000", .driver_data = (kernel_ulong_t)&m10bmc_spi_n3000 },
	-	{ .name = "m10-d5005", .driver_data = (kernel_ulong_t)&m10bmc_spi_d5005 },
	-	{ .name = "m10-n5010", .driver_data = (kernel_ulong_t)&m10bmc_spi_n5010 },
	+	{ .name = "m10-n3000", .driver_data_ptr = &m10bmc_spi_n3000 },
	+	{ .name = "m10-d5005", .driver_data_ptr = &m10bmc_spi_d5005 },
	+	{ .name = "m10-n5010", .driver_data_ptr = &m10bmc_spi_n5010 },
		{ }
	 };
	 MODULE_DEVICE_TABLE(spi, m10bmc_spi_id);

increasing readability due to less explicit casting. This also yields tighter type checking as the assignment in the first hunk results in a warning if info wasn't a pointer to a const type.

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

There are no dependencies between the patches, and they are merge window material.

Best regards
Uwe

Uwe Kleine-König (The Capable Hub) (3):
mfd: Drop unused assignment of spi_device_id driver data
mfd: Initialize spi_device_id arrays using member names
mfd: Unify style of spi_device_id arrays

 drivers/mfd/altera-a10sr.c      |  2 +-
 drivers/mfd/arizona-spi.c       | 12 ++++++------
 drivers/mfd/cs40l50-spi.c       |  4 ++--
 drivers/mfd/da9052-spi.c        | 12 ++++++------
 drivers/mfd/intel-m10-bmc-spi.c |  6 +++---
 drivers/mfd/madera-spi.c        | 18 +++++++++---------
 drivers/mfd/motorola-cpcap.c    |  6 +++---
 drivers/mfd/ocelot-spi.c        |  2 +-
 drivers/mfd/rk8xx-spi.c         |  2 +-
 drivers/mfd/rsmu_spi.c          | 12 ++++++------
 drivers/mfd/sprd-sc27xx-spi.c   |  2 +-
 drivers/mfd/stmpe-spi.c         | 12 ++++++------
 drivers/mfd/tps65912-spi.c      |  2 +-
 drivers/mfd/wm831x-spi.c        | 16 ++++++++--------
 14 files changed, 54 insertions(+), 54 deletions(-)

base-commit: 4f441960e691d37c880d2cc004de06bb5b6bd5e4

Signature · 1 line
2.55.0.11.g153666a7d9bb
#1 lore raw

PATCH 1/3 mfd: Drop unused assignment of spi_device_id driver data

The drivers explicitly set the .driver_data member of struct spi_device_id to zero without relying on that value. Drop these unused assignments.

While touching these arrays use named initializers for .name.

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/mfd/ocelot-spi.c   | 2 +-
 drivers/mfd/rk8xx-spi.c    | 2 +-
 drivers/mfd/tps65912-spi.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/mfd/ocelot-spi.c +1 -1
index fc30663824bb..d3ab4868a523 100644
@@ -270,7 +270,7 @@ static int ocelot_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id ocelot_spi_ids[] = {
-	{ "vsc7512", 0 },
+	{ .name = "vsc7512" },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ocelot_spi_ids);
drivers/mfd/rk8xx-spi.c +1 -1
index 3405fb82ff9f..bb85fe60518f 100644
@@ -104,7 +104,7 @@ static const struct of_device_id rk8xx_spi_of_match[] = {
 MODULE_DEVICE_TABLE(of, rk8xx_spi_of_match);
 
 static const struct spi_device_id rk8xx_spi_id_table[] = {
-	{ "rk806", 0 },
+	{ .name = "rk806" },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, rk8xx_spi_id_table);
drivers/mfd/tps65912-spi.c +1 -1
index 2a77dccd6059..2442a2e67d67 100644
@@ -43,7 +43,7 @@ static int tps65912_spi_probe(struct spi_device *spi)
 }
 
 static const struct spi_device_id tps65912_spi_id_table[] = {
-	{ "tps65912", 0 },
+	{ .name = "tps65912" },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(spi, tps65912_spi_id_table);
Signature · 1 line
2.55.0.11.g153666a7d9bb
#2 lore raw

PATCH 2/3 mfd: Initialize spi_device_id arrays using member names

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 spi_device_id that replaces .driver_data by an anonymous union.

Also adapt spacing and usage of commas to the most common style.

This patch doesn't modify the compiled array, only its representation in source form benefits.

---
 drivers/mfd/arizona-spi.c       | 12 ++++++------
 drivers/mfd/cs40l50-spi.c       |  4 ++--
 drivers/mfd/da9052-spi.c        | 12 ++++++------
 drivers/mfd/intel-m10-bmc-spi.c |  6 +++---
 drivers/mfd/madera-spi.c        | 18 +++++++++---------
 drivers/mfd/rsmu_spi.c          | 12 ++++++------
 drivers/mfd/stmpe-spi.c         | 12 ++++++------
 drivers/mfd/wm831x-spi.c        | 16 ++++++++--------
 8 files changed, 46 insertions(+), 46 deletions(-)
drivers/mfd/arizona-spi.c +6 -6
index eaa2b2bc5dd0..04baf5a1c652 100644
@@ -255,12 +255,12 @@ static void arizona_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id arizona_spi_ids[] = {
-	{ "wm5102", WM5102 },
-	{ "wm5110", WM5110 },
-	{ "wm8280", WM8280 },
-	{ "wm1831", WM1831 },
-	{ "cs47l24", CS47L24 },
-	{ },
+	{ .name = "wm5102", .driver_data = WM5102 },
+	{ .name = "wm5110", .driver_data = WM5110 },
+	{ .name = "wm8280", .driver_data = WM8280 },
+	{ .name = "wm1831", .driver_data = WM1831 },
+	{ .name = "cs47l24", .driver_data = CS47L24 },
+	{ }
 };
 MODULE_DEVICE_TABLE(spi, arizona_spi_ids);
 
drivers/mfd/cs40l50-spi.c +2 -2
index 53526b595a0d..a635951ca6b7 100644
@@ -40,8 +40,8 @@ static void cs40l50_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id cs40l50_id_spi[] = {
-	{ "cs40l50" },
-	{}
+	{ .name = "cs40l50" },
+	{ }
 };
 MODULE_DEVICE_TABLE(spi, cs40l50_id_spi);
 
drivers/mfd/da9052-spi.c +6 -6
index be5f2b34e18a..29cf2c17fde1 100644
@@ -63,12 +63,12 @@ static void da9052_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id da9052_spi_id[] = {
-	{"da9052", DA9052},
-	{"da9053-aa", DA9053_AA},
-	{"da9053-ba", DA9053_BA},
-	{"da9053-bb", DA9053_BB},
-	{"da9053-bc", DA9053_BC},
-	{}
+	{ .name = "da9052", .driver_data = DA9052 },
+	{ .name = "da9053-aa", .driver_data = DA9053_AA },
+	{ .name = "da9053-ba", .driver_data = DA9053_BA },
+	{ .name = "da9053-bb", .driver_data = DA9053_BB },
+	{ .name = "da9053-bc", .driver_data = DA9053_BC },
+	{ }
 };
 
 static struct spi_driver da9052_spi_driver = {
drivers/mfd/intel-m10-bmc-spi.c +3 -3
index cfa620f0c70e..94b9c99bb4f8 100644
@@ -160,9 +160,9 @@ static const struct intel_m10bmc_platform_info m10bmc_spi_n5010 = {
 };
 
 static const struct spi_device_id m10bmc_spi_id[] = {
-	{ "m10-n3000", (kernel_ulong_t)&m10bmc_spi_n3000 },
-	{ "m10-d5005", (kernel_ulong_t)&m10bmc_spi_d5005 },
-	{ "m10-n5010", (kernel_ulong_t)&m10bmc_spi_n5010 },
+	{ .name = "m10-n3000", .driver_data = (kernel_ulong_t)&m10bmc_spi_n3000 },
+	{ .name = "m10-d5005", .driver_data = (kernel_ulong_t)&m10bmc_spi_d5005 },
+	{ .name = "m10-n5010", .driver_data = (kernel_ulong_t)&m10bmc_spi_n5010 },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, m10bmc_spi_id);
drivers/mfd/madera-spi.c +9 -9
index ce9e90322c9c..3fffa21ceadc 100644
@@ -112,15 +112,15 @@ static void madera_spi_remove(struct spi_device *spi)
 }
 
 static const struct spi_device_id madera_spi_ids[] = {
-	{ "cs47l15", CS47L15 },
-	{ "cs47l35", CS47L35 },
-	{ "cs47l85", CS47L85 },
-	{ "cs47l90", CS47L90 },
-	{ "cs47l91", CS47L91 },
-	{ "cs42l92", CS42L92 },
-	{ "cs47l92", CS47L92 },
-	{ "cs47l93", CS47L93 },
-	{ "wm1840", WM1840 },
+	{ .name = "cs47l15", .driver_data = CS47L15 },
+	{ .name = "cs47l35", .driver_data = CS47L35 },
+	{ .name = "cs47l85", .driver_data = CS47L85 },
+	{ .name = "cs47l90", .driver_data = CS47L90 },
+	{ .name = "cs47l91", .driver_data = CS47L91 },
+	{ .name = "cs42l92", .driver_data = CS42L92 },
+	{ .name = "cs47l92", .driver_data = CS47L92 },
+	{ .name = "cs47l93", .driver_data = CS47L93 },
+	{ .name = "wm1840", .driver_data = WM1840 },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, madera_spi_ids);
drivers/mfd/rsmu_spi.c +6 -6
index e07f21482439..cdb0f9797ec6 100644
@@ -239,12 +239,12 @@ static void rsmu_spi_remove(struct spi_device *client)
 }
 
 static const struct spi_device_id rsmu_spi_id[] = {
-	{ "8a34000",  RSMU_CM },
-	{ "8a34001",  RSMU_CM },
-	{ "8a34002",  RSMU_CM },
-	{ "82p33810", RSMU_SABRE },
-	{ "82p33811", RSMU_SABRE },
-	{}
+	{ .name = "8a34000", .driver_data = RSMU_CM },
+	{ .name = "8a34001", .driver_data = RSMU_CM },
+	{ .name = "8a34002", .driver_data = RSMU_CM },
+	{ .name = "82p33810", .driver_data = RSMU_SABRE },
+	{ .name = "82p33811", .driver_data = RSMU_SABRE },
+	{ }
 };
 MODULE_DEVICE_TABLE(spi, rsmu_spi_id);
 
drivers/mfd/stmpe-spi.c +6 -6
index dea31efface6..22a3da062dee 100644
@@ -121,12 +121,12 @@ static const struct of_device_id stmpe_spi_of_match[] = {
 MODULE_DEVICE_TABLE(of, stmpe_spi_of_match);
 
 static const struct spi_device_id stmpe_spi_id[] = {
-	{ "stmpe610", STMPE610 },
-	{ "stmpe801", STMPE801 },
-	{ "stmpe811", STMPE811 },
-	{ "stmpe1601", STMPE1601 },
-	{ "stmpe2401", STMPE2401 },
-	{ "stmpe2403", STMPE2403 },
+	{ .name = "stmpe610", .driver_data = STMPE610 },
+	{ .name = "stmpe801", .driver_data = STMPE801 },
+	{ .name = "stmpe811", .driver_data = STMPE811 },
+	{ .name = "stmpe1601", .driver_data = STMPE1601 },
+	{ .name = "stmpe2401", .driver_data = STMPE2401 },
+	{ .name = "stmpe2403", .driver_data = STMPE2403 },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, stmpe_spi_id);
drivers/mfd/wm831x-spi.c +8 -8
index 54c87267917b..1e519fd9a9e1 100644
@@ -77,14 +77,14 @@ static const struct dev_pm_ops wm831x_spi_pm = {
 };
 
 static const struct spi_device_id wm831x_spi_ids[] = {
-	{ "wm8310", WM8310 },
-	{ "wm8311", WM8311 },
-	{ "wm8312", WM8312 },
-	{ "wm8320", WM8320 },
-	{ "wm8321", WM8321 },
-	{ "wm8325", WM8325 },
-	{ "wm8326", WM8326 },
-	{ },
+	{ .name = "wm8310", .driver_data = WM8310 },
+	{ .name = "wm8311", .driver_data = WM8311 },
+	{ .name = "wm8312", .driver_data = WM8312 },
+	{ .name = "wm8320", .driver_data = WM8320 },
+	{ .name = "wm8321", .driver_data = WM8321 },
+	{ .name = "wm8325", .driver_data = WM8325 },
+	{ .name = "wm8326", .driver_data = WM8326 },
+	{ }
 };
 
 static struct spi_driver wm831x_spi_driver = {
Signature · 1 line
2.55.0.11.g153666a7d9bb
maintainer Reviewed-by on v1 2/3
#3 lore raw
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 spi_device_id that replaces .driver_data by an anonymous union.

Quoted 7 lines

Also adapt spacing and usage of commas to the most common style.

This patch doesn't modify the compiled array, only its representation in source form benefits.

---

Cirrus/Wolfson bits all look good to me:

Thanks,
Charles

#4 lore raw

PATCH 3/3 mfd: Unify style of spi_device_id arrays

In reply to Uwe Kleine-König (The Capable Hub)

The two previous commits adapted the style of some spi_device_id arrays. Fix the remaining arrays to the same style, that is:

- no comma after the list terminator and after an initializer iff the closing } is on the same line
- a single space in the list terminator

---
 drivers/mfd/altera-a10sr.c    | 2 +-
 drivers/mfd/motorola-cpcap.c  | 6 +++---
 drivers/mfd/sprd-sc27xx-spi.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/mfd/altera-a10sr.c +1 -1
index d53e433ab5c1..9c0262228655 100644
@@ -155,7 +155,7 @@ MODULE_DEVICE_TABLE(of, altr_a10sr_spi_of_match);
 
 static const struct spi_device_id altr_a10sr_spi_ids[] = {
 	{ .name = "a10sr" },
-	{ },
+	{ }
 };
 MODULE_DEVICE_TABLE(spi, altr_a10sr_spi_ids);
 
drivers/mfd/motorola-cpcap.c +3 -3
index feeccb2c6655..4ed8704c985a 100644
@@ -202,9 +202,9 @@ static const struct of_device_id cpcap_of_match[] = {
 MODULE_DEVICE_TABLE(of, cpcap_of_match);
 
 static const struct spi_device_id cpcap_spi_ids[] = {
-	{ .name = "cpcap", },
-	{ .name = "6556002", },
-	{},
+	{ .name = "cpcap" },
+	{ .name = "6556002" },
+	{ }
 };
 MODULE_DEVICE_TABLE(spi, cpcap_spi_ids);
 
drivers/mfd/sprd-sc27xx-spi.c +1 -1
index aa052f646623..8c4af2f7ece2 100644
@@ -294,7 +294,7 @@ MODULE_DEVICE_TABLE(of, sprd_pmic_match);
 static const struct spi_device_id sprd_pmic_spi_ids[] = {
 	{ .name = "sc2730", .driver_data = PMIC_TYPE_SC2730 },
 	{ .name = "sc2731", .driver_data = PMIC_TYPE_SC2731 },
-	{},
+	{ }
 };
 MODULE_DEVICE_TABLE(spi, sprd_pmic_spi_ids);
 
Signature · 1 line
2.55.0.11.g153666a7d9bb
maintainer Applied
#5 lore raw
In reply to Uwe Kleine-König (The Capable Hub)
Quoted 6 lines · Uwe Kleine-König (The Capable Hub)

this series targets to use named initializers for spi_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

Quoted 7 lines
	diff --git a/include/linux/device-id/spi.h b/include/linux/device-id/spi.h
	index 812e7c3854a7..93d9cd45569a 100644
	--- a/include/linux/device-id/spi.h
	+++ b/include/linux/device-id/spi.h
	@@ -13,7 +13,11 @@ typedef unsigned long kernel_ulong_t;

[...]

Applied, thanks!

[1/3] mfd: Drop unused assignment of spi_device_id driver data

      commit: 8339fb0eca348d41f04bb9631707192569f753e6
[2/3] mfd: Initialize spi_device_id arrays using member names
      commit: bdaceafafa54b3fd4f9dba9e0044a910f16e4a2c
[3/3] mfd: Unify style of spi_device_id arrays
      commit: 6384e5c5e0bcfbc9a915d70cb3925e0022d7b337

--
Lee Jones [李琼斯]