From: refactormyself@gmail.com
To: helgaas@kernel.org
Cc: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>,
bjorn@helgaas.com, yangyicong@hisilicon.com,
skhan@linuxfoundation.org, linux-pci@vger.kernel.org
Subject: [PATCH RFC 1/2] pci: Make return value of pcie_capability_*() consistent
Date: Mon, 4 May 2020 07:18:11 +0200 [thread overview]
Message-ID: <20200504051812.22662-2-refactormyself@gmail.com> (raw)
In-Reply-To: <20200504051812.22662-1-refactormyself@gmail.com>
From: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
pcie_capability_{read|write}_*() could return 0, -EINVAL, or any of the
PCIBIOS_* error codes. This is behaviour is now changed to ONLY return a
PCIBIOS_* error code or -ERANGE on error.
This has now been made consistent across all accessors. Callers now have
a consistent way for checking which error has occurred.
An audit of the callers of these functions was made and no contradicting
case was found in the examined call chains.
Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.com>
Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
---
drivers/pci/access.c | 64 +++++++++++++++++++++++++++++++++++---------
1 file changed, 51 insertions(+), 13 deletions(-)
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 79c4a2ef269a..10c771079e35 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -402,6 +402,8 @@ static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos)
* Note that these accessor functions are only for the "PCI Express
* Capability" (see PCIe spec r3.0, sec 7.8). They do not apply to the
* other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.)
+ *
+ * Return 0 on success, otherwise a negative value
*/
int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
{
@@ -409,7 +411,7 @@ int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
*val = 0;
if (pos & 1)
- return -EINVAL;
+ return PCIBIOS_BAD_REGISTER_NUMBER;
if (pcie_capability_reg_implemented(dev, pos)) {
ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val);
@@ -444,7 +446,7 @@ int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val)
*val = 0;
if (pos & 3)
- return -EINVAL;
+ return PCIBIOS_BAD_REGISTER_NUMBER;
if (pcie_capability_reg_implemented(dev, pos)) {
ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val);
@@ -453,9 +455,9 @@ int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val)
* have been written as 0xFFFFFFFF if hardware error happens
* during pci_read_config_dword().
*/
- if (ret)
- *val = 0;
- return ret;
+ if (ret)
+ *val = 0;
+ return ret;
}
if (pci_is_pcie(dev) && pcie_downstream_port(dev) &&
@@ -469,7 +471,7 @@ EXPORT_SYMBOL(pcie_capability_read_dword);
int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val)
{
if (pos & 1)
- return -EINVAL;
+ return PCIBIOS_BAD_REGISTER_NUMBER;
if (!pcie_capability_reg_implemented(dev, pos))
return 0;
@@ -481,7 +483,7 @@ EXPORT_SYMBOL(pcie_capability_write_word);
int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val)
{
if (pos & 3)
- return -EINVAL;
+ return PCIBIOS_BAD_REGISTER_NUMBER;
if (!pcie_capability_reg_implemented(dev, pos))
return 0;
@@ -526,56 +528,92 @@ EXPORT_SYMBOL(pcie_capability_clear_and_set_dword);
int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val)
{
+ int ret;
if (pci_dev_is_disconnected(dev)) {
*val = ~0;
return PCIBIOS_DEVICE_NOT_FOUND;
}
- return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val);
+
+ ret = pci_bus_read_config_byte(dev->bus, dev->devfn, where, val);
+
+ if (ret > 0)
+ ret = -ERANGE;
+ return ret;
}
EXPORT_SYMBOL(pci_read_config_byte);
int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val)
{
+ int ret;
if (pci_dev_is_disconnected(dev)) {
*val = ~0;
return PCIBIOS_DEVICE_NOT_FOUND;
}
- return pci_bus_read_config_word(dev->bus, dev->devfn, where, val);
+
+ ret = pci_bus_read_config_word(dev->bus, dev->devfn, where, val);
+
+ if (ret > 0)
+ ret = -ERANGE;
+ return ret;
}
EXPORT_SYMBOL(pci_read_config_word);
int pci_read_config_dword(const struct pci_dev *dev, int where,
u32 *val)
{
+ int ret;
if (pci_dev_is_disconnected(dev)) {
*val = ~0;
return PCIBIOS_DEVICE_NOT_FOUND;
}
- return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
+
+ ret = pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
+
+ if (ret > 0)
+ ret = -ERANGE;
+ return ret;
}
EXPORT_SYMBOL(pci_read_config_dword);
int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val)
{
+ int ret;
if (pci_dev_is_disconnected(dev))
return PCIBIOS_DEVICE_NOT_FOUND;
- return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val);
+
+ ret = pci_bus_write_config_byte(dev->bus, dev->devfn, where, val);
+
+ if (ret > 0)
+ ret = -ERANGE;
+ return ret;
}
EXPORT_SYMBOL(pci_write_config_byte);
int pci_write_config_word(const struct pci_dev *dev, int where, u16 val)
{
+ int ret;
if (pci_dev_is_disconnected(dev))
return PCIBIOS_DEVICE_NOT_FOUND;
- return pci_bus_write_config_word(dev->bus, dev->devfn, where, val);
+
+ ret = pci_bus_write_config_word(dev->bus, dev->devfn, where, val);
+
+ if (ret > 0)
+ ret = -ERANGE;
+ return ret;
}
EXPORT_SYMBOL(pci_write_config_word);
int pci_write_config_dword(const struct pci_dev *dev, int where,
u32 val)
{
+ int ret;
if (pci_dev_is_disconnected(dev))
return PCIBIOS_DEVICE_NOT_FOUND;
- return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
+
+ ret = pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
+
+ if (ret > 0)
+ ret = -ERANGE;
+ return ret;
}
EXPORT_SYMBOL(pci_write_config_dword);
--
2.18.2
next prev parent reply other threads:[~2020-05-04 6:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 5:18 [PATCH RFC 0/2] pci: Make return value of pcie_capability_*() consistent refactormyself
2020-05-04 5:18 ` refactormyself [this message]
2020-05-05 0:06 ` [PATCH RFC 1/2] " Bjorn Helgaas
2020-05-04 5:18 ` [PATCH RFC 2/2] pci: Set all PCIBIOS_* error codes to generic error codes refactormyself
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200504051812.22662-2-refactormyself@gmail.com \
--to=refactormyself@gmail.com \
--cc=bjorn@helgaas.com \
--cc=helgaas@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=yangyicong@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox