Skip to contentSkip to conversation

iommu/riscv: Drop superflous zeros in pci_device_id array

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

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

PATCH 1/1 iommu/riscv: 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.

---
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).

There is no iommu driver using pointers for driver data, so the example is from a different subsystem. Also this is the only pci driver in drivers/iommu, so no further patches for this part of my quest to that subsystem.

Best regards
Uwe

 drivers/iommu/riscv/iommu-pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/riscv/iommu-pci.c +3 -3
index d82d2b00904c..8abf52dfb4c9 100644
@@ -109,9 +109,9 @@ static void riscv_iommu_pci_shutdown(struct pci_dev *pdev)
 }
 
 static const struct pci_device_id riscv_iommu_pci_tbl[] = {
-	{PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_RISCV_IOMMU), 0},
-	{PCI_VDEVICE(RIVOS, PCI_DEVICE_ID_RIVOS_RISCV_IOMMU_GA), 0},
-	{0,}
+	{ PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_RISCV_IOMMU) },
+	{ PCI_VDEVICE(RIVOS, PCI_DEVICE_ID_RIVOS_RISCV_IOMMU_GA) },
+	{ }
 };
 
 static struct pci_driver riscv_iommu_pci_driver = {

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731

Signature · 1 line
2.47.3
#1 lore raw

Hello,

Quoted 7 lines · Uwe Kleine-König (The Capable Hub)

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 was sent before v7.1-rc5 and missed the merge window leading to v7.2-rc1. I wonder if it's still on someone's radar?

Best regards
Uwe

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Uwe Kleine-König (The Capable Hub)
Quoted 5 lines · Uwe Kleine-König (The Capable Hub)

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.

I think I'd agree this counts as a nice enough cleanup in its own right.

Quoted 74 lines

---
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).

There is no iommu driver using pointers for driver data, so the example is from a different subsystem. Also this is the only pci driver in drivers/iommu, so no further patches for this part of my quest to that subsystem.

Best regards
Uwe

  drivers/iommu/riscv/iommu-pci.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/riscv/iommu-pci.c +3 -3
index d82d2b00904c..8abf52dfb4c9 100644
@@ -109,9 +109,9 @@ static void riscv_iommu_pci_shutdown(struct pci_dev *pdev)
  }
 
  static const struct pci_device_id riscv_iommu_pci_tbl[] = {
-	{PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_RISCV_IOMMU), 0},
-	{PCI_VDEVICE(RIVOS, PCI_DEVICE_ID_RIVOS_RISCV_IOMMU_GA), 0},
-	{0,}
+	{ PCI_VDEVICE(REDHAT, PCI_DEVICE_ID_REDHAT_RISCV_IOMMU) },
+	{ PCI_VDEVICE(RIVOS, PCI_DEVICE_ID_RIVOS_RISCV_IOMMU_GA) },
+	{ }
  };
 
  static struct pci_driver riscv_iommu_pci_driver = {

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731