From nobody Mon May 25 05:13:13 2026 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 766201DD877 for ; Mon, 18 May 2026 13:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779111646; cv=none; b=Nuc0OADdMFMFlq4B3SbPh/+G7S49IcCuOyasapE6yPn2ZEN3Z76QS+zdw6DZ6kAub/bOuNe58vpXv/C8pci+Cwq3kHlMnawlFn6jx/vxqQWPuxbLHnTkqJUk3brkggpMD0MCYCCwXnu+uvq3OJ/gMDQyiz9ACcj6bmptj9r9RfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779111646; c=relaxed/simple; bh=ZhXkY/aFii0+a1TkYz4GJmkLr4kAHKio/rEJc4mD+jA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=FIH6Dv2z9/5/+0zHH/bsNxmEit3eIsCNC5sv7h0utTH9T7/I3IwZyk3om5NbOynZwEqFUpoURJNtPzKZ0uoE/zfdhrNlrFjU5a235bWwzffRKgUOicBH6Fj5xjVlJIQ+uPT1rbiXajw5Ilh/BhIQv1QDr1ht1dD9Q6yH9KGxeCU= 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.20251104.gappssmtp.com header.i=@baylibre-com.20251104.gappssmtp.com header.b=Nizw3OgR; arc=none smtp.client-ip=209.85.128.53 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.20251104.gappssmtp.com header.i=@baylibre-com.20251104.gappssmtp.com header.b="Nizw3OgR" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-488a14c31eeso13829445e9.0 for ; Mon, 18 May 2026 06:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20251104.gappssmtp.com; s=20251104; t=1779111642; x=1779716442; 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=7e3Kv37qN46FabbuNjAXyfnvvC90X5GgaD4rjhPUgYk=; b=Nizw3OgRYO3TyT6GjlgnPltCwgHQTUFVxe3pWHlPE7vc5IZ8MrTxNtl7IF/I4J3HAg xRuZaSA7cB+HG0xipcbxEmTHIGC+6apxrHwKttHNF6SagjprR3J1n1Qwq4aNZyrqsmEa 4Z50tewql2XXTB21Pja6tqS3S112L0mvM6Nvuj4yjWBpQe9frnHeG+IZEb48GpDHbGhS SLuJ5IyXT1GH9HEzIXt86D6poJ1mxUSv85cmlWM8Tm908R6jlqDTMdszVmIgVrxuvr0c petabHJbMDQwpfNne+VWXwLmtp8+rjwe87cfzy4J30vGxdgQJlgzbGUA8+Tpowq2r4b2 2QSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779111642; x=1779716442; 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=7e3Kv37qN46FabbuNjAXyfnvvC90X5GgaD4rjhPUgYk=; b=f0mQYtuSXHKcNPDJh/lGk/P1LTVaR1qUrjuAwJHSuoqinNC4odePNE1W3aeO4INyXY 9yEInSayZjiTTixPSyNpd7pFLEm/DkzAzaRPncMFA7m8clU5+Ib4+nwUFguywh2SJxvp +VP0lc8g1z5CPsCSQllBap0YQQCh9gF2lZtHHLKxlpza91dQLHBjQQhy/LaA0kdcj340 6L9Dr3z41On9zv4JE0Q67Gj3np+a1VFdQg163ue+AzFppC2IHVqdKMJ62DaaJVFo9eWJ WaWel5VYApRcAeT5psSiWaXVrRpeEWKfkKwPK+Fh3Pfn/FD01TI+v9mnfNq34mszK7PU JuLQ== X-Forwarded-Encrypted: i=1; AFNElJ/welAuCLV/+fPvwsZocBlAtSIxEdQYep/1z1Tkkm+GFVGAzkXSTHBJEHpFw2VSbFvT8Jru7qsi915QM9M=@vger.kernel.org X-Gm-Message-State: AOJu0YzZFImms0YPXoxS0l9cQx60B/tHAFgU1qYtHtj1FZQEwZWJSvIs FO6xVoNCD8sSb5IbXxKTPW16ZUvM0PA50WMNIccYlzq/DSvV0ncX75q3x96VJr/kiWw= X-Gm-Gg: Acq92OE3xQUmCnCMb+ecCnJOd+VIsp9TUtomSJ/3CKu/UatYvfq/KCWdorlLwm1ty6t /2QcwgMK6z9BqGsBOEP0/r9+XtN6J0+gwL7xkA7Q1PPoOZVDZFaXmVe8LI+QFOUBVcaJ3yCvjQ6 mtm+Y+Q824AkEOm2/eRURL2+13MUtDzKLb8AhROTgOmb4tnp3MtvR1CS2br+cXXJPE0/rk1Fk4a 5J0/bR8/hqyZ/9FfmrzAqokmYWHjx59YeuQ3YtdlNSdYylOUj2yBw0qC2G4DwLYF5NaiOOmu3TV kUznOl436R7bAz0ziqm+ZOKOBZDlmNwm51dqx6AwgnBLQ5J7n5iO734JEK/Mo2iyZx6+1/r35TY 0McX/z172mJMQFmCPLjuFAOdxNTGvQYkvgthtM9Vdn+LNVhK05JmIcZSjceU0qIDradbkPRBXxi jORy9AFPXRdbF36Zp9ZJnIeOy98KuJixm+lFsxXLZIGS5dYyqyDIrbh0YdxmyIZHj5lLjFHZh/T fRigkROKO1uuQ== X-Received: by 2002:a05:600c:310f:b0:48f:d346:e646 with SMTP id 5b1f17b1804b1-48fe60d5693mr214937675e9.10.1779111641728; Mon, 18 May 2026 06:40:41 -0700 (PDT) Received: from localhost (p200300f65f47db04e77777300859e43d.dip0.t-ipconnect.de. [2003:f6:5f47:db04:e777:7730:859:e43d]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-48fe5694fcasm237673935e9.5.2026.05.18.06.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 06:40:41 -0700 (PDT) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20=28The=20Capable=20Hub=29?= To: Peter Huewe , Jarkko Sakkinen Cc: Jason Gunthorpe , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tpm: Use named initializers for arrays of i2c_device_data Date: Mon, 18 May 2026 15:40:35 +0200 Message-ID: <20260518134035.644762-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=6232; i=u.kleine-koenig@baylibre.com; h=from:subject; bh=ZhXkY/aFii0+a1TkYz4GJmkLr4kAHKio/rEJc4mD+jA=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBqCxbU++qQEdVaxAqo/8l8BQ0m1/2K1bb2i65eo qF6fugk1RSJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCagsW1AAKCRCPgPtYfRL+ TrOKB/9Qnvwl9/SiA5vvgWwnsbHhSW0UoB2wS3555Lw+bx2OvdqgUUfwPv2Wl83ezwUy5baG9jc sjKYnXluTZipV+XqrNg0AoX6yd/NnTmDKWzofkIrqCLQKDKurQsQvQeE07ON2Z151MNO5D2vAf8 APac63DA6DULCt0j6ZGSR9IqIw6XLfPwa42EyxRZrpkruPzj8H6KiMXEYqzHQeEu1+xkVte4jOF oy8IuE+gKVfLdECDbpsmZ9jb6gDYOIyeAMi8yIRLlv6LqhixPiV2+jkhPv2M3zn/V0A3xymIxJl scgKrn9swWQF9D1C11/36T0aYFNTsyw6N8mB6UEdSQwh5bhk 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) --- 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 a tpm 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/char/tpm/st33zp24/i2c.c | 4 ++-- drivers/char/tpm/tpm_i2c_atmel.c | 4 ++-- drivers/char/tpm/tpm_i2c_infineon.c | 8 ++++---- drivers/char/tpm/tpm_i2c_nuvoton.c | 6 +++--- drivers/char/tpm/tpm_tis_i2c.c | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2= c.c index 81348487c125..74b25af5ce79 100644 --- a/drivers/char/tpm/st33zp24/i2c.c +++ b/drivers/char/tpm/st33zp24/i2c.c @@ -133,8 +133,8 @@ static void st33zp24_i2c_remove(struct i2c_client *clie= nt) } =20 static const struct i2c_device_id st33zp24_i2c_id[] =3D { - { TPM_ST33_I2C }, - {} + { .name =3D TPM_ST33_I2C }, + { } }; MODULE_DEVICE_TABLE(i2c, st33zp24_i2c_id); =20 diff --git a/drivers/char/tpm/tpm_i2c_atmel.c b/drivers/char/tpm/tpm_i2c_at= mel.c index 9fd73049821f..6891642a7f51 100644 --- a/drivers/char/tpm/tpm_i2c_atmel.c +++ b/drivers/char/tpm/tpm_i2c_atmel.c @@ -199,8 +199,8 @@ static void i2c_atmel_remove(struct i2c_client *client) } =20 static const struct i2c_device_id i2c_atmel_id[] =3D { - { I2C_DRIVER_NAME }, - {} + { .name =3D I2C_DRIVER_NAME }, + { } }; MODULE_DEVICE_TABLE(i2c, i2c_atmel_id); =20 diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c= _infineon.c index 8b7d32de0b2e..29cf2f998405 100644 --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c @@ -664,10 +664,10 @@ static int tpm_tis_i2c_init(struct device *dev) } =20 static const struct i2c_device_id tpm_tis_i2c_table[] =3D { - {"tpm_i2c_infineon"}, - {"slb9635tt"}, - {"slb9645tt"}, - {}, + { .name =3D "tpm_i2c_infineon" }, + { .name =3D "slb9635tt" }, + { .name =3D "slb9645tt" }, + { } }; =20 MODULE_DEVICE_TABLE(i2c, tpm_tis_i2c_table); diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_= nuvoton.c index d44903b29929..71c59eeaccab 100644 --- a/drivers/char/tpm/tpm_i2c_nuvoton.c +++ b/drivers/char/tpm/tpm_i2c_nuvoton.c @@ -624,9 +624,9 @@ static void i2c_nuvoton_remove(struct i2c_client *clien= t) } =20 static const struct i2c_device_id i2c_nuvoton_id[] =3D { - {"tpm_i2c_nuvoton"}, - {"tpm2_i2c_nuvoton", .driver_data =3D I2C_IS_TPM2}, - {} + { .name =3D "tpm_i2c_nuvoton" }, + { .name =3D "tpm2_i2c_nuvoton", .driver_data =3D I2C_IS_TPM2}, + { } }; MODULE_DEVICE_TABLE(i2c, i2c_nuvoton_id); =20 diff --git a/drivers/char/tpm/tpm_tis_i2c.c b/drivers/char/tpm/tpm_tis_i2c.c index 6cd07dd34507..21d66bfba6a8 100644 --- a/drivers/char/tpm/tpm_tis_i2c.c +++ b/drivers/char/tpm/tpm_tis_i2c.c @@ -375,8 +375,8 @@ static void tpm_tis_i2c_remove(struct i2c_client *clien= t) } =20 static const struct i2c_device_id tpm_tis_i2c_id[] =3D { - { "tpm_tis_i2c" }, - {} + { .name =3D "tpm_tis_i2c" }, + { } }; MODULE_DEVICE_TABLE(i2c, tpm_tis_i2c_id); =20 --=20 2.47.3