summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2020-01-18 18:23:22 +0000
committerNico Huber <nico.h@gmx.de>2020-01-19 23:48:48 +0000
commit67710afe4e34f63a6e7b28d5493753caa8e79a52 (patch)
tree0edfe8de4e07350a7e89115d1532a24f130f6072
parent370a9f3eea20a575f32ebf6ecead7ccf7562a2c0 (diff)
downloadflashrom-67710afe4e34f63a6e7b28d5493753caa8e79a52.tar.gz
flashrom-67710afe4e34f63a6e7b28d5493753caa8e79a52.tar.bz2
flashrom-67710afe4e34f63a6e7b28d5493753caa8e79a52.zip
Revert "pcidev.c: Factor out pcidev_validate() into pure fn"
This reverts commit e28d75ed7204d7fac2c0fac13978098530b0574e. This is broken in multiple ways, e.g. pcidev_init() can only return NULL. Change-Id: I06242147ba9d3a062d442f645eb0800ef51af19f Signed-off-by: Nico Huber <nico.h@gmx.de> Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Reported-by: Michael Bishop <cleverca22@gmail.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/38319 Reviewed-by: Angel Pons <th3fanbus@gmail.com>
-rw-r--r--pcidev.c53
1 files changed, 24 insertions, 29 deletions
diff --git a/pcidev.c b/pcidev.c
index 401284094..54c1fd34c 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -148,33 +148,6 @@ uintptr_t pcidev_readbar(struct pci_dev *dev, int bar)
return (uintptr_t)addr;
}
-static uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs)
-{
- unsigned i;
-
- /* Check against list of supported devices. */
- for (i = 0; devs[i].device_name != NULL; i++) {
- if (dev->device_id != devs[i].device_id)
- continue;
-
- msg_pinfo("Found \"%s %s\" (%04x:%04x, BDF %02x:%02x.%x).\n",
- devs[i].vendor_name, devs[i].device_name,
- dev->vendor_id, dev->device_id, dev->bus, dev->dev,
- dev->func);
-
- if (devs[i].status == NT)
- msg_pinfo("===\nThis PCI device is UNTESTED. Please report the 'flashrom -p "
- "xxxx' output\n"
- "to flashrom@flashrom.org if it works for you. Please add the name "
- "of your\n"
- "PCI device to the subject. Thank you for your help!\n===\n");
-
-
- return pcidev_readbar(dev, bar);
- }
- return 0;
-}
-
static int pcidev_shutdown(void *data)
{
if (pacc == NULL) {
@@ -210,10 +183,12 @@ int pci_init_common(void)
struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar)
{
struct pci_dev *dev;
+ struct pci_dev *found_dev = NULL;
struct pci_filter filter;
char *pcidev_bdf;
char *msg = NULL;
int found = 0;
+ int i;
uintptr_t addr = 0;
if (pci_init_common() != 0)
@@ -232,10 +207,30 @@ struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar)
for (dev = pacc->devices; dev; dev = dev->next) {
if (pci_filter_match(&filter, dev)) {
+ /* Check against list of supported devices. */
+ for (i = 0; devs[i].device_name != NULL; i++)
+ if ((dev->vendor_id == devs[i].vendor_id) &&
+ (dev->device_id == devs[i].device_id))
+ break;
+ /* Not supported, try the next one. */
+ if (devs[i].device_name == NULL)
+ continue;
+
+ msg_pdbg("Found \"%s %s\" (%04x:%04x, BDF %02x:%02x.%x).\n", devs[i].vendor_name,
+ devs[i].device_name, dev->vendor_id, dev->device_id, dev->bus, dev->dev,
+ dev->func);
+ if (devs[i].status == NT)
+ msg_pinfo("===\nThis PCI device is UNTESTED. Please report the 'flashrom -p "
+ "xxxx' output\n"
+ "to flashrom@flashrom.org if it works for you. Please add the name "
+ "of your\n"
+ "PCI device to the subject. Thank you for your help!\n===\n");
+
/* FIXME: We should count all matching devices, not
* just those with a valid BAR.
*/
- if ((addr = pcidev_validate(dev, bar, devs)) != 0) {
+ if ((addr = pcidev_readbar(dev, bar)) != 0) {
+ found_dev = dev;
found++;
}
}
@@ -251,7 +246,7 @@ struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar)
return NULL;
}
- return dev;
+ return found_dev;
}
enum pci_write_type {