drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-)
While being more verbose using a named initializer yields easier to
understand code and doesn't rely on the two hidden zeros in the
PCI_VDEVICE macro.
While at it, also drop the explicit zero in the terminating entry.
This doesn't introduce any changes to the compiled result of the array,
which was confirmed on x86 and arm64.
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 (see
https://lore.kernel.org/all/20260507074102.2654314-2-u.kleine-koenig@baylibre.com/
for an example), but inifiniband won't profit as no driver uses a
pointer for driver_data.
Best regards
Uwe
drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 32 ++++++++++++++++------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index fa36700d0db2..cfe5269ba6a8 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -7249,16 +7249,30 @@ static const struct hns_roce_hw hns_roce_hw_v2 = {
};
static const struct pci_device_id hns_roce_hw_v2_pci_tbl[] = {
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_200G_RDMA), 0},
- {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_RDMA_DCB_PFC_VF),
- HNAE3_DEV_SUPPORT_ROCE_DCB_BITS},
+ {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA),
+ .driver_data = 0,
+ }, {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC),
+ .driver_data = 0,
+ }, {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA),
+ .driver_data = 0,
+ }, {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC),
+ .driver_data = 0,
+ }, {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC),
+ .driver_data = 0,
+ }, {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_200G_RDMA),
+ .driver_data = 0,
+ }, {
+ PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_RDMA_DCB_PFC_VF),
+ .driver_data = HNAE3_DEV_SUPPORT_ROCE_DCB_BITS,
+ },
/* required last entry */
- {0, }
+ { }
};
MODULE_DEVICE_TABLE(pci, hns_roce_hw_v2_pci_tbl);
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
--
2.47.3
On Thu, 07 May 2026 09:54:37 +0200, Uwe Kleine-König (The Capable Hub) wrote:
> While being more verbose using a named initializer yields easier to
> understand code and doesn't rely on the two hidden zeros in the
> PCI_VDEVICE macro.
>
> While at it, also drop the explicit zero in the terminating entry.
>
> This doesn't introduce any changes to the compiled result of the array,
> which was confirmed on x86 and arm64.
>
> [...]
Applied, thanks!
[1/1] RDMS/hns: Use named initializer for pci_device_id array
https://git.kernel.org/rdma/rdma/c/9dd3e17173bfb8
Best regards,
--
Leon Romanovsky <leon@kernel.org>
On Wed, May 13, 2026 at 02:51:20PM -0400, Leon Romanovsky wrote: > > On Thu, 07 May 2026 09:54:37 +0200, Uwe Kleine-König (The Capable Hub) wrote: > > While being more verbose using a named initializer yields easier to > > understand code and doesn't rely on the two hidden zeros in the > > PCI_VDEVICE macro. > > > > While at it, also drop the explicit zero in the terminating entry. > > > > This doesn't introduce any changes to the compiled result of the array, > > which was confirmed on x86 and arm64. > > > > [...] > > Applied, thanks! > > [1/1] RDMS/hns: Use named initializer for pci_device_id array > https://git.kernel.org/rdma/rdma/c/9dd3e17173bfb8 Thanks for picking the patch up and also for the typo fix! Best regards Uwe
On 2026/5/7 15:54, Uwe Kleine-König (The Capable Hub) wrote:
> While being more verbose using a named initializer yields easier to
> understand code and doesn't rely on the two hidden zeros in the
> PCI_VDEVICE macro.
>
> While at it, also drop the explicit zero in the terminating entry.
>
> This doesn't introduce any changes to the compiled result of the array,
> which was confirmed on x86 and arm64.
>
> 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 (see
> https://lore.kernel.org/all/20260507074102.2654314-2-u.kleine-koenig@baylibre.com/
> for an example), but inifiniband won't profit as no driver uses a
> pointer for driver_data.
>
> Best regards
> Uwe
There is a small typo in the patch subject, it should be "RDMA/hns".
The patch itself looks good to me.
Reviewed-by: Junxian Huang <huangjunxian6@hisilicon.com>
Thanks,
Junxian
>
> drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 32 ++++++++++++++++------
> 1 file changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> index fa36700d0db2..cfe5269ba6a8 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> @@ -7249,16 +7249,30 @@ static const struct hns_roce_hw hns_roce_hw_v2 = {
> };
>
> static const struct pci_device_id hns_roce_hw_v2_pci_tbl[] = {
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_200G_RDMA), 0},
> - {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_RDMA_DCB_PFC_VF),
> - HNAE3_DEV_SUPPORT_ROCE_DCB_BITS},
> + {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA),
> + .driver_data = 0,
> + }, {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC),
> + .driver_data = 0,
> + }, {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA),
> + .driver_data = 0,
> + }, {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC),
> + .driver_data = 0,
> + }, {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC),
> + .driver_data = 0,
> + }, {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_200G_RDMA),
> + .driver_data = 0,
> + }, {
> + PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_RDMA_DCB_PFC_VF),
> + .driver_data = HNAE3_DEV_SUPPORT_ROCE_DCB_BITS,
> + },
> /* required last entry */
> - {0, }
> + { }
> };
>
> MODULE_DEVICE_TABLE(pci, hns_roce_hw_v2_pci_tbl);
>
> base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
© 2016 - 2026 Red Hat, Inc.