* [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id
@ 2026-05-18 10:41 Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 1/2] extcon: rt8973: Drop unused driver data Uwe Kleine-König (The Capable Hub)
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-05-18 10:41 UTC (permalink / raw)
To: MyungJoo Ham, Chanwoo Choi; +Cc: linux-kernel, Krzysztof Kozlowski
Hello,
I plan to do the following to the definition of i2c_device_id:
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 */
. 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..dfb0b07500a7 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;
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 extcon driver that benefits, so
this is "only" a regulator driver example.)
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 simplifies one extcon driver to not use .driver_data,
the second converts all extcon drivers to initialize i2c_device_ids
using named initializers.
Best regards
Uwe
[1] https://cheri-alliance.org/discover-cheri/
https://lwn.net/Articles/1037974/
Uwe Kleine-König (The Capable Hub) (2):
extcon: rt8973: Drop unused driver data
extcon: Use named initializers for arrays of i2c_device_data
drivers/extcon/extcon-fsa9480.c | 4 ++--
drivers/extcon/extcon-lc824206xa.c | 2 +-
drivers/extcon/extcon-max14526.c | 2 +-
drivers/extcon/extcon-ptn5150.c | 2 +-
drivers/extcon/extcon-rt8973a.c | 2 +-
drivers/extcon/extcon-rt8973a.h | 4 ----
drivers/extcon/extcon-sm5502.c | 6 +++---
7 files changed, 9 insertions(+), 13 deletions(-)
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 1/2] extcon: rt8973: Drop unused driver data
2026-05-18 10:41 [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
@ 2026-05-18 10:41 ` Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 2/2] extcon: Use named initializers for arrays of i2c_device_data Uwe Kleine-König (The Capable Hub)
2026-06-10 17:10 ` [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
2 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-05-18 10:41 UTC (permalink / raw)
To: MyungJoo Ham, Chanwoo Choi; +Cc: linux-kernel
The .driver_data member isn't used in this driver, so the explicit
assignment can safely be dropped. Also drop the enum after its only user
is gone.
While touching this i2c_device_id array, assign .name using a named
initializer which makes it easier to understand and more robust to
changes in the definition of struct i2c_device_id.
Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
---
drivers/extcon/extcon-rt8973a.c | 2 +-
drivers/extcon/extcon-rt8973a.h | 4 ----
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c
index 19bb49f13fb0..dfeedb295c51 100644
--- a/drivers/extcon/extcon-rt8973a.c
+++ b/drivers/extcon/extcon-rt8973a.c
@@ -684,7 +684,7 @@ static SIMPLE_DEV_PM_OPS(rt8973a_muic_pm_ops,
rt8973a_muic_suspend, rt8973a_muic_resume);
static const struct i2c_device_id rt8973a_i2c_id[] = {
- { "rt8973a", TYPE_RT8973A },
+ { .name = "rt8973a" },
{ }
};
MODULE_DEVICE_TABLE(i2c, rt8973a_i2c_id);
diff --git a/drivers/extcon/extcon-rt8973a.h b/drivers/extcon/extcon-rt8973a.h
index 0d0d69fcac92..039af2d1cac6 100644
--- a/drivers/extcon/extcon-rt8973a.h
+++ b/drivers/extcon/extcon-rt8973a.h
@@ -8,10 +8,6 @@
#ifndef __LINUX_EXTCON_RT8973A_H
#define __LINUX_EXTCON_RT8973A_H
-enum rt8973a_types {
- TYPE_RT8973A,
-};
-
/* RT8973A registers */
enum rt8973A_reg {
RT8973A_REG_DEVICE_ID = 0x1,
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 2/2] extcon: Use named initializers for arrays of i2c_device_data
2026-05-18 10:41 [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 1/2] extcon: rt8973: Drop unused driver data Uwe Kleine-König (The Capable Hub)
@ 2026-05-18 10:41 ` Uwe Kleine-König (The Capable Hub)
2026-06-10 17:10 ` [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
2 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-05-18 10:41 UTC (permalink / raw)
To: MyungJoo Ham, Chanwoo Choi; +Cc: Krzysztof Kozlowski, linux-kernel
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.
While touching all these arrays, unify usage of whitespace in the list
terminator.
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>
---
drivers/extcon/extcon-fsa9480.c | 4 ++--
drivers/extcon/extcon-lc824206xa.c | 2 +-
drivers/extcon/extcon-max14526.c | 2 +-
drivers/extcon/extcon-ptn5150.c | 2 +-
drivers/extcon/extcon-sm5502.c | 6 +++---
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/extcon/extcon-fsa9480.c b/drivers/extcon/extcon-fsa9480.c
index a031eb0914a0..5de77ac5a294 100644
--- a/drivers/extcon/extcon-fsa9480.c
+++ b/drivers/extcon/extcon-fsa9480.c
@@ -350,8 +350,8 @@ static const struct dev_pm_ops fsa9480_pm_ops = {
};
static const struct i2c_device_id fsa9480_id[] = {
- { "fsa9480" },
- {}
+ { .name = "fsa9480" },
+ { }
};
MODULE_DEVICE_TABLE(i2c, fsa9480_id);
diff --git a/drivers/extcon/extcon-lc824206xa.c b/drivers/extcon/extcon-lc824206xa.c
index 56938748aea8..a758f2955207 100644
--- a/drivers/extcon/extcon-lc824206xa.c
+++ b/drivers/extcon/extcon-lc824206xa.c
@@ -475,7 +475,7 @@ static int lc824206xa_probe(struct i2c_client *client)
}
static const struct i2c_device_id lc824206xa_i2c_ids[] = {
- { "lc824206xa" },
+ { .name = "lc824206xa" },
{ }
};
MODULE_DEVICE_TABLE(i2c, lc824206xa_i2c_ids);
diff --git a/drivers/extcon/extcon-max14526.c b/drivers/extcon/extcon-max14526.c
index 3750a5c20612..2c337fd7214f 100644
--- a/drivers/extcon/extcon-max14526.c
+++ b/drivers/extcon/extcon-max14526.c
@@ -281,7 +281,7 @@ static const struct of_device_id max14526_match[] = {
MODULE_DEVICE_TABLE(of, max14526_match);
static const struct i2c_device_id max14526_id[] = {
- { "max14526" },
+ { .name = "max14526" },
{ }
};
MODULE_DEVICE_TABLE(i2c, max14526_id);
diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
index eca1b140aeb0..bcbd38ed0d0d 100644
--- a/drivers/extcon/extcon-ptn5150.c
+++ b/drivers/extcon/extcon-ptn5150.c
@@ -393,7 +393,7 @@ static const struct of_device_id ptn5150_dt_match[] = {
MODULE_DEVICE_TABLE(of, ptn5150_dt_match);
static const struct i2c_device_id ptn5150_i2c_id[] = {
- { "ptn5150" },
+ { .name = "ptn5150" },
{ }
};
MODULE_DEVICE_TABLE(i2c, ptn5150_i2c_id);
diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c
index c8c4b9ef72aa..5661b57cbb45 100644
--- a/drivers/extcon/extcon-sm5502.c
+++ b/drivers/extcon/extcon-sm5502.c
@@ -827,9 +827,9 @@ static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops,
sm5502_muic_suspend, sm5502_muic_resume);
static const struct i2c_device_id sm5502_i2c_id[] = {
- { "sm5502", (kernel_ulong_t)&sm5502_data },
- { "sm5504", (kernel_ulong_t)&sm5504_data },
- { "sm5703-muic", (kernel_ulong_t)&sm5502_data },
+ { .name = "sm5502", .driver_data = (kernel_ulong_t)&sm5502_data },
+ { .name = "sm5504", .driver_data = (kernel_ulong_t)&sm5504_data },
+ { .name = "sm5703-muic", .driver_data = (kernel_ulong_t)&sm5502_data },
{ }
};
MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id);
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id
2026-05-18 10:41 [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 1/2] extcon: rt8973: Drop unused driver data Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 2/2] extcon: Use named initializers for arrays of i2c_device_data Uwe Kleine-König (The Capable Hub)
@ 2026-06-10 17:10 ` Uwe Kleine-König (The Capable Hub)
2026-07-17 10:31 ` Uwe Kleine-König (The Capable Hub)
2 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-06-10 17:10 UTC (permalink / raw)
To: MyungJoo Ham, Chanwoo Choi; +Cc: linux-kernel, Krzysztof Kozlowski
[-- Attachment #1: Type: text/plain, Size: 866 bytes --]
On Mon, May 18, 2026 at 12:41:43PM +0200, Uwe Kleine-König (The Capable Hub) wrote:
> Hello,
>
> I plan to do the following to the definition of i2c_device_id:
>
> 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 */
I want to work on that, but I'd need this patch series to be in for it.
Do you still have this patch on your radar?
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id
2026-06-10 17:10 ` [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
@ 2026-07-17 10:31 ` Uwe Kleine-König (The Capable Hub)
0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-07-17 10:31 UTC (permalink / raw)
To: MyungJoo Ham, Chanwoo Choi; +Cc: linux-kernel, Krzysztof Kozlowski
[-- Attachment #1: Type: text/plain, Size: 1240 bytes --]
Hello,
On Wed, Jun 10, 2026 at 07:10:51PM +0200, Uwe Kleine-König (The Capable Hub) wrote:
> On Mon, May 18, 2026 at 12:41:43PM +0200, Uwe Kleine-König (The Capable Hub) wrote:
> > Hello,
> >
> > I plan to do the following to the definition of i2c_device_id:
> >
> > 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 */
>
> I want to work on that, but I'd need this patch series to be in for it.
> Do you still have this patch on your radar?
While I still have to make several patches land before I can modify
struct i2c_device_id, getting the patches from this thread in would at
least make my queue smaller.
FTR: The series still applies fine to next-20260716.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-17 10:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-18 10:41 [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 1/2] extcon: rt8973: Drop unused driver data Uwe Kleine-König (The Capable Hub)
2026-05-18 10:41 ` [PATCH v1 2/2] extcon: Use named initializers for arrays of i2c_device_data Uwe Kleine-König (The Capable Hub)
2026-06-10 17:10 ` [PATCH v1 0/2] extcon: Rework initialization of i2c_device_id Uwe Kleine-König (The Capable Hub)
2026-07-17 10:31 ` Uwe Kleine-König (The Capable Hub)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox