[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <80c7a253134b43289ba28a320ba99f9c@AcuMS.aculab.com>
Date: Tue, 14 Jul 2020 08:10:00 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Saheed Olayemi Bolarinwa' <refactormyself@...il.com>,
"helgaas@...nel.org" <helgaas@...nel.org>
CC: "bjorn@...gaas.com" <bjorn@...gaas.com>,
"skhan@...uxfoundation.org" <skhan@...uxfoundation.org>,
"linux-pci@...r.kernel.org" <linux-pci@...r.kernel.org>,
"linux-kernel-mentees@...ts.linuxfoundation.org"
<linux-kernel-mentees@...ts.linuxfoundation.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH 11/14 v3] PCI/PM: Check return value of
pcie_capability_read_*()
> From: Saheed Olayemi Bolarinwa
> Sent: 10 July 2020 22:20
> To: helgaas@...nel.org
> From: Bolarinwa Olayemi Saheed <refactormyself@...il.com>
>
> 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 <bjorn@...gaas.com>
> Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@...il.com>
> ---
> 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)
Powered by blists - more mailing lists