Skip to content

Commit d97ffe2

Browse files
Gavin Shanbjorn-helgaas
authored andcommitted
PCI: Fix return value from pci_user_{read,write}_config_*()
The PCI user-space config accessors pci_user_{read,write}_config_*() return negative error numbers, which were introduced by commit 34e3207 ("PCI: handle positive error codes"). That patch converted all positive error numbers from platform-specific PCI config accessors to -EINVAL, which means the callers don't know anything about the specific cause of the failure. The patch fixes the issue by converting the positive PCIBIOS_* error values to generic negative error numbers with pcibios_err_to_errno(). [bhelgaas: changelog] Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Greg Thelen <gthelen@google.com>
1 parent a43ae58 commit d97ffe2

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

‎drivers/pci/access.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static noinline void pci_wait_cfg(struct pci_dev *dev)
148148
int pci_user_read_config_##size \
149149
(struct pci_dev *dev, int pos, type *val) \
150150
{ \
151-
int ret = 0; \
151+
int ret = PCIBIOS_SUCCESSFUL; \
152152
u32 data = -1; \
153153
if (PCI_##size##_BAD) \
154154
return -EINVAL; \
@@ -159,9 +159,7 @@ int pci_user_read_config_##size \
159159
pos, sizeof(type), &data); \
160160
raw_spin_unlock_irq(&pci_lock); \
161161
*val = (type)data; \
162-
if (ret > 0) \
163-
ret = -EINVAL; \
164-
return ret; \
162+
return pcibios_err_to_errno(ret); \
165163
} \
166164
EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
167165

@@ -170,7 +168,7 @@ EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
170168
int pci_user_write_config_##size \
171169
(struct pci_dev *dev, int pos, type val) \
172170
{ \
173-
int ret = -EIO; \
171+
int ret = PCIBIOS_SUCCESSFUL; \
174172
if (PCI_##size##_BAD) \
175173
return -EINVAL; \
176174
raw_spin_lock_irq(&pci_lock); \
@@ -179,9 +177,7 @@ int pci_user_write_config_##size \
179177
ret = dev->bus->ops->write(dev->bus, dev->devfn, \
180178
pos, sizeof(type), val); \
181179
raw_spin_unlock_irq(&pci_lock); \
182-
if (ret > 0) \
183-
ret = -EINVAL; \
184-
return ret; \
180+
return pcibios_err_to_errno(ret); \
185181
} \
186182
EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
187183

‎include/linux/pci.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static inline int pcibios_err_to_errno(int err)
518518
case PCIBIOS_FUNC_NOT_SUPPORTED:
519519
return -ENOENT;
520520
case PCIBIOS_BAD_VENDOR_ID:
521-
return -EINVAL;
521+
return -ENOTTY;
522522
case PCIBIOS_DEVICE_NOT_FOUND:
523523
return -ENODEV;
524524
case PCIBIOS_BAD_REGISTER_NUMBER:
@@ -529,7 +529,7 @@ static inline int pcibios_err_to_errno(int err)
529529
return -ENOSPC;
530530
}
531531

532-
return -ENOTTY;
532+
return -ERANGE;
533533
}
534534

535535
/* Low-level architecture-dependent routines */

0 commit comments

Comments
 (0)