linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
@ 2024-05-27 13:23 Ilpo Järvinen
  2024-05-27 13:23 ` [PATCH 2/2] gpio: rdc321x: " Ilpo Järvinen
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Ilpo Järvinen @ 2024-05-27 13:23 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Dmitry Baryshkov, linux-gpio,
	linux-kernel
  Cc: Ilpo Järvinen, stable

amd_gpio_init() uses pci_read_config_dword() that returns PCIBIOS_*
codes. The return code is then returned as is but amd_gpio_init() is
a module init function that should return normal errnos.

Convert PCIBIOS_* returns code using pcibios_err_to_errno() into normal
errno before returning it from amd_gpio_init().

Fixes: f942a7de047d ("gpio: add a driver for GPIO pins found on AMD-8111 south bridge chips")
Cc: stable@vger.kernel.org
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/gpio/gpio-amd8111.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
index 6f3ded619c8b..3377667a28de 100644
--- a/drivers/gpio/gpio-amd8111.c
+++ b/drivers/gpio/gpio-amd8111.c
@@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
 
 found:
 	err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
-	if (err)
+	if (err) {
+		err = pcibios_err_to_errno(err);
 		goto out;
+	}
 	err = -EIO;
 	gp.pmbase &= 0x0000FF00;
 	if (gp.pmbase == 0)
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] gpio: rdc321x: Convert PCIBIOS_* return codes to errnos
  2024-05-27 13:23 [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos Ilpo Järvinen
@ 2024-05-27 13:23 ` Ilpo Järvinen
  2024-05-27 14:02 ` [PATCH 1/2] gpio: amd8111: " Dan Carpenter
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Ilpo Järvinen @ 2024-05-27 13:23 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Samuel Ortiz,
	Florian Fainelli, linux-gpio, linux-kernel
  Cc: Ilpo Järvinen, stable

rdc_gpio_config() uses pci_{read,write}_config_dword() that return
PCIBIOS_* codes. rdc_gpio_config() is used for
direction_{input,output}() in the struct gpio_chip which both require
normal errnos to be returned.

Similarly, rdc321x_gpio_probe() that is probe function returns
PCIBIOS_* codes without converting them first into normal errnos.

Convert PCIBIOS_* returns code using pcibios_err_to_errno() into normal
errno before returning them to fix both issues.

Fixes: 9956d02d6e60 ("gpio: Add support for RDC321x GPIO controller")
Cc: stable@vger.kernel.org
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/gpio/gpio-rdc321x.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c
index 01ed2517e9fd..ec7fb9220a47 100644
--- a/drivers/gpio/gpio-rdc321x.c
+++ b/drivers/gpio/gpio-rdc321x.c
@@ -102,7 +102,7 @@ static int rdc_gpio_config(struct gpio_chip *chip,
 unlock:
 	spin_unlock(&gpch->lock);
 
-	return err;
+	return pcibios_err_to_errno(err);
 }
 
 /* configure GPIO pin as input */
@@ -170,13 +170,13 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
 					rdc321x_gpio_dev->reg1_data_base,
 					&rdc321x_gpio_dev->data_reg[0]);
 	if (err)
-		return err;
+		return pcibios_err_to_errno(err);
 
 	err = 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;
+		return pcibios_err_to_errno(err);
 
 	dev_info(&pdev->dev, "registering %d GPIOs\n",
 					rdc321x_gpio_dev->chip.ngpio);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 13:23 [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos Ilpo Järvinen
  2024-05-27 13:23 ` [PATCH 2/2] gpio: rdc321x: " Ilpo Järvinen
@ 2024-05-27 14:02 ` Dan Carpenter
  2024-05-27 14:11   ` Ilpo Järvinen
  2024-05-30  9:30   ` Andy Shevchenko
  2024-05-30  9:21 ` Bartosz Golaszewski
  2024-05-30  9:22 ` Bartosz Golaszewski
  3 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2024-05-27 14:02 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Linus Walleij, Bartosz Golaszewski, Dmitry Baryshkov, linux-gpio,
	linux-kernel, stable

On Mon, May 27, 2024 at 04:23:44PM +0300, Ilpo Järvinen wrote:
> diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> index 6f3ded619c8b..3377667a28de 100644
> --- a/drivers/gpio/gpio-amd8111.c
> +++ b/drivers/gpio/gpio-amd8111.c
> @@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
>  
>  found:
>  	err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> -	if (err)
> +	if (err) {
> +		err = pcibios_err_to_errno(err);

The patch is correct, but is the CC to stable necessary?  Is this a real
concern?

Most callers don't check.  Linus Torvalds, once said something to the
effect that if your PCI bus starts failing, there isn't anything the
operating system can do, so checking is pointless.  The only fix is to
buy new hardware.  There was a hotpluggable PCI back in the day but I
don't think it exists any more.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 14:02 ` [PATCH 1/2] gpio: amd8111: " Dan Carpenter
@ 2024-05-27 14:11   ` Ilpo Järvinen
  2024-05-27 14:26     ` Dan Carpenter
  2024-05-30  9:30   ` Andy Shevchenko
  1 sibling, 1 reply; 9+ messages in thread
From: Ilpo Järvinen @ 2024-05-27 14:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Bartosz Golaszewski, Dmitry Baryshkov, linux-gpio,
	LKML, stable

[-- Attachment #1: Type: text/plain, Size: 1012 bytes --]

On Mon, 27 May 2024, Dan Carpenter wrote:

> On Mon, May 27, 2024 at 04:23:44PM +0300, Ilpo Järvinen wrote:
> > diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> > index 6f3ded619c8b..3377667a28de 100644
> > --- a/drivers/gpio/gpio-amd8111.c
> > +++ b/drivers/gpio/gpio-amd8111.c
> > @@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
> >  
> >  found:
> >  	err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> > -	if (err)
> > +	if (err) {
> > +		err = pcibios_err_to_errno(err);
> 
> The patch is correct, but is the CC to stable necessary?  Is this a real
> concern?
> 
> Most callers don't check.  Linus Torvalds, once said something to the
> effect that if your PCI bus starts failing, there isn't anything the
> operating system can do, so checking is pointless.  The only fix is to
> buy new hardware.  There was a hotpluggable PCI back in the day but I
> don't think it exists any more.

I don't mind if the CC stable isn't there.


-- 
 i.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 14:11   ` Ilpo Järvinen
@ 2024-05-27 14:26     ` Dan Carpenter
  2024-05-27 14:57       ` Ilpo Järvinen
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2024-05-27 14:26 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Linus Walleij, Bartosz Golaszewski, Dmitry Baryshkov, linux-gpio,
	LKML, stable

On Mon, May 27, 2024 at 05:11:32PM +0300, Ilpo Järvinen wrote:
> On Mon, 27 May 2024, Dan Carpenter wrote:
> 
> > On Mon, May 27, 2024 at 04:23:44PM +0300, Ilpo Järvinen wrote:
> > > diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> > > index 6f3ded619c8b..3377667a28de 100644
> > > --- a/drivers/gpio/gpio-amd8111.c
> > > +++ b/drivers/gpio/gpio-amd8111.c
> > > @@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
> > >  
> > >  found:
> > >  	err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> > > -	if (err)
> > > +	if (err) {
> > > +		err = pcibios_err_to_errno(err);
> > 
> > The patch is correct, but is the CC to stable necessary?  Is this a real
> > concern?
> > 
> > Most callers don't check.  Linus Torvalds, once said something to the
> > effect that if your PCI bus starts failing, there isn't anything the
> > operating system can do, so checking is pointless.  The only fix is to
> > buy new hardware.  There was a hotpluggable PCI back in the day but I
> > don't think it exists any more.
> 
> I don't mind if the CC stable isn't there.

I don't mind either way.  I was hoping you were going to say it was for
some new hotswap hardware Intel was working on.

Smatch deletes all the failure paths from the pci_read_ functions
because otherwise you end up with a lot of warnings that no one cares
about.  Uninitialized variables mostly?

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 14:26     ` Dan Carpenter
@ 2024-05-27 14:57       ` Ilpo Järvinen
  0 siblings, 0 replies; 9+ messages in thread
From: Ilpo Järvinen @ 2024-05-27 14:57 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Bartosz Golaszewski, Dmitry Baryshkov, linux-gpio,
	LKML, stable

[-- Attachment #1: Type: text/plain, Size: 2884 bytes --]

On Mon, 27 May 2024, Dan Carpenter wrote:
> On Mon, May 27, 2024 at 05:11:32PM +0300, Ilpo Järvinen wrote:
> > On Mon, 27 May 2024, Dan Carpenter wrote:
> > 
> > > On Mon, May 27, 2024 at 04:23:44PM +0300, Ilpo Järvinen wrote:
> > > > diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> > > > index 6f3ded619c8b..3377667a28de 100644
> > > > --- a/drivers/gpio/gpio-amd8111.c
> > > > +++ b/drivers/gpio/gpio-amd8111.c
> > > > @@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
> > > >  
> > > >  found:
> > > >  	err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> > > > -	if (err)
> > > > +	if (err) {
> > > > +		err = pcibios_err_to_errno(err);
> > > 
> > > The patch is correct, but is the CC to stable necessary?  Is this a real
> > > concern?
> > > 
> > > Most callers don't check.  Linus Torvalds, once said something to the
> > > effect that if your PCI bus starts failing, there isn't anything the
> > > operating system can do, so checking is pointless.  The only fix is to
> > > buy new hardware.  There was a hotpluggable PCI back in the day but I
> > > don't think it exists any more.
> > 
> > I don't mind if the CC stable isn't there.
> 
> I don't mind either way.  I was hoping you were going to say it was for
> some new hotswap hardware Intel was working on.

That's not exactly the correct answer but I'm auditing all these because 
I have a sinister plan to convert the PCI accessors away from returning 
PCIBIOS_* codes and push the conversion down into real PCIBIOS interface 
under arch/x86/pci where they'd be immediately converted into errnos.

As the by-product of the audit, I see all these cases where the return
type is incorrect so I've created a fix for each where the return type 
confusion propagates.

> Smatch deletes all the failure paths from the pci_read_ functions
> because otherwise you end up with a lot of warnings that no one cares
> about.  Uninitialized variables mostly?

Please note that there's a difference between ignoring errors entirely and 
returning wrong value (type) on errors.

At this point, I've already ignored many many cases where the value type 
confusion does not propagate because of my main goal which is anyway to 
eventually get rid of having to deal with PCIBIOS_* codes in any generic 
code.

If a PCIBIOS_* return code somehow leaks into userspace where errno would 
be expected, it could confuse userspace (e.g., one case unrelated to 
module init functions I found is sysfs show function returning positive in 
case of error which has obviously different meaning from the caller's 
point of view).

In case of module init, do_module_init() checks for ret > 0 and prints 
warning + stacktrace, however, it does not attempt to correct the return 
code so I think the positive code still leaks into userspace.

-- 
 i.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 13:23 [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos Ilpo Järvinen
  2024-05-27 13:23 ` [PATCH 2/2] gpio: rdc321x: " Ilpo Järvinen
  2024-05-27 14:02 ` [PATCH 1/2] gpio: amd8111: " Dan Carpenter
@ 2024-05-30  9:21 ` Bartosz Golaszewski
  2024-05-30  9:22 ` Bartosz Golaszewski
  3 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2024-05-30  9:21 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Dmitry Baryshkov, linux-gpio,
	linux-kernel, Ilpo Järvinen
  Cc: Bartosz Golaszewski, stable

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Mon, 27 May 2024 16:23:44 +0300, Ilpo Järvinen wrote:
> amd_gpio_init() uses pci_read_config_dword() that returns PCIBIOS_*
> codes. The return code is then returned as is but amd_gpio_init() is
> a module init function that should return normal errnos.
> 
> Convert PCIBIOS_* returns code using pcibios_err_to_errno() into normal
> errno before returning it from amd_gpio_init().
> 
> [...]

Applied, thanks!

[1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
      commit: d4cde6e42f2eb56436cab6d1931738ec09e64f74
[2/2] gpio: rdc321x: Convert PCIBIOS_* return codes to errnos
      commit: 9a73e037f4b5eb45c9ecccb191d39c280abe7cbd

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 13:23 [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos Ilpo Järvinen
                   ` (2 preceding siblings ...)
  2024-05-30  9:21 ` Bartosz Golaszewski
@ 2024-05-30  9:22 ` Bartosz Golaszewski
  3 siblings, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2024-05-30  9:22 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Linus Walleij, Dmitry Baryshkov, linux-gpio, linux-kernel, stable

On Mon, May 27, 2024 at 3:23 PM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> amd_gpio_init() uses pci_read_config_dword() that returns PCIBIOS_*
> codes. The return code is then returned as is but amd_gpio_init() is
> a module init function that should return normal errnos.
>
> Convert PCIBIOS_* returns code using pcibios_err_to_errno() into normal
> errno before returning it from amd_gpio_init().
>
> Fixes: f942a7de047d ("gpio: add a driver for GPIO pins found on AMD-8111 south bridge chips")
> Cc: stable@vger.kernel.org

I dropped these.

Bart

> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>  drivers/gpio/gpio-amd8111.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> index 6f3ded619c8b..3377667a28de 100644
> --- a/drivers/gpio/gpio-amd8111.c
> +++ b/drivers/gpio/gpio-amd8111.c
> @@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
>
>  found:
>         err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> -       if (err)
> +       if (err) {
> +               err = pcibios_err_to_errno(err);
>                 goto out;
> +       }
>         err = -EIO;
>         gp.pmbase &= 0x0000FF00;
>         if (gp.pmbase == 0)
> --
> 2.39.2
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos
  2024-05-27 14:02 ` [PATCH 1/2] gpio: amd8111: " Dan Carpenter
  2024-05-27 14:11   ` Ilpo Järvinen
@ 2024-05-30  9:30   ` Andy Shevchenko
  1 sibling, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2024-05-30  9:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Ilpo Järvinen, Linus Walleij, Bartosz Golaszewski,
	Dmitry Baryshkov, linux-gpio, linux-kernel, stable

Mon, May 27, 2024 at 05:02:12PM +0300, Dan Carpenter kirjoitti:
> On Mon, May 27, 2024 at 04:23:44PM +0300, Ilpo Järvinen wrote:
> > diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
> > index 6f3ded619c8b..3377667a28de 100644
> > --- a/drivers/gpio/gpio-amd8111.c
> > +++ b/drivers/gpio/gpio-amd8111.c
> > @@ -195,8 +195,10 @@ static int __init amd_gpio_init(void)
> >  
> >  found:
> >  	err = pci_read_config_dword(pdev, 0x58, &gp.pmbase);
> > -	if (err)
> > +	if (err) {
> > +		err = pcibios_err_to_errno(err);
> 
> The patch is correct, but is the CC to stable necessary?  Is this a real
> concern?
> 
> Most callers don't check.  Linus Torvalds, once said something to the
> effect that if your PCI bus starts failing, there isn't anything the
> operating system can do, so checking is pointless.  The only fix is to
> buy new hardware.  There was a hotpluggable PCI back in the day but I
> don't think it exists any more.

Now we have a USB4 that can tunnel PCIe, I'm not sure no generation of it may
not fail with the errors that are listed as positive PCI bus specific codes.

And it's hotpluggable, of course.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-30  9:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27 13:23 [PATCH 1/2] gpio: amd8111: Convert PCIBIOS_* return codes to errnos Ilpo Järvinen
2024-05-27 13:23 ` [PATCH 2/2] gpio: rdc321x: " Ilpo Järvinen
2024-05-27 14:02 ` [PATCH 1/2] gpio: amd8111: " Dan Carpenter
2024-05-27 14:11   ` Ilpo Järvinen
2024-05-27 14:26     ` Dan Carpenter
2024-05-27 14:57       ` Ilpo Järvinen
2024-05-30  9:30   ` Andy Shevchenko
2024-05-30  9:21 ` Bartosz Golaszewski
2024-05-30  9:22 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).