drivers/mtd/maps/amd76xrom.c | 10 ++++------ drivers/mtd/maps/ck804xrom.c | 2 +- drivers/mtd/maps/esb2rom.c | 20 +++++++------------- drivers/mtd/maps/ichxrom.c | 17 ++++++----------- drivers/mtd/maps/pci.c | 16 +++++----------- drivers/mtd/maps/scb2_flash.c | 9 ++------- drivers/mtd/nand/raw/cafe_nand.c | 3 +-- drivers/mtd/nand/raw/denali_pci.c | 4 ++-- drivers/mtd/nand/raw/r852.c | 4 ++-- 9 files changed, 30 insertions(+), 55 deletions(-)
Initializing a pci_device_id using plain list expressions is hard to
understand for a human who isn't into the Linux PCI subsystem. So for
each initializer use one of the PCI_DEVICE macros for .vendor, .device,
.subvendor and .subdevice and named initializers for the remaining
assignments. This makes it easier to parse and also more robust against
chagnes to the struct definition.
Also drop useless zeros and commas.
The mentioned robustness is relevant for a planned change to struct
pci_device_id that replaces .driver_data by an anonymous union.
This change doesn't introduce changes to the compiled pci_device_id
array. Tested 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 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 pci driver below drivers/mtd using pointers for driver data,
so the example is from a different subsystem.
Best regards
Uwe
drivers/mtd/maps/amd76xrom.c | 10 ++++------
drivers/mtd/maps/ck804xrom.c | 2 +-
drivers/mtd/maps/esb2rom.c | 20 +++++++-------------
drivers/mtd/maps/ichxrom.c | 17 ++++++-----------
drivers/mtd/maps/pci.c | 16 +++++-----------
drivers/mtd/maps/scb2_flash.c | 9 ++-------
drivers/mtd/nand/raw/cafe_nand.c | 3 +--
drivers/mtd/nand/raw/denali_pci.c | 4 ++--
drivers/mtd/nand/raw/r852.c | 4 ++--
9 files changed, 30 insertions(+), 55 deletions(-)
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 95f9b99ce5fc..457e6ab7f3fb 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -296,12 +296,10 @@ static void amd76xrom_remove_one(struct pci_dev *pdev)
}
static const struct pci_device_id amd76xrom_pci_tbl[] = {
- { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7410,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7440,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_AMD, 0x7468 }, /* amd8111 support */
- { 0, }
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7410) },
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7440) },
+ { PCI_DEVICE_SUB(PCI_VENDOR_ID_AMD, 0x7468, 0, 0) }, /* amd8111 support */
+ { }
};
MODULE_DEVICE_TABLE(pci, amd76xrom_pci_tbl);
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 5e44134caa8e..ef4afa8c1931 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -335,7 +335,7 @@ static const struct pci_device_id ck804xrom_pci_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, 0x0365), .driver_data = DEV_MCP55 },
{ PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, 0x0366), .driver_data = DEV_MCP55 },
{ PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, 0x0367), .driver_data = DEV_MCP55 },
- { 0, }
+ { }
};
#if 0
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index fc7f2c3a62b0..043bad544414 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -385,19 +385,13 @@ static void esb2rom_remove_one(struct pci_dev *pdev)
}
static const struct pci_device_id esb2rom_pci_tbl[] = {
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { 0, },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0) },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0) },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0) },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0) },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0) },
+ { },
};
#if 0
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index 6608b782149b..8fecd1820f6e 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -323,17 +323,12 @@ static void ichxrom_remove_one(struct pci_dev *pdev)
}
static const struct pci_device_id ichxrom_pci_tbl[] = {
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
- PCI_ANY_ID, PCI_ANY_ID, },
- { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
- PCI_ANY_ID, PCI_ANY_ID, },
- { 0, },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0), },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0), },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0), },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0), },
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1), },
+ { },
};
#if 0
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index 4a84ca8aed40..34041cc8f173 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -227,22 +227,16 @@ static struct mtd_pci_info intel_dc21285_info = {
static const struct pci_device_id mtd_pci_ids[] = {
{
- .vendor = PCI_VENDOR_ID_INTEL,
- .device = 0x530d,
- .subvendor = PCI_ANY_ID,
- .subdevice = PCI_ANY_ID,
+ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x530d),
.class = PCI_CLASS_MEMORY_OTHER << 8,
.class_mask = 0xffff00,
.driver_data = (unsigned long)&intel_iq80310_info,
- },
- {
- .vendor = PCI_VENDOR_ID_DEC,
- .device = PCI_DEVICE_ID_DEC_21285,
- .subvendor = 0, /* DC21285 defaults to 0 on reset */
- .subdevice = 0, /* DC21285 defaults to 0 on reset */
+ }, {
+ /* DC21285 defaults to 0 for .subvendor and .subdevice on reset */
+ PCI_DEVICE_SUB(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, 0, 0),
.driver_data = (unsigned long)&intel_dc21285_info,
},
- { 0, }
+ { }
};
/*
diff --git a/drivers/mtd/maps/scb2_flash.c b/drivers/mtd/maps/scb2_flash.c
index 57303f904bc1..5c7e1dad101b 100644
--- a/drivers/mtd/maps/scb2_flash.c
+++ b/drivers/mtd/maps/scb2_flash.c
@@ -215,13 +215,8 @@ static void scb2_flash_remove(struct pci_dev *dev)
}
static struct pci_device_id scb2_flash_pci_ids[] = {
- {
- .vendor = PCI_VENDOR_ID_SERVERWORKS,
- .device = PCI_DEVICE_ID_SERVERWORKS_CSB5,
- .subvendor = PCI_ANY_ID,
- .subdevice = PCI_ANY_ID
- },
- { 0, }
+ { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5) },
+ { }
};
static struct pci_driver scb2_flash_driver = {
diff --git a/drivers/mtd/nand/raw/cafe_nand.c b/drivers/mtd/nand/raw/cafe_nand.c
index c4018bc59670..f3117b031cd2 100644
--- a/drivers/mtd/nand/raw/cafe_nand.c
+++ b/drivers/mtd/nand/raw/cafe_nand.c
@@ -830,8 +830,7 @@ static void cafe_nand_remove(struct pci_dev *pdev)
}
static const struct pci_device_id cafe_nand_tbl[] = {
- { PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_88ALP01_NAND,
- PCI_ANY_ID, PCI_ANY_ID },
+ { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_88ALP01_NAND) },
{ }
};
diff --git a/drivers/mtd/nand/raw/denali_pci.c b/drivers/mtd/nand/raw/denali_pci.c
index 97fa32d73441..f53df1b32dda 100644
--- a/drivers/mtd/nand/raw/denali_pci.c
+++ b/drivers/mtd/nand/raw/denali_pci.c
@@ -19,8 +19,8 @@
/* List of platforms this NAND controller has be integrated into */
static const struct pci_device_id denali_pci_ids[] = {
- { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
- { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
+ { PCI_VDEVICE(INTEL, 0x0701), .driver_data = INTEL_CE4100 },
+ { PCI_VDEVICE(INTEL, 0x0809), .driver_data = INTEL_MRST },
{ /* end: all zeroes */ }
};
MODULE_DEVICE_TABLE(pci, denali_pci_ids);
diff --git a/drivers/mtd/nand/raw/r852.c b/drivers/mtd/nand/raw/r852.c
index 8a5572b30893..92c47d351c27 100644
--- a/drivers/mtd/nand/raw/r852.c
+++ b/drivers/mtd/nand/raw/r852.c
@@ -1070,8 +1070,8 @@ static int r852_resume(struct device *device)
static const struct pci_device_id r852_pci_id_tbl[] = {
- { PCI_VDEVICE(RICOH, 0x0852), },
- { },
+ { PCI_VDEVICE(RICOH, 0x0852) },
+ { }
};
MODULE_DEVICE_TABLE(pci, r852_pci_id_tbl);
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
--
2.47.3
© 2016 - 2026 Red Hat, Inc.