Re: [Linux-kernel-mentees] [PATCH 11/14 v3] PCI/PM: Check return value of pcie_capability_read_*()
From: David Laight <hidden>
Date: 2020-07-14 08:10:07
Also in:
linux-pci, lkml
quoted hunk ↗ jump to hunk
From: Saheed Olayemi Bolarinwa Sent: 10 July 2020 22:20 To: helgaas@kernel.org From: Bolarinwa Olayemi Saheed <redacted> On failure pcie_capability_read_dword() sets it's last parameter, val to 0. However, with Patch 14/14, it is possible that val is set to ~0 on failure. This would introduce a bug because (x & x) == (~0 & x). This bug can be avoided if the return value of pcie_capability_read_dword is checked to confirm success. Check the return value of pcie_capability_read_dword() to ensure success. Suggested-by: Bjorn Helgaas <redacted> Signed-off-by: Bolarinwa Olayemi Saheed <redacted> --- drivers/pci/pci.c | 52 ++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 19 deletions(-)diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ce096272f52b..9f18ffbf7bd4 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c@@ -3207,6 +3207,7 @@ void pci_configure_ari(struct pci_dev *dev) { u32 cap; struct pci_dev *bridge; + int ret; if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) return;@@ -3215,8 +3216,8 @@ void pci_configure_ari(struct pci_dev *dev) if (!bridge) return; - pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap); - if (!(cap & PCI_EXP_DEVCAP2_ARI)) + ret = pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap); + if (ret || !(cap & PCI_EXP_DEVCAP2_ARI)) return;
Why not make the function result 64bit? Then you can return ~0ull on failure and the capability value on success. Gets rid of the horrid error + return value pair. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees