Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array
@ 2026-05-22 14:59 Uwe Kleine-König (The Capable Hub)
  2026-07-07  9:07 ` Uwe Kleine-König (The Capable Hub)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-05-22 14:59 UTC (permalink / raw)
  To: Tomasz Jeznach, Joerg Roedel, Will Deacon
  Cc: Robin Murphy, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, iommu, linux-riscv, linux-kernel

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.

Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
---
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(-)

diff --git a/drivers/iommu/riscv/iommu-pci.c b/drivers/iommu/riscv/iommu-pci.c
index d82d2b00904c..8abf52dfb4c9 100644
--- a/drivers/iommu/riscv/iommu-pci.c
+++ b/drivers/iommu/riscv/iommu-pci.c
@@ -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
-- 
2.47.3


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array
  2026-05-22 14:59 [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array Uwe Kleine-König (The Capable Hub)
@ 2026-07-07  9:07 ` Uwe Kleine-König (The Capable Hub)
  2026-07-07 13:26 ` Robin Murphy
  2026-07-09  8:10 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König (The Capable Hub) @ 2026-07-07  9:07 UTC (permalink / raw)
  To: Tomasz Jeznach, Joerg Roedel, Will Deacon
  Cc: Robin Murphy, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, iommu, linux-riscv, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 651 bytes --]

Hello,

On Fri, May 22, 2026 at 04:59:43PM +0200, Uwe Kleine-König (The Capable Hub) 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.
> 
> Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>

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

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array
  2026-05-22 14:59 [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array Uwe Kleine-König (The Capable Hub)
  2026-07-07  9:07 ` Uwe Kleine-König (The Capable Hub)
@ 2026-07-07 13:26 ` Robin Murphy
  2026-07-09  8:10 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Robin Murphy @ 2026-07-07 13:26 UTC (permalink / raw)
  To: Uwe Kleine-König (The Capable Hub), Tomasz Jeznach,
	Joerg Roedel, Will Deacon
  Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti, iommu,
	linux-riscv, linux-kernel

On 22/05/2026 3:59 pm, Uwe Kleine-König (The Capable Hub) 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.

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

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
> ---
> 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(-)
> 
> diff --git a/drivers/iommu/riscv/iommu-pci.c b/drivers/iommu/riscv/iommu-pci.c
> index d82d2b00904c..8abf52dfb4c9 100644
> --- a/drivers/iommu/riscv/iommu-pci.c
> +++ b/drivers/iommu/riscv/iommu-pci.c
> @@ -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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array
  2026-05-22 14:59 [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array Uwe Kleine-König (The Capable Hub)
  2026-07-07  9:07 ` Uwe Kleine-König (The Capable Hub)
  2026-07-07 13:26 ` Robin Murphy
@ 2026-07-09  8:10 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2026-07-09  8:10 UTC (permalink / raw)
  To: Uwe Kleine-König (The Capable Hub)
  Cc: Tomasz Jeznach, Will Deacon, Robin Murphy, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Alexandre Ghiti, iommu, linux-riscv,
	linux-kernel

On Fri, May 22, 2026 at 04:59:43PM +0200, Uwe Kleine-König (The Capable Hub) wrote:
>  drivers/iommu/riscv/iommu-pci.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-09  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-22 14:59 [PATCH v1] iommu/riscv: Drop superflous zeros in pci_device_id array Uwe Kleine-König (The Capable Hub)
2026-07-07  9:07 ` Uwe Kleine-König (The Capable Hub)
2026-07-07 13:26 ` Robin Murphy
2026-07-09  8:10 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox