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: 7+ 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)
2026-05-31 5:13 ` Dmitry Torokhov
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$(echo .)com \
--cc=alexandre.belloni@bootlin$(echo .)com \
--cc=alexandre.torgue@foss$(echo .)st.com \
--cc=andriy.shevchenko@linux$(echo .)intel.com \
--cc=anshulusr@gmail$(echo .)com \
--cc=clamor95@gmail$(echo .)com \
--cc=claudiu.beznea@tuxon$(echo .)dev \
--cc=david@ixit$(echo .)cz \
--cc=geert+renesas@glider$(echo .)be \
--cc=hansg@kernel$(echo .)org \
--cc=ii4gsp@gmail$(echo .)com \
--cc=javier.carrasco@wolfvision$(echo .)net \
--cc=jeff@labundy$(echo .)com \
--cc=jekhor@gmail$(echo .)com \
--cc=job@noorman$(echo .)info \
--cc=johannes.kirchmair@skidata$(echo .)com \
--cc=josua@solid-run$(echo .)com \
--cc=kees@kernel$(echo .)org \
--cc=krzysztof.kozlowski@oss$(echo .)qualcomm.com \
--cc=kuzhylol@gmail$(echo .)com \
--cc=linusw@kernel$(echo .)org \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-input@vger$(echo .)kernel.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-stm32@st-md-mailman$(echo .)stormreply.com \
--cc=m.tretter@pengutronix$(echo .)de \
--cc=marco.crivellari@suse$(echo .)com \
--cc=marek.vasut+renesas@mailbox$(echo .)org \
--cc=mcoquelin.stm32@gmail$(echo .)com \
--cc=michael.hennerich@analog$(echo .)com \
--cc=mingo@kernel$(echo .)org \
--cc=mpenttil@redhat$(echo .)com \
--cc=nick@shmanahar$(echo .)org \
--cc=nicolas.ferre@microchip$(echo .)com \
--cc=petr.hodina@protonmail$(echo .)com \
--cc=phucduc.bui@gmail$(echo .)com \
--cc=platform-driver-x86@vger$(echo .)kernel.org \
--cc=sakari.ailus@linux$(echo .)intel.com \
--cc=support.opensource@diasemi$(echo .)com \
--cc=tglx@kernel$(echo .)org \
--cc=thorsten.blum@linux$(echo .)dev \
--cc=u.kleine-koenig@baylibre$(echo .)com \
--cc=y.oudjana@protonmail$(echo .)com \
--cc=zhao.xichao@vivo$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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