From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Uwe Kleine-König (The Capable Hub)" <u.kleine-koenig@baylibre.com>
Cc: "Anshul Dalal" <anshulusr@gmail.com>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Yassine Oudjana" <y.oudjana@protonmail.com>,
"Linus Walleij" <linusw@kernel.org>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Support Opensource" <support.opensource@diasemi.com>,
"Nick Dyer" <nick@shmanahar.org>,
"Hans de Goede" <hansg@kernel.org>,
"Job Noorman" <job@noorman.info>,
"Mika Penttilä" <mpenttil@redhat.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Kees Cook" <kees@kernel.org>,
"bui duc phuc" <phucduc.bui@gmail.com>,
"Thorsten Blum" <thorsten.blum@linux.dev>,
"Yauhen Kharuzhy" <jekhor@gmail.com>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Marco Crivellari" <marco.crivellari@suse.com>,
"Minseong Kim" <ii4gsp@gmail.com>,
"Ingo Molnar" <mingo@kernel.org>,
"Thomas Gleixner" <tglx@kernel.org>,
"Oleh Kuzhylnyi" <kuzhylol@gmail.com>,
"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski@oss.qualcomm.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>,
"Josua Mayer" <josua@solid-run.com>,
"Michael Tretter" <m.tretter@pengutronix.de>,
"Jeff LaBundy" <jeff@labundy.com>,
"Javier Carrasco" <javier.carrasco@wolfvision.net>,
"David Heidelberg" <david@ixit.cz>,
"Petr Hodina" <petr.hodina@protonmail.com>,
"Svyatoslav Ryhel" <clamor95@gmail.com>,
"Johannes Kirchmair" <johannes.kirchmair@skidata.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Xichao Zhao" <zhao.xichao@vivo.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
platform-driver-x86@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH v1] Input: Use named initializers for arrays of i2c_device_data
Date: Fri, 29 May 2026 22:56:48 -0700 [thread overview]
Message-ID: <ahp7WuHiPYa7Q_pX@google.com> (raw)
In-Reply-To: <20260515164848.497608-2-u.kleine-koenig@baylibre.com>
Hi Uwe,
On Fri, May 15, 2026 at 06:48:47PM +0200, Uwe Kleine-König (The Capable Hub) 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>
> ---
> 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/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
> index 66ada7ffbc80..94aa4dc002c5 100644
> --- a/drivers/input/touchscreen/ili210x.c
> +++ b/drivers/input/touchscreen/ili210x.c
> @@ -969,7 +969,7 @@ static int ili210x_i2c_probe(struct i2c_client *client)
>
> chip = device_get_match_data(dev);
> if (!chip && id)
> - chip = (const struct ili2xxx_chip *)id->driver_data;
> + chip = id->driver_data_ptr;
> if (!chip)
> return dev_err_probe(&client->dev, -ENODEV, "unknown device model\n");
>
> @@ -1049,10 +1049,10 @@ static int ili210x_i2c_probe(struct i2c_client *client)
> }
>
> static const struct i2c_device_id ili210x_i2c_id[] = {
> - { .name = "ili210x", .driver_data = (long)&ili210x_chip },
> - { .name = "ili2117", .driver_data = (long)&ili211x_chip },
> - { .name = "ili2120", .driver_data = (long)&ili212x_chip },
> - { .name = "ili251x", .driver_data = (long)&ili251x_chip },
> + { .name = "ili210x", .driver_data_ptr = &ili210x_chip },
> + { .name = "ili2117", .driver_data_ptr = &ili211x_chip },
> + { .name = "ili2120", .driver_data_ptr = &ili212x_chip },
> + { .name = "ili251x", .driver_data_ptr = &ili251x_chip },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, ili210x_i2c_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.
>
> 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.
I like the ability to properly set up pointers for driver data, however
I do not think we should use named initializers for name field. As long
as we are not planning on moving its position I like the brevity of just
saying
{ "ili210x", .driver_data_ptr = &ili210x_chip },
Can we keep the old style for the name field?
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-05-30 5:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 16:48 [PATCH v1] Input: Use named initializers for arrays of i2c_device_data Uwe Kleine-König (The Capable Hub)
2026-05-18 7:24 ` Geert Uytterhoeven
2026-05-18 7:30 ` Andy Shevchenko
2026-05-18 7:56 ` Uwe Kleine-König (The Capable Hub)
2026-05-30 5:56 ` Dmitry Torokhov [this message]
2026-05-30 12:02 ` Uwe Kleine-König (The Capable Hub)
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=ahp7WuHiPYa7Q_pX@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=anshulusr@gmail.com \
--cc=clamor95@gmail.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=david@ixit.cz \
--cc=geert+renesas@glider.be \
--cc=hansg@kernel.org \
--cc=ii4gsp@gmail.com \
--cc=javier.carrasco@wolfvision.net \
--cc=jeff@labundy.com \
--cc=jekhor@gmail.com \
--cc=job@noorman.info \
--cc=johannes.kirchmair@skidata.com \
--cc=josua@solid-run.com \
--cc=kees@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=kuzhylol@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=m.tretter@pengutronix.de \
--cc=marco.crivellari@suse.com \
--cc=marek.vasut+renesas@mailbox.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=michael.hennerich@analog.com \
--cc=mingo@kernel.org \
--cc=mpenttil@redhat.com \
--cc=nick@shmanahar.org \
--cc=nicolas.ferre@microchip.com \
--cc=petr.hodina@protonmail.com \
--cc=phucduc.bui@gmail.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=support.opensource@diasemi.com \
--cc=tglx@kernel.org \
--cc=thorsten.blum@linux.dev \
--cc=u.kleine-koenig@baylibre.com \
--cc=y.oudjana@protonmail.com \
--cc=zhao.xichao@vivo.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