The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Uwe Kleine-König (The Capable Hub)" <u.kleine-koenig@baylibre.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Puranjay Mohan" <puranjay@kernel.org>,
	"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	"Ramona Gradinariu" <ramona.gradinariu@analog.com>,
	"Ariana Lazar" <ariana.lazar@microchip.com>,
	"Alex Lanzano" <lanzano.alex@gmail.com>,
	"Jean-Baptiste Maneyrol" <jean-baptiste.maneyrol@tdk.com>,
	"Remi Buisson" <remi.buisson@tdk.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Christian Eggers" <ceggers@arri.de>,
	"Tomasz Duszynski" <tduszyns@gmail.com>,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
	"Andreas Klinger" <ak@it-klinger.de>,
	"Waqar Hameed" <waqar.hameed@axis.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Gustavo Vaz" <gustavo.vaz@usp.br>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>,
	"Dixit Parmar" <dixitparmar19@gmail.com>,
	"Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Chuang Zhu" <git@chuang.cz>,
	"Kyle Hsieh" <kylehsieh1995@gmail.com>,
	"Linus Walleij" <linusw@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Sander Vanheule" <sander@svanheule.net>,
	"Romain Gantois" <romain.gantois@bootlin.com>,
	"David Jander" <david@protonic.nl>,
	"Kurt Borja" <kuurtb@gmail.com>,
	"Tomas Borquez" <tomasborquez13@gmail.com>,
	"Matti Vaittinen" <mazziesaccount@gmail.com>,
	chuguangqing <chuguangqing@inspur.com>,
	"Shi Hao" <i.shihao.999@gmail.com>,
	"Erikas Bitovtas" <xerikasxx@gmail.com>,
	"Marcus Folkesson" <marcus.folkesson@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] iio: Initialize i2c_device_id arrays using member names
Date: Tue, 12 May 2026 15:00:06 +0100	[thread overview]
Message-ID: <20260512150006.7ab14fcf@jic23-huawei> (raw)
In-Reply-To: <35a46c1014a1452b0c191a588bee8a09ddea964e.1778582187.git.u.kleine-koenig@baylibre.com>

On Tue, 12 May 2026 14:50:35 +0200
Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com> wrote:

> 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.
> 
> 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>
Hi Uwe

A couple of these are cases where we can rip the driver_data out like you did in patch 1.

Other minor things inline.

Thanks for doing this.

Jonathan

> diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
> index b4604f441553..aab3b110faa5 100644
> --- a/drivers/iio/accel/bmc150-accel-i2c.c
> +++ b/drivers/iio/accel/bmc150-accel-i2c.c
> @@ -245,16 +245,16 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
>  MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
>  
>  static const struct i2c_device_id bmc150_accel_id[] = {
> -	{"bma222"},
> -	{"bma222e"},
> -	{"bma250e"},
> -	{"bma253"},
> -	{"bma254"},
> -	{"bma255"},
> -	{"bma280"},
> -	{"bmc150_accel"},
> -	{"bmc156_accel", BOSCH_BMC156},
> -	{"bmi055_accel"},
> +	{ .name = "bma222", .driver_data = 0 },
So we do have BOSCH_UKNOWN for the the 0 value.  It doesn't actually mean
it's unknown but rather that ID matching will work so we don't need
to know what it is.  Maybe we should use it anyway rather than 0?

Original approach of relying on the magic 0 is more horrible still so
this is definitely an improvement!

> +	{ .name = "bma222e", .driver_data = 0 },
> +	{ .name = "bma250e", .driver_data = 0 },
> +	{ .name = "bma253", .driver_data = 0 },
> +	{ .name = "bma254", .driver_data = 0 },
> +	{ .name = "bma255", .driver_data = 0 },
> +	{ .name = "bma280", .driver_data = 0 },
> +	{ .name = "bmc150_accel", .driver_data = 0 },
> +	{ .name = "bmc156_accel", .driver_data = BOSCH_BMC156 },
> +	{ .name = "bmi055_accel", .driver_data = 0 },
>  	{ }
>  };
>  

> diff --git a/drivers/iio/adc/ad7091r5.c b/drivers/iio/adc/ad7091r5.c
> index bd4877268689..d4c4b19edc61 100644
> --- a/drivers/iio/adc/ad7091r5.c
> +++ b/drivers/iio/adc/ad7091r5.c
> @@ -117,7 +117,7 @@ static const struct of_device_id ad7091r5_dt_ids[] = {
>  MODULE_DEVICE_TABLE(of, ad7091r5_dt_ids);
>  
>  static const struct i2c_device_id ad7091r5_i2c_ids[] = {
> -	{ "ad7091r5", (kernel_ulong_t)&ad7091r5_init_info },
> +	{ .name = "ad7091r5", .driver_data = (kernel_ulong_t)&ad7091r5_init_info },
>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, ad7091r5_i2c_ids);

Hmm.  I guess another user of the common library actually supports multiple parts.
For this one we could just hard code it in ad7091r5_i2c_probe()


>
> diff --git a/drivers/iio/dac/max5821.c b/drivers/iio/dac/max5821.c
> index e7e29359f8fe..b3ae00431910 100644
> --- a/drivers/iio/dac/max5821.c
> +++ b/drivers/iio/dac/max5821.c
> @@ -332,7 +332,7 @@ static int max5821_probe(struct i2c_client *client)
>  }
>  
>  static const struct i2c_device_id max5821_id[] = {
> -	{ "max5821", ID_MAX5821 },
> +	{ .name = "max5821", .driver_data = ID_MAX5821 },

Used?  I get suspicious of any single entry ones and I can't immediately
see where it is used.

>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, max5821_id);

> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index fb02eac78ed4..602f7b95c83e 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
Comments below refer to the these 3.

> @@ -1007,8 +1007,8 @@ static const struct of_device_id sx9310_of_match[] = {
>  MODULE_DEVICE_TABLE(of, sx9310_of_match);
>  
>  static const struct i2c_device_id sx9310_id[] = {
> -	{ "sx9310", (kernel_ulong_t)&sx9310_info },
> -	{ "sx9311", (kernel_ulong_t)&sx9311_info },
> +	{ .name = "sx9310", .driver_data = (kernel_ulong_t)&sx9310_info },
> +	{ .name = "sx9311", .driver_data = (kernel_ulong_t)&sx9311_info },

These are used so fine. But the other users of the sx_common library are
less obvious. I'm fairly sure the use here is confined to this sub driver.

>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, sx9310_id);
> diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
> index f61eff39751d..4831d33cb337 100644
> --- a/drivers/iio/proximity/sx9324.c
> +++ b/drivers/iio/proximity/sx9324.c
> @@ -1135,7 +1135,7 @@ static const struct of_device_id sx9324_of_match[] = {
>  MODULE_DEVICE_TABLE(of, sx9324_of_match);
>  
>  static const struct i2c_device_id sx9324_id[] = {
> -	{ "sx9324", SX9324_WHOAMI_VALUE },
> +	{ .name = "sx9324", .driver_data = SX9324_WHOAMI_VALUE },
Same as below. I think you can rip this out.  Do the same for the other
tables whilst doing so.

>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, sx9324_id);
> diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c
> index 4448988d4e7e..f8fd399dc2be 100644
> --- a/drivers/iio/proximity/sx9360.c
> +++ b/drivers/iio/proximity/sx9360.c
> @@ -845,7 +845,7 @@ static const struct of_device_id sx9360_of_match[] = {
>  MODULE_DEVICE_TABLE(of, sx9360_of_match);
>  
>  static const struct i2c_device_id sx9360_id[] = {
> -	{"sx9360", SX9360_WHOAMI_VALUE },
> +	{ .name = "sx9360", .driver_data = SX9360_WHOAMI_VALUE },

These are only 'sort of used'  I wonder if we should just rip
them out.  They are used locally in e.g. sx9310_check_whoami()
but there is only one value so we could hard coded it there instead.

This smells like cut and paste rather than something that is actually useful.
The name should be hardcoded as well.  Is is for this particular
driver and the sx9324.



>  	{ }
>  };
>  MODULE_DEVICE_TABLE(i2c, sx9360_id);

      parent reply	other threads:[~2026-05-12 14:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 12:50 [PATCH v1 0/2] iio: Rework i2c_device_id initialisation Uwe Kleine-König (The Capable Hub)
2026-05-12 12:50 ` [PATCH v1 1/2] iio: Drop unused driver_data in four i2c drivers Uwe Kleine-König (The Capable Hub)
2026-05-12 14:01   ` Jonathan Cameron
2026-05-12 12:50 ` [PATCH v1 2/2] iio: Initialize i2c_device_id arrays using member names Uwe Kleine-König (The Capable Hub)
2026-05-12 13:16   ` Linus Walleij
2026-05-12 14:00   ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260512150006.7ab14fcf@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=ak@it-klinger.de \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=ariana.lazar@microchip.com \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=bigeasy@linutronix.de \
    --cc=ceggers@arri.de \
    --cc=chuguangqing@inspur.com \
    --cc=david@protonic.nl \
    --cc=dixitparmar19@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=git@chuang.cz \
    --cc=gustavo.vaz@usp.br \
    --cc=i.shihao.999@gmail.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jean-baptiste.maneyrol@tdk.com \
    --cc=kuurtb@gmail.com \
    --cc=kylehsieh1995@gmail.com \
    --cc=lanzano.alex@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linusw@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lorenzo@kernel.org \
    --cc=marcelo.schmitt@analog.com \
    --cc=marcus.folkesson@gmail.com \
    --cc=mazziesaccount@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=o.rempel@pengutronix.de \
    --cc=puranjay@kernel.org \
    --cc=ramona.gradinariu@analog.com \
    --cc=remi.buisson@tdk.com \
    --cc=romain.gantois@bootlin.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sander@svanheule.net \
    --cc=tduszyns@gmail.com \
    --cc=tomasborquez13@gmail.com \
    --cc=u.kleine-koenig@baylibre.com \
    --cc=waqar.hameed@axis.com \
    --cc=xerikasxx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox