Skip to content

clk: Rework initialization of i2c_device_ids

Uwe Kleine-König (The Capable Hub) linux-clk lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2clk: si5341: Drop unused i2c driver_datadrivers/clk/clk-si5341.c+5 -51 reply
2/2clk: Use named initializers for arrays of i2c_device_datadrivers/clk/clk-cdce706.c drivers/clk/clk-cdce925.c drivers/clk/clk-cs2000-cp.c +8 more+35 -352 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchBrian MasneyLuca Ceresoli
1/2R-b
2/2R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH v1 0/2] 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