Commit 34e32072 authored by Greg Thelen's avatar Greg Thelen Committed by Jesse Barnes

PCI: handle positive error codes

Callers expect pci_user_{read,write}_config_*() to indicate errors by
returning negative values.  Prior to this change, the indicated routines
could return positive error codes (e.g. PCIBIOS_BAD_REGISTER_NUMBER)
which callers would mistakenly interpret as success.

This change converts any non-zero return from the mentioned routines
into unambiguous negative value return codes.
Signed-off-by: default avatarGreg Thelen <gthelen@google.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent d97ecd81
...@@ -143,33 +143,41 @@ static noinline void pci_wait_ucfg(struct pci_dev *dev) ...@@ -143,33 +143,41 @@ static noinline void pci_wait_ucfg(struct pci_dev *dev)
__remove_wait_queue(&pci_ucfg_wait, &wait); __remove_wait_queue(&pci_ucfg_wait, &wait);
} }
/* Returns 0 on success, negative values indicate error. */
#define PCI_USER_READ_CONFIG(size,type) \ #define PCI_USER_READ_CONFIG(size,type) \
int pci_user_read_config_##size \ int pci_user_read_config_##size \
(struct pci_dev *dev, int pos, type *val) \ (struct pci_dev *dev, int pos, type *val) \
{ \ { \
int ret = 0; \ int ret = 0; \
u32 data = -1; \ u32 data = -1; \
if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \ if (PCI_##size##_BAD) \
return -EINVAL; \
raw_spin_lock_irq(&pci_lock); \ raw_spin_lock_irq(&pci_lock); \
if (unlikely(dev->block_ucfg_access)) pci_wait_ucfg(dev); \ if (unlikely(dev->block_ucfg_access)) pci_wait_ucfg(dev); \
ret = dev->bus->ops->read(dev->bus, dev->devfn, \ ret = dev->bus->ops->read(dev->bus, dev->devfn, \
pos, sizeof(type), &data); \ pos, sizeof(type), &data); \
raw_spin_unlock_irq(&pci_lock); \ raw_spin_unlock_irq(&pci_lock); \
*val = (type)data; \ *val = (type)data; \
if (ret > 0) \
ret = -EINVAL; \
return ret; \ return ret; \
} }
/* Returns 0 on success, negative values indicate error. */
#define PCI_USER_WRITE_CONFIG(size,type) \ #define PCI_USER_WRITE_CONFIG(size,type) \
int pci_user_write_config_##size \ int pci_user_write_config_##size \
(struct pci_dev *dev, int pos, type val) \ (struct pci_dev *dev, int pos, type val) \
{ \ { \
int ret = -EIO; \ int ret = -EIO; \
if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \ if (PCI_##size##_BAD) \
return -EINVAL; \
raw_spin_lock_irq(&pci_lock); \ raw_spin_lock_irq(&pci_lock); \
if (unlikely(dev->block_ucfg_access)) pci_wait_ucfg(dev); \ if (unlikely(dev->block_ucfg_access)) pci_wait_ucfg(dev); \
ret = dev->bus->ops->write(dev->bus, dev->devfn, \ ret = dev->bus->ops->write(dev->bus, dev->devfn, \
pos, sizeof(type), val); \ pos, sizeof(type), val); \
raw_spin_unlock_irq(&pci_lock); \ raw_spin_unlock_irq(&pci_lock); \
if (ret > 0) \
ret = -EINVAL; \
return ret; \ return ret; \
} }
...@@ -197,6 +205,8 @@ struct pci_vpd_pci22 { ...@@ -197,6 +205,8 @@ struct pci_vpd_pci22 {
* This code has to spin since there is no other notification from the PCI * This code has to spin since there is no other notification from the PCI
* hardware. Since the VPD is often implemented by serial attachment to an * hardware. Since the VPD is often implemented by serial attachment to an
* EEPROM, it may take many milliseconds to complete. * EEPROM, it may take many milliseconds to complete.
*
* Returns 0 on success, negative values indicate error.
*/ */
static int pci_vpd_pci22_wait(struct pci_dev *dev) static int pci_vpd_pci22_wait(struct pci_dev *dev)
{ {
...@@ -212,7 +222,7 @@ static int pci_vpd_pci22_wait(struct pci_dev *dev) ...@@ -212,7 +222,7 @@ static int pci_vpd_pci22_wait(struct pci_dev *dev)
for (;;) { for (;;) {
ret = pci_user_read_config_word(dev, vpd->cap + PCI_VPD_ADDR, ret = pci_user_read_config_word(dev, vpd->cap + PCI_VPD_ADDR,
&status); &status);
if (ret) if (ret < 0)
return ret; return ret;
if ((status & PCI_VPD_ADDR_F) == vpd->flag) { if ((status & PCI_VPD_ADDR_F) == vpd->flag) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment