All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	"Saheed O. Bolarinwa" <refactormyself@gmail.com>,
	bjorn@helgaas.com, Shuah Khan <skhan@linuxfoundation.org>,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-pci@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	linux-gpio <linux-gpio@vger.kernel.org>
Subject: Re: [RFC PATCH 08/17] gpio: Drop uses of pci_read_config_*() return value
Date: Tue, 18 Aug 2020 21:59:50 +0200	[thread overview]
Message-ID: <CAMpxmJX8SV6RTgy4vKNRPzKvnVaJZpZKQmOf1pX1wGd+H2zaeA@mail.gmail.com> (raw)
In-Reply-To: <20200801112446.149549-9-refactormyself@gmail.com>

On Sat, Aug 1, 2020 at 2:24 PM Saheed O. Bolarinwa
<refactormyself@gmail.com> wrote:
>
> The return value of pci_read_config_*() may not indicate a device error.
> However, the value read by these functions is more likely to indicate
> this kind of error. This presents two overlapping ways of reporting
> errors and complicates error checking.
>
> It is possible to move to one single way of checking for error if the
> dependency on the return value of these functions is removed, then it
> can later be made to return void.
>
> Remove all uses of the return value of pci_read_config_*().
> Check the actual value read for ~0. In this case, ~0 is an invalid
> value thus it indicates some kind of error.
>
> Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
> Signed-off-by: Saheed O. Bolarinwa <refactormyself@gmail.com>
> ---
>  drivers/gpio/gpio-amd8111.c |  7 +++++--
>  drivers/gpio/gpio-rdc321x.c | 21 ++++++++++++---------
>  2 files changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> index fdcebe59510d..7b9882380cbc 100644
> --- a/drivers/gpio/gpio-amd8111.c
> +++ b/drivers/gpio/gpio-amd8111.c
> @@ -198,9 +198,12 @@ static int __init amd_gpio_init(void)
>         goto out;
>
>  found:
> -       err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> -       if (err)
> +       pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> +       if (gp.pmbase == (u32)~0) {
> +               err = -ENODEV;
>                 goto out;
> +       }
> +
>         err = -EIO;
>         gp.pmbase &= 0x0000FF00;
>         if (gp.pmbase == 0)
> diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c
> index 01ed2517e9fd..03f1ff07b844 100644
> --- a/drivers/gpio/gpio-rdc321x.c
> +++ b/drivers/gpio/gpio-rdc321x.c
> @@ -85,10 +85,13 @@ static int rdc_gpio_config(struct gpio_chip *chip,
>         gpch = gpiochip_get_data(chip);
>
>         spin_lock(&gpch->lock);
> -       err = pci_read_config_dword(gpch->sb_pdev, gpio < 32 ?
> -                       gpch->reg1_ctrl_base : gpch->reg2_ctrl_base, &reg);
> -       if (err)
> +       pci_read_config_dword(gpch->sb_pdev,
> +                               (gpio < 32) ? gpch->reg1_ctrl_base
> +                                       : gpch->reg2_ctrl_base, &reg);
> +       if (reg == (u32)~0) {
> +               err = -ENODEV;
>                 goto unlock;
> +       }
>
>         reg |= 1 << (gpio & 0x1f);
>
> @@ -166,17 +169,17 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
>         /* This might not be, what others (BIOS, bootloader, etc.)
>            wrote to these registers before, but it's a good guess. Still
>            better than just using 0xffffffff. */
> -       err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
> +       pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
>                                         rdc321x_gpio_dev->reg1_data_base,
>                                         &rdc321x_gpio_dev->data_reg[0]);
> -       if (err)
> -               return err;
> +       if (rdc321x_gpio_dev->data_reg[0] == (u32)~0)
> +               return -ENODEV;
>
> -       err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
> +       pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
>                                         rdc321x_gpio_dev->reg2_data_base,
>                                         &rdc321x_gpio_dev->data_reg[1]);
> -       if (err)
> -               return err;
> +       if (rdc321x_gpio_dev->data_reg[1] == (u32)~0)
> +               return -ENODEV;
>
>         dev_info(&pdev->dev, "registering %d GPIOs\n",
>                                         rdc321x_gpio_dev->chip.ngpio);
> --
> 2.18.4
>

Bjorn,

I don't know the pci sub-system at all. Does this look good to you?

Bartosz

WARNING: multiple messages have this Message-ID (diff)
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: "Saheed O. Bolarinwa" <refactormyself@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-gpio <linux-gpio@vger.kernel.org>,
	linux-pci@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [Linux-kernel-mentees] [RFC PATCH 08/17] gpio: Drop uses of pci_read_config_*() return value
Date: Tue, 18 Aug 2020 21:59:50 +0200	[thread overview]
Message-ID: <CAMpxmJX8SV6RTgy4vKNRPzKvnVaJZpZKQmOf1pX1wGd+H2zaeA@mail.gmail.com> (raw)
In-Reply-To: <20200801112446.149549-9-refactormyself@gmail.com>

On Sat, Aug 1, 2020 at 2:24 PM Saheed O. Bolarinwa
<refactormyself@gmail.com> wrote:
>
> The return value of pci_read_config_*() may not indicate a device error.
> However, the value read by these functions is more likely to indicate
> this kind of error. This presents two overlapping ways of reporting
> errors and complicates error checking.
>
> It is possible to move to one single way of checking for error if the
> dependency on the return value of these functions is removed, then it
> can later be made to return void.
>
> Remove all uses of the return value of pci_read_config_*().
> Check the actual value read for ~0. In this case, ~0 is an invalid
> value thus it indicates some kind of error.
>
> Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
> Signed-off-by: Saheed O. Bolarinwa <refactormyself@gmail.com>
> ---
>  drivers/gpio/gpio-amd8111.c |  7 +++++--
>  drivers/gpio/gpio-rdc321x.c | 21 ++++++++++++---------
>  2 files changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> index fdcebe59510d..7b9882380cbc 100644
> --- a/drivers/gpio/gpio-amd8111.c
> +++ b/drivers/gpio/gpio-amd8111.c
> @@ -198,9 +198,12 @@ static int __init amd_gpio_init(void)
>         goto out;
>
>  found:
> -       err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> -       if (err)
> +       pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> +       if (gp.pmbase == (u32)~0) {
> +               err = -ENODEV;
>                 goto out;
> +       }
> +
>         err = -EIO;
>         gp.pmbase &= 0x0000FF00;
>         if (gp.pmbase == 0)
> diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c
> index 01ed2517e9fd..03f1ff07b844 100644
> --- a/drivers/gpio/gpio-rdc321x.c
> +++ b/drivers/gpio/gpio-rdc321x.c
> @@ -85,10 +85,13 @@ static int rdc_gpio_config(struct gpio_chip *chip,
>         gpch = gpiochip_get_data(chip);
>
>         spin_lock(&gpch->lock);
> -       err = pci_read_config_dword(gpch->sb_pdev, gpio < 32 ?
> -                       gpch->reg1_ctrl_base : gpch->reg2_ctrl_base, &reg);
> -       if (err)
> +       pci_read_config_dword(gpch->sb_pdev,
> +                               (gpio < 32) ? gpch->reg1_ctrl_base
> +                                       : gpch->reg2_ctrl_base, &reg);
> +       if (reg == (u32)~0) {
> +               err = -ENODEV;
>                 goto unlock;
> +       }
>
>         reg |= 1 << (gpio & 0x1f);
>
> @@ -166,17 +169,17 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
>         /* This might not be, what others (BIOS, bootloader, etc.)
>            wrote to these registers before, but it's a good guess. Still
>            better than just using 0xffffffff. */
> -       err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
> +       pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
>                                         rdc321x_gpio_dev->reg1_data_base,
>                                         &rdc321x_gpio_dev->data_reg[0]);
> -       if (err)
> -               return err;
> +       if (rdc321x_gpio_dev->data_reg[0] == (u32)~0)
> +               return -ENODEV;
>
> -       err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
> +       pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
>                                         rdc321x_gpio_dev->reg2_data_base,
>                                         &rdc321x_gpio_dev->data_reg[1]);
> -       if (err)
> -               return err;
> +       if (rdc321x_gpio_dev->data_reg[1] == (u32)~0)
> +               return -ENODEV;
>
>         dev_info(&pdev->dev, "registering %d GPIOs\n",
>                                         rdc321x_gpio_dev->chip.ngpio);
> --
> 2.18.4
>

Bjorn,

I don't know the pci sub-system at all. Does this look good to you?

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

  reply	other threads:[~2020-08-18 20:00 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01 11:24 [RFC PATCH 00/17] Drop uses of pci_read_config_*() return value Saheed O. Bolarinwa
2020-08-01 11:24 ` [Intel-gfx] " Saheed O. Bolarinwa
2020-08-01 11:24 ` Saheed O. Bolarinwa
2020-08-01 11:24 ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` Saheed O. Bolarinwa
2020-08-01 11:24 ` Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 01/17] ata: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 02/17] atm: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-05 10:51   ` kernel test robot
2020-08-01 11:24 ` [RFC PATCH 03/17] bcma: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 04/17] hwrng: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 05/17] dmaengine: ioat: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 06/17] edac: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 21:38   ` kernel test robot
2020-08-01 11:24 ` [RFC PATCH 07/17] fpga: altera-cvp: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 22:32   ` kernel test robot
2020-08-05 12:31   ` kernel test robot
2020-08-01 11:24 ` [RFC PATCH 08/17] gpio: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-18 19:59   ` Bartosz Golaszewski [this message]
2020-08-18 19:59     ` Bartosz Golaszewski
2020-08-19  2:21     ` Bjorn Helgaas
2020-08-19  2:21       ` [Linux-kernel-mentees] " Bjorn Helgaas
2020-08-01 11:24 ` [RFC PATCH 09/17] drm/i915/vga: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Intel-gfx] " Saheed O. Bolarinwa
2020-08-01 11:24   ` Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 10/17] hwmon: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-04 21:26   ` Guenter Roeck
2020-08-04 21:26     ` [Linux-kernel-mentees] " Guenter Roeck
2020-08-01 11:24 ` [RFC PATCH 11/17] intel_th: pci: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 12/17] i2c: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 13/17] ide: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 14/17] IB: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 14:18   ` kernel test robot
2020-08-01 11:24 ` [RFC PATCH 15/17] iommu/vt-d: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24   ` Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 16/17] mtd: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 11:24   ` Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 17/17] net: " Saheed O. Bolarinwa
2020-08-01 11:24   ` [Linux-kernel-mentees] " Saheed O. Bolarinwa
2020-08-01 14:58   ` kernel test robot
2020-08-01 12:56 ` [RFC PATCH 00/17] " Borislav Petkov
2020-08-01 12:56   ` [Intel-gfx] " Borislav Petkov
2020-08-01 12:56   ` Borislav Petkov
2020-08-01 12:56   ` [Linux-kernel-mentees] " Borislav Petkov
2020-08-01 12:56   ` Borislav Petkov
2020-08-01 12:56   ` Borislav Petkov
2020-08-02 14:53   ` Tom Rix
2020-08-02 14:53     ` [Intel-gfx] " Tom Rix
2020-08-02 14:53     ` Tom Rix
2020-08-02 14:53     ` [Linux-kernel-mentees] " Tom Rix
2020-08-02 14:53     ` Tom Rix
2020-08-02 14:53     ` Tom Rix
2020-08-02 17:28   ` Saheed Bolarinwa
2020-08-02 17:28     ` [Intel-gfx] " Saheed Bolarinwa
2020-08-02 17:28     ` Saheed Bolarinwa
2020-08-02 17:28     ` [Linux-kernel-mentees] " Saheed Bolarinwa
2020-08-02 17:28     ` Saheed Bolarinwa
2020-08-02 17:28     ` Saheed Bolarinwa
2020-08-02 18:46     ` Borislav Petkov
2020-08-02 18:46       ` [Intel-gfx] " Borislav Petkov
2020-08-02 18:46       ` Borislav Petkov
2020-08-02 18:46       ` [Linux-kernel-mentees] " Borislav Petkov
2020-08-02 18:46       ` Borislav Petkov
2020-08-02 18:46       ` Borislav Petkov
2020-08-02 19:14       ` Bjorn Helgaas
2020-08-02 19:14         ` [Intel-gfx] " Bjorn Helgaas
2020-08-02 19:14         ` Bjorn Helgaas
2020-08-02 19:14         ` [Linux-kernel-mentees] " Bjorn Helgaas
2020-08-02 19:14         ` Bjorn Helgaas
2020-08-02 19:14         ` Bjorn Helgaas
2020-08-02 20:18         ` Borislav Petkov
2020-08-02 20:18           ` [Intel-gfx] " Borislav Petkov
2020-08-02 20:18           ` Borislav Petkov
2020-08-02 20:18           ` [Linux-kernel-mentees] " Borislav Petkov
2020-08-02 20:18           ` Borislav Petkov
2020-08-02 20:18           ` Borislav Petkov
2020-08-03  6:56         ` Christoph Hellwig
2020-08-03  6:56           ` [Intel-gfx] " Christoph Hellwig
2020-08-03  6:56           ` [Linux-kernel-mentees] " Christoph Hellwig
2020-08-03  6:56           ` Christoph Hellwig
2020-08-03  6:56           ` Christoph Hellwig

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=CAMpxmJX8SV6RTgy4vKNRPzKvnVaJZpZKQmOf1pX1wGd+H2zaeA@mail.gmail.com \
    --to=bgolaszewski@baylibre.com \
    --cc=bjorn@helgaas.com \
    --cc=helgaas@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.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.