All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Saheed Olayemi Bolarinwa' <refactormyself@gmail.com>,
	"helgaas@kernel.org" <helgaas@kernel.org>
Cc: "bjorn@helgaas.com" <bjorn@helgaas.com>,
	"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel-mentees@lists.linuxfoundation.org" 
	<linux-kernel-mentees@lists.linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 11/14 v3] PCI/PM: Check return value of pcie_capability_read_*()
Date: Tue, 14 Jul 2020 08:10:00 +0000	[thread overview]
Message-ID: <80c7a253134b43289ba28a320ba99f9c@AcuMS.aculab.com> (raw)
In-Reply-To: <20200710212026.27136-12-refactormyself@gmail.com>

> 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)


WARNING: multiple messages have this Message-ID (diff)
From: David Laight <David.Laight@ACULAB.COM>
To: 'Saheed Olayemi Bolarinwa' <refactormyself@gmail.com>,
	"helgaas@kernel.org" <helgaas@kernel.org>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel-mentees@lists.linuxfoundation.org"
	<linux-kernel-mentees@lists.linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [Linux-kernel-mentees] [PATCH 11/14 v3] PCI/PM: Check return value of pcie_capability_read_*()
Date: Tue, 14 Jul 2020 08:10:00 +0000	[thread overview]
Message-ID: <80c7a253134b43289ba28a320ba99f9c@AcuMS.aculab.com> (raw)
In-Reply-To: <20200710212026.27136-12-refactormyself@gmail.com>

> 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)

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2020-07-14  8:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10 21:20 [PATCH 0/14 v3] PCI: Remove '*val = 0' from pcie_capability_read_*() Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 2/14 v3] misc: rtsx: Check the return value of pcie_capability_read_*() Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 5/14 v3] PCI: pciehp: " Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 6/14 v3] PCI: pciehp: Make "Power On" the default Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 7/14 v3] PCI: pciehp: Check the return value of pcie_capability_read_*() Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 9/14 v3] PCI: pciehp: Check " Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 10/14 v3] PCI: " Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 11/14 v3] PCI/PM: " Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-14  8:10   ` David Laight [this message]
2020-07-14  8:10     ` David Laight
2020-07-10 21:20 ` [PATCH 13/14] PCI/ASPM: Check the " Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20 ` [PATCH 14/14 v3] PCI: Remove '*val = 0' from pcie_capability_read_*() Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` [Linux-kernel-mentees] " Saheed Olayemi Bolarinwa
2020-07-10 21:20   ` Saheed Olayemi Bolarinwa
     [not found] ` <20200710212026.27136-5-refactormyself@gmail.com>
2020-07-13 13:44   ` [PATCH 4/14 v3] iwlegacy: Check the return value of pcie_capability_read_*() Kalle Valo
2020-07-13 18:02     ` Saheed Bolarinwa

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=80c7a253134b43289ba28a320ba99f9c@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=bjorn@helgaas.com \
    --cc=helgaas@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=refactormyself@gmail.com \
    --cc=skhan@linuxfoundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.