Skip to contentSkip to conversation

s390/ism: Drop superflous zeros in pci_device_id array

PATCH Applied Uwe Kleine-König (The Capable Hub) 4 participants 4 messages May 22 – May 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/ism: Drop superflous zeros in pci_device_id array

The .driver_data member of the struct pci_device_id array were initialized by a list expressions to zero without making use of that value. In this case it's better to not specify a value at all and let the compiler fill in the zeros. Same for the list terminator that can better be completely empty.

This patch doesn't introduce changes to the compiled array.

---
Hello,

while being a cleanup that can stand on its own this is also a preparation for making driver_data an anonymous union that requires that .driver_data is initialized by name and not by list order. The union allows to make better use of the C type system and drops the need for casting. The change to a driver will look as follows:

	diff --git a/arch/x86/platform/intel-mid/pwr.c b/arch/x86/platform/intel-mid/pwr.c
	index 1739971478ff..c0d9da81d512 100644
	--- a/arch/x86/platform/intel-mid/pwr.c
	+++ b/arch/x86/platform/intel-mid/pwr.c
	@@ -347,7 +347,7 @@ struct mid_pwr_device_info {
	 
	 static int mid_pwr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
	 {
	-	struct mid_pwr_device_info *info = (void *)id->driver_data;
	+	struct mid_pwr_device_info *info = id->driver_data_ptr;
		struct device *dev = &pdev->dev;
		struct mid_pwr *pwr;
		int ret;
	@@ -471,8 +471,8 @@ static const struct mid_pwr_device_info tng_info = {
	 
	 /* This table should be in sync with the one in drivers/pci/pci-mid.c */
	 static const struct pci_device_id mid_pwr_pci_ids[] = {
	-	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PENWELL), .driver_data = (kernel_ulong_t)&pnw_info },
	-	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_TANGIER), .driver_data = (kernel_ulong_t)&tng_info },
	+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PENWELL), .driver_data_ptr = &pnw_info },
	+	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_TANGIER), .driver_data_ptr = &tng_info },
		{}
	 };

which is a nice improvement dropping three casts and that will make the compiler say:

arch/x86/platform/intel-mid/pwr.c: In function ‘mid_pwr_probe’:
arch/x86/platform/intel-mid/pwr.c:350:44: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
350 | struct mid_pwr_device_info *info = id->driver_data_ptr;
| ^~

(so it promotes that driver data is supposed to be const).

The patch under discussion touches the only pci driver below drivers/s390, so the example is from a different subsystem. Also this means no further patches for this part of my quest to that subsystem.

Best regards
Uwe

 drivers/s390/net/ism_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/s390/net/ism_drv.c +2 -2
index 7d0479e4e095..d99c588d3e00 100644
@@ -23,8 +23,8 @@ MODULE_LICENSE("GPL");
 #define DRV_NAME "ism"
 
 static const struct pci_device_id ism_device_table[] = {
-	{ PCI_VDEVICE(IBM, PCI_DEVICE_ID_IBM_ISM), 0 },
-	{ 0, }
+	{ PCI_VDEVICE(IBM, PCI_DEVICE_ID_IBM_ISM) },
+	{ }
 };
 MODULE_DEVICE_TABLE(pci, ism_device_table);
 

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731

Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Uwe Kleine-König (The Capable Hub)

Subject: [PATCH v1 net-next] s390/ism: Drop superflous zeros in pci_device_id array

Nit: s/superflous/superfluous/ ?

Quoted 7 lines

The .driver_data member of the struct pci_device_id array were initialized by a list expressions to zero without making use of that value. In this case it's better to not specify a value at all and let the compiler fill in the zeros. Same for the list terminator that can better be completely empty.

This patch doesn't introduce changes to the compiled array.

True. For a static const aggregate, omitted members are zero-initialized per C99 6.7.8, so dropping the trailing , 0 and collapsing { 0, } to { } is a no-op at the object level.

Quoted 1 line
maintainer Acked-by
#2 lore raw
Quoted 13 lines · Breno Leitao
Quoted 1 line · Uwe Kleine-König (The Capable Hub)

Subject: [PATCH v1 net-next] s390/ism: Drop superflous zeros in pci_device_id array

Nit: s/superflous/superfluous/ ?

Quoted 7 lines

The .driver_data member of the struct pci_device_id array were initialized by a list expressions to zero without making use of that value. In this case it's better to not specify a value at all and let the compiler fill in the zeros. Same for the list terminator that can better be completely empty.

This patch doesn't introduce changes to the compiled array.

Quoted 7 lines

True. For a static const aggregate, omitted members are zero-initialized per C99 6.7.8, so dropping the trailing , 0 and collapsing { 0, } to { } is a no-op at the object level.

Quoted 1 line
#3 lore raw
In reply to Uwe Kleine-König (The Capable Hub)
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Fri, 22 May 2026 17:30:09 +0200 you wrote:

The .driver_data member of the struct pci_device_id array were initialized by a list expressions to zero without making use of that value. In this case it's better to not specify a value at all and let the compiler fill in the zeros. Same for the list terminator that can better be completely empty.

This patch doesn't introduce changes to the compiled array.

[...]

Here is the summary with links:
- [v1,net-next] s390/ism: Drop superflous zeros in pci_device_id array

    https://git.kernel.org/netdev/net-next/c/18b9f739d3f2

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html