Decouple BAR reading from pci device init, handle errors gracefully
Pcidev_init() now returns struct pci_device * instead of a BAR stored in
PCI config space. This allows for real error checking instead of having
exit(1) everywhere in pcidev.c.
Thanks to Niklas Söderlund for coming up with the original error
handling patch which was slightly modified and folded into this patch.
Move the declaration of struct pci_device in programmer.h before the
first user.
Corresponding to flashrom svn r1644.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
diff --git a/nic3com.c b/nic3com.c
index 4ec6193..8d67b54 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -86,13 +86,18 @@
int nic3com_init(void)
{
+ struct pci_dev *dev = NULL;
+
if (rget_io_perms())
return 1;
- /* No need to check for errors, pcidev_init() will not return in case of errors. */
- io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, nics_3com);
+ dev = pcidev_init(nics_3com, PCI_BASE_ADDRESS_0);
+ if (!dev)
+ return 1;
- id = pcidev_dev->device_id;
+ io_base_addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
+
+ id = dev->device_id;
/* 3COM 3C90xB cards need a special fixup. */
if (id == 0x9055 || id == 0x9001 || id == 0x9004 || id == 0x9005