From nobody Mon May 25 05:12:54 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6968448C3F1 for ; Mon, 18 May 2026 16:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779122723; cv=none; b=eRbome/KFS15Nl5grsfeEj3MeXABycRv7PA2Qu78BcZInFzlWuRUp8EsrgnRGHc7WVGBdj4SVO+viwHZ4hysgszh+Tn7ulYBBJpGxW0eJXpTZ4uWBd6dIoP1AHb4udteZ9p65x4lJZk4FusgfdevaBJ6oSxzei6AmRAqCo+Cp+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779122723; c=relaxed/simple; bh=lCH/RQ3ab4WHRokQ/M9DUnB00sh46GAiobF+8oiI4Vc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lXLo/QXfKWPN354lMRG7z0NxHfarJTbaW+UrlUekZKGwCj86vVGieGPoqNJK9YYMQspeh4fFNGkTes1MQFqD4TGGflQqdSuefUKqRUQ7PVNAcPigIIEIx+u9zH9FuEGwk97LCW6d/vlYCc0wbt962bYTetwkHK6Oj1bEOYWXUKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b=Waw7m/Gn; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.b="Waw7m/Gn" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-488a88aeec9so30454175e9.2 for ; Mon, 18 May 2026 09:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1779122718; x=1779727518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=e4uoJqOZQPI2cVHQzOQoRk6wrV7n9yA1ivdWcQg27mc=; b=Waw7m/GnMONd5p2mErNWBYQyHzIuR1amS9drXSQGgPbtodgZEyfMGI4GCY3b4G7KYO kaHm5lU0EZLA6rDHlUIyfj6bkWOh9aAaiN2b9fw0sBGLik4de9lUnvuUEMZ2TCB5DE2W xMa0WMU1qC0VB2iH3qWuWZSUO+iAUwgyFLLG7xKKNwcF2geuowW4zdaztHzQhJLyvj1v rBXub16ptGB3h0VeLdnhSn+lpiK+Q/ltOl477huDY3I3SDTuC6Jsdhi/Y+fM01p2zdTg y98Xzy2btIHBUGATCywU1ReBUZEF2B8apzGCyY14vj8HfJ3TsU9DE8oOScj7h4Eq8U+k pCZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779122718; x=1779727518; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=e4uoJqOZQPI2cVHQzOQoRk6wrV7n9yA1ivdWcQg27mc=; b=A6VjMQClm+uTaSu/xwif3MiznbS+5iRe+vKSxvABBKMmgTorGbt/1f8hep/b2XHAl4 pirpREW2DWXJ2NaVbX3GBV4ppIp36NfzTaUVv+HjGEayddArIDmll8pnmw3YR0zZb9Ne +o9YcJTLGdy07B7E7/WGp9svMummWpB0XPVpImwHrNA1+PODxX5Ejru1YFa//B8stqE2 o99ZRQ4NO4mJ8af8mfuQmnDEfy9c9i6Y//vC41DJ2/yD/Q5PnWB2dQ2a17UMN54f6y48 V6Z+GnFk8dtPIfcMTwJx5beUfDiisOiuc95O3vTe/1qmQwm/NgyUlElGE1otBfNi9lyx Idbw== X-Forwarded-Encrypted: i=1; AFNElJ8kdBMUKGNY7aLdgXSEPy3DDE+rcNDTcY831MrnbWim1L9NAOJ2cOVIizWjQSaXpcMyFZoRMQ+2sbDZe8k=@vger.kernel.org X-Gm-Message-State: AOJu0YxS5U1l61ZpacHxg2OZdl4u1xt1QaKJl7T7HNafukBOLpqfGI8G 5GV8+nYzjCqEp1tWTK1VZiNwpFzIPKYtzdRPWGFBN7diJI/9buBLDGFdl0M12nXXO9Q= X-Gm-Gg: Acq92OFqHGjWs6/tt8/bcW8cN9ROK0Nzk4VFbVFFEH5s2mSS9u/Dt+9cF7ApE4vpbup Pv0xaIhzfsnYqUwnH7scisBBWRswRq7TTvY7Q8OPgIericY8yEm/o/ZdIe/qFgEa7UsIJKlUfdj 2iUwZAr8pwpNcHFBFhZe6jGiopr8yZVo/u2/TTphu/IU9wTJP3cbj2MpfeqzA/WStm54z8n7SnF HyfcCalFLyzIszounDdxyVOh23SnLu0GTb1VSvs2t6UPg7QiRpcwwjfEktEf6AMXuMyJJza8K6s r8zCtpRV+gCDf9YsbrTHlnWkRwUl5KFvPjlKapGJ2SgtA0wCL2DLvR3Ni49hULooz+chIw40txM vsX6PseKtFBG6P6nA2oiWLJxxXFKgIFI1wPJ3u1EjR8jhqoQi4CFP91prShfE2Ntc7C0T8NA3tB zF14ITCaDp25hXqRHCgk8xsBfXF+5RpaP89CuV6NrOxz1gP8rhRKUbCsKg+z7VbE8XF+WTj2wVV 8eMpojQof5VQkQaSPX3CBA/ X-Received: by 2002:a05:600c:181b:b0:48f:e230:2a1d with SMTP id 5b1f17b1804b1-48fec369d0fmr142735965e9.32.1779122717763; Mon, 18 May 2026 09:45:17 -0700 (PDT) Received: from localhost (p200300f65f47db041bee4d0e08e9609b.dip0.t-ipconnect.de. [2003:f6:5f47:db04:1bee:4d0e:8e9:609b]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-48fe5ab3977sm290714205e9.9.2026.05.18.09.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 09:45:17 -0700 (PDT) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20=28The=20Capable=20Hub=29?= To: Wolfram Sang , Peter Rosin Cc: Michael Hennerich , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] i2c: Use named initializers for arrays of i2c_device_data Date: Mon, 18 May 2026 18:45:09 +0200 Message-ID: <20260518164510.805502-2-u.kleine-koenig@baylibre.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Developer-Signature: v=1; a=openpgp-sha256; l=10046; i=u.kleine-koenig@baylibre.com; h=from:subject; bh=lCH/RQ3ab4WHRokQ/M9DUnB00sh46GAiobF+8oiI4Vc=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBqC0IWKD1anbKMQT5x3rIuO8tRTfVyYIG6F45vD vXmFuLqvm6JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCagtCFgAKCRCPgPtYfRL+ TgPRB/4tYpmhpRNIIafzwyzih7JRor42G48nsBsAJm0vqj1u8+T3mLpTscaBJtP4AT76+dhv3HS 8i+j5qVenK9XBR+h9xLo5xiqS4GTvwvy22X6UtC/JtiHVL07TcR5R3ERjJ0gMutxU40tKzGMBEc NTqRgYAuALE8G6Txzvwlh2wIMP8Tz0mrG0fuqxxX1cZa+C+rH1IovVj9WJvviDQ40sGNqMKquez CnJO+Nn73HIyjVizZmh9uJzaCVSDzf4wPr9pWJizWZMkP9ZtN9sz1ppOGnwDBvjqM/thAn5uaar uO7K84h7dNyNy9PnMZB0W1q67JCKnc2bjttCbew/9b5LnBZo X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 Content-Transfer-Encoding: quoted-printable 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=C3=B6nig (The Capable Hub) Forwarded: id:20260518134035.644762-2-u.kleine-koenig@baylibre.com Reviewed-by: Wolfram Sang --- Hello, the mentioned change to i2c_device_id is the following: diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetab= le.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..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 =3D {10, 4, 0,= 120000}; static const struct i2c_device_id ad5398_id[] =3D { - { .name =3D "ad5398", .driver_data =3D (kernel_ulong_t)&df_10_4_120 }, - { .name =3D "ad5821", .driver_data =3D (kernel_ulong_t)&df_10_4_120 }, + { .name =3D "ad5398", .driver_data_ptr =3D &df_10_4_120 }, + { .name =3D "ad5821", .driver_data_ptr =3D &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 =3D dev_get_platdata(&client->dev); struct regulator_config config =3D { }; struct ad5398_chip_info *chip; - const struct ad5398_current_data_format *df =3D - (struct ad5398_current_data_format *)id->driver_data; + const struct ad5398_current_data_format *df =3D id->driver_data; chip =3D 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 an i2c 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. Best regards Uwe [1] https://cheri-alliance.org/discover-cheri/ https://lwn.net/Articles/1037974/ drivers/i2c/i2c-core-base.c | 4 ++-- drivers/i2c/i2c-slave-eeprom.c | 16 ++++++------- drivers/i2c/i2c-slave-testunit.c | 2 +- drivers/i2c/i2c-smbus.c | 2 +- drivers/i2c/muxes/i2c-mux-ltc4306.c | 4 ++-- drivers/i2c/muxes/i2c-mux-pca9541.c | 4 ++-- drivers/i2c/muxes/i2c-mux-pca954x.c | 36 ++++++++++++++--------------- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 9c46147e3506..7e4b7adffd6e 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1107,8 +1107,8 @@ EXPORT_SYMBOL(i2c_find_device_by_fwnode); =20 =20 static const struct i2c_device_id dummy_id[] =3D { - { "dummy", }, - { "smbus_host_notify", }, + { .name =3D "dummy" }, + { .name =3D "smbus_host_notify" }, { } }; =20 diff --git a/drivers/i2c/i2c-slave-eeprom.c b/drivers/i2c/i2c-slave-eeprom.c index 6bc2ef650a74..226d722af662 100644 --- a/drivers/i2c/i2c-slave-eeprom.c +++ b/drivers/i2c/i2c-slave-eeprom.c @@ -191,14 +191,14 @@ static void i2c_slave_eeprom_remove(struct i2c_client= *client) } =20 static const struct i2c_device_id i2c_slave_eeprom_id[] =3D { - { "slave-24c02", I2C_SLAVE_DEVICE_MAGIC(2048 / 8, 0) }, - { "slave-24c02ro", I2C_SLAVE_DEVICE_MAGIC(2048 / 8, I2C_SLAVE_FLAG_RO) }, - { "slave-24c32", I2C_SLAVE_DEVICE_MAGIC(32768 / 8, I2C_SLAVE_FLAG_ADDR16)= }, - { "slave-24c32ro", I2C_SLAVE_DEVICE_MAGIC(32768 / 8, I2C_SLAVE_FLAG_ADDR1= 6 | I2C_SLAVE_FLAG_RO) }, - { "slave-24c64", I2C_SLAVE_DEVICE_MAGIC(65536 / 8, I2C_SLAVE_FLAG_ADDR16)= }, - { "slave-24c64ro", I2C_SLAVE_DEVICE_MAGIC(65536 / 8, I2C_SLAVE_FLAG_ADDR1= 6 | I2C_SLAVE_FLAG_RO) }, - { "slave-24c512", I2C_SLAVE_DEVICE_MAGIC(524288 / 8, I2C_SLAVE_FLAG_ADDR1= 6) }, - { "slave-24c512ro", I2C_SLAVE_DEVICE_MAGIC(524288 / 8, I2C_SLAVE_FLAG_ADD= R16 | I2C_SLAVE_FLAG_RO) }, + { .name =3D "slave-24c02", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(2048 /= 8, 0) }, + { .name =3D "slave-24c02ro", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(2048= / 8, I2C_SLAVE_FLAG_RO) }, + { .name =3D "slave-24c32", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(32768 = / 8, I2C_SLAVE_FLAG_ADDR16) }, + { .name =3D "slave-24c32ro", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(3276= 8 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) }, + { .name =3D "slave-24c64", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(65536 = / 8, I2C_SLAVE_FLAG_ADDR16) }, + { .name =3D "slave-24c64ro", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(6553= 6 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) }, + { .name =3D "slave-24c512", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(52428= 8 / 8, I2C_SLAVE_FLAG_ADDR16) }, + { .name =3D "slave-24c512ro", .driver_data =3D I2C_SLAVE_DEVICE_MAGIC(524= 288 / 8, I2C_SLAVE_FLAG_ADDR16 | I2C_SLAVE_FLAG_RO) }, { } }; MODULE_DEVICE_TABLE(i2c, i2c_slave_eeprom_id); diff --git a/drivers/i2c/i2c-slave-testunit.c b/drivers/i2c/i2c-slave-testu= nit.c index 6de4307050dd..68a07d957113 100644 --- a/drivers/i2c/i2c-slave-testunit.c +++ b/drivers/i2c/i2c-slave-testunit.c @@ -270,7 +270,7 @@ static void i2c_slave_testunit_remove(struct i2c_client= *client) } =20 static const struct i2c_device_id i2c_slave_testunit_id[] =3D { - { "slave-testunit" }, + { .name =3D "slave-testunit" }, { } }; MODULE_DEVICE_TABLE(i2c, i2c_slave_testunit_id); diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index bc7bd55e6370..069f08f68bc1 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -220,7 +220,7 @@ static void smbalert_remove(struct i2c_client *ara) } =20 static const struct i2c_device_id smbalert_ids[] =3D { - { "smbus_alert" }, + { .name =3D "smbus_alert" }, { /* LIST END */ } }; MODULE_DEVICE_TABLE(i2c, smbalert_ids); diff --git a/drivers/i2c/muxes/i2c-mux-ltc4306.c b/drivers/i2c/muxes/i2c-mu= x-ltc4306.c index 50fbc0d06e62..18228f5b80e8 100644 --- a/drivers/i2c/muxes/i2c-mux-ltc4306.c +++ b/drivers/i2c/muxes/i2c-mux-ltc4306.c @@ -191,8 +191,8 @@ static int ltc4306_deselect_mux(struct i2c_mux_core *mu= xc, u32 chan) } =20 static const struct i2c_device_id ltc4306_id[] =3D { - { "ltc4305", ltc_4305 }, - { "ltc4306", ltc_4306 }, + { .name =3D "ltc4305", .driver_data =3D ltc_4305 }, + { .name =3D "ltc4306", .driver_data =3D ltc_4306 }, { } }; MODULE_DEVICE_TABLE(i2c, ltc4306_id); diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mu= x-pca9541.c index 3d8002caf703..9a59129bc50f 100644 --- a/drivers/i2c/muxes/i2c-mux-pca9541.c +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c @@ -74,8 +74,8 @@ struct pca9541 { }; =20 static const struct i2c_device_id pca9541_id[] =3D { - { "pca9541" }, - {} + { .name =3D "pca9541" }, + { } }; =20 MODULE_DEVICE_TABLE(i2c, pca9541_id); diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mu= x-pca954x.c index b9f370c9f018..8fca709ed279 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -250,24 +250,24 @@ static const struct chip_desc chips[] =3D { }; =20 static const struct i2c_device_id pca954x_id[] =3D { - { "max7356", max_7356 }, - { "max7357", max_7357 }, - { "max7358", max_7358 }, - { "max7367", max_7367 }, - { "max7368", max_7368 }, - { "max7369", max_7369 }, - { "pca9540", pca_9540 }, - { "pca9542", pca_9542 }, - { "pca9543", pca_9543 }, - { "pca9544", pca_9544 }, - { "pca9545", pca_9545 }, - { "pca9546", pca_9546 }, - { "pca9547", pca_9547 }, - { "pca9548", pca_9548 }, - { "pca9846", pca_9846 }, - { "pca9847", pca_9847 }, - { "pca9848", pca_9848 }, - { "pca9849", pca_9849 }, + { .name =3D "max7356", .driver_data =3D max_7356 }, + { .name =3D "max7357", .driver_data =3D max_7357 }, + { .name =3D "max7358", .driver_data =3D max_7358 }, + { .name =3D "max7367", .driver_data =3D max_7367 }, + { .name =3D "max7368", .driver_data =3D max_7368 }, + { .name =3D "max7369", .driver_data =3D max_7369 }, + { .name =3D "pca9540", .driver_data =3D pca_9540 }, + { .name =3D "pca9542", .driver_data =3D pca_9542 }, + { .name =3D "pca9543", .driver_data =3D pca_9543 }, + { .name =3D "pca9544", .driver_data =3D pca_9544 }, + { .name =3D "pca9545", .driver_data =3D pca_9545 }, + { .name =3D "pca9546", .driver_data =3D pca_9546 }, + { .name =3D "pca9547", .driver_data =3D pca_9547 }, + { .name =3D "pca9548", .driver_data =3D pca_9548 }, + { .name =3D "pca9846", .driver_data =3D pca_9846 }, + { .name =3D "pca9847", .driver_data =3D pca_9847 }, + { .name =3D "pca9848", .driver_data =3D pca_9848 }, + { .name =3D "pca9849", .driver_data =3D pca_9849 }, { } }; MODULE_DEVICE_TABLE(i2c, pca954x_id); base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731 --=20 2.47.3