Re: [PATCH RFC] pci: Make return value of pcie_capability_read*() consistent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 4/24/20 12:38 AM, Bjorn Helgaas wrote:
On Thu, Apr 23, 2020 at 07:55:17PM +0800, Yicong Yang wrote:
On 2020/4/19 14:51, Bolarinwa Olayemi Saheed wrote:
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 79c4a2ef269a..451f2b8b2b3c 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -409,7 +409,7 @@ int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
Maybe provide some comments for the function, to notify the outside
users to do the error code conversion.
A short function comment about the set of possible return values
wouldn't hurt.  We don't have those for pci_read_config_word() and
friends, and there are several pcie_capability_*() functions.  I don't
think it's worth repeating the comment for every function, so maybe we
could just extend the existing comment at pcie_capability_read_word().

Is enough to adjust the comment on pcie_capability_read_word() to this:

   /*
     * 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.)
     *
     * On error, this function returns a PCIBIOS_* error code,
     * you may want to use pcibios_err_to_errno()(include/linux/pci.h)
     * to convert to a non-PCI code
     */

BTW, pci_{read, write}_config_*() may also have the issues that
export the private err code outside. You may want to solve these in
a series along with this patch.
If you see a specific issue, please point it out.

I looked at pci_read_config_word(), and it can return
PCIBIOS_DEVICE_NOT_FOUND, PCIBIOS_BAD_REGISTER_NUMBER, or the return
value from bus->ops->read().

I looked at all the users of PCIBIOS_*.  There's really no interesting
use of any of them except by pcibios_err_to_errno() and
xen_pcibios_err_to_errno(), so I'm not sure it's even worth keeping
them.

But I think it's probably more work to excise all of them than it is
to simply make pci_read_config_word() and pcie_capability_read_word()
return the same set of error values.  So I think we should do this
first.

  	*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 +444,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);

Also, can I just send this as a single patch while we conclude on pcie_capability_write*() ?

Thank you.

- Saheed




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux