lkml.org 
[lkml]   [2020]   [Jul]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH 11/14 v3] PCI/PM: Check return value of pcie_capability_read_*()
Date
> From: Saheed Olayemi Bolarinwa
> Sent: 10 July 2020 22:20
> To: helgaas@kernel.org
> From: Bolarinwa Olayemi Saheed <refactormyself@gmail.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@helgaas.com>
> Signed-off-by: Bolarinwa Olayemi Saheed <refactormyself@gmail.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)

\
 
 \ /
  Last update: 2020-07-14 10:10    [W:0.058 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site