public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mfd: intel-lpss: Fix IRQ check
@ 2023-11-01  6:26 Chen Ni
  2023-11-01  7:03 ` Mika Westerberg
  0 siblings, 1 reply; 8+ messages in thread
From: Chen Ni @ 2023-11-01  6:26 UTC (permalink / raw)
  To: lee, andriy.shevchenko, mika.westerberg; +Cc: linux-kernel, Chen Ni

platform_get_irq() returns a negative error code to indicating an
error. So in intel_lpss_probe() the unset / erroneous IRQ should be
returned as is.

Fixes: 4b45efe85263 ("mfd: Add support for Intel Sunrisepoint LPSS devices")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
Changelog:

v1 -> v2:
1. Update commit message
2. Fix IRQ check in intel_lpcc_probe()
---
 drivers/mfd/intel-lpss.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c
index 9591b354072a..4c9d0222751a 100644
--- a/drivers/mfd/intel-lpss.c
+++ b/drivers/mfd/intel-lpss.c
@@ -378,9 +378,12 @@ int intel_lpss_probe(struct device *dev,
 	struct intel_lpss *lpss;
 	int ret;
 
-	if (!info || !info->mem || info->irq <= 0)
+	if (!info || !info->mem)
 		return -EINVAL;
 
+	if (info->irq < 0)
+		return info->irq;
+
 	lpss = devm_kzalloc(dev, sizeof(*lpss), GFP_KERNEL);
 	if (!lpss)
 		return -ENOMEM;
-- 
2.25.1


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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-01  6:26 [PATCH v2] mfd: intel-lpss: Fix IRQ check Chen Ni
@ 2023-11-01  7:03 ` Mika Westerberg
  2023-11-01  9:38   ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Mika Westerberg @ 2023-11-01  7:03 UTC (permalink / raw)
  To: Chen Ni; +Cc: lee, andriy.shevchenko, linux-kernel

On Wed, Nov 01, 2023 at 06:26:43AM +0000, Chen Ni wrote:
> platform_get_irq() returns a negative error code to indicating an
> error. So in intel_lpss_probe() the unset / erroneous IRQ should be
> returned as is.
> 
> Fixes: 4b45efe85263 ("mfd: Add support for Intel Sunrisepoint LPSS devices")

There is no need for Fixes tag here.

> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
> Changelog:
> 
> v1 -> v2:
> 1. Update commit message
> 2. Fix IRQ check in intel_lpcc_probe()
> ---
>  drivers/mfd/intel-lpss.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c
> index 9591b354072a..4c9d0222751a 100644
> --- a/drivers/mfd/intel-lpss.c
> +++ b/drivers/mfd/intel-lpss.c
> @@ -378,9 +378,12 @@ int intel_lpss_probe(struct device *dev,
>  	struct intel_lpss *lpss;
>  	int ret;
>  
> -	if (!info || !info->mem || info->irq <= 0)
> +	if (!info || !info->mem)

This check (info->irq <= 0) covers both "invalid" interrupt numbers
(that's the negative errno and 0 as no interrupt) so I don't see how
this change makes it any better and the changelog does not clarify it
either.

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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-01  7:03 ` Mika Westerberg
@ 2023-11-01  9:38   ` Andy Shevchenko
  2023-11-01  9:42     ` Andy Shevchenko
  2023-11-01 10:47     ` Mika Westerberg
  0 siblings, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-11-01  9:38 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Chen Ni, lee, linux-kernel

On Wed, Nov 01, 2023 at 09:03:10AM +0200, Mika Westerberg wrote:
> On Wed, Nov 01, 2023 at 06:26:43AM +0000, Chen Ni wrote:
> > platform_get_irq() returns a negative error code to indicating an
> > error. So in intel_lpss_probe() the unset / erroneous IRQ should be
> > returned as is.
> > 
> > Fixes: 4b45efe85263 ("mfd: Add support for Intel Sunrisepoint LPSS devices")

> There is no need for Fixes tag here.

I said that already in v1 :-)

...

> > -	if (!info || !info->mem || info->irq <= 0)
> > +	if (!info || !info->mem)
> 
> This check (info->irq <= 0) covers both "invalid" interrupt numbers
> (that's the negative errno and 0 as no interrupt) so I don't see how
> this change makes it any better and the changelog does not clarify it
> either.

It makes sense. The IRQ here may not be 0. We should actually fix
the PCI code to guarantee that (platform_get_irq() guarantees that
in platform driver).

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-01  9:38   ` Andy Shevchenko
@ 2023-11-01  9:42     ` Andy Shevchenko
  2023-11-01 10:47     ` Mika Westerberg
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-11-01  9:42 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Chen Ni, lee, linux-kernel

On Wed, Nov 01, 2023 at 11:38:28AM +0200, Andy Shevchenko wrote:
> On Wed, Nov 01, 2023 at 09:03:10AM +0200, Mika Westerberg wrote:
> > On Wed, Nov 01, 2023 at 06:26:43AM +0000, Chen Ni wrote:

...

> We should actually fix the PCI code to guarantee that.

(which also barely a fix as PCI IRQ == 0 is quite unusual case IRL)

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-01  9:38   ` Andy Shevchenko
  2023-11-01  9:42     ` Andy Shevchenko
@ 2023-11-01 10:47     ` Mika Westerberg
  2023-11-02 12:38       ` Andy Shevchenko
  1 sibling, 1 reply; 8+ messages in thread
From: Mika Westerberg @ 2023-11-01 10:47 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Chen Ni, lee, linux-kernel

On Wed, Nov 01, 2023 at 11:38:28AM +0200, Andy Shevchenko wrote:
> On Wed, Nov 01, 2023 at 09:03:10AM +0200, Mika Westerberg wrote:
> > On Wed, Nov 01, 2023 at 06:26:43AM +0000, Chen Ni wrote:
> > > platform_get_irq() returns a negative error code to indicating an
> > > error. So in intel_lpss_probe() the unset / erroneous IRQ should be
> > > returned as is.
> > > 
> > > Fixes: 4b45efe85263 ("mfd: Add support for Intel Sunrisepoint LPSS devices")
> 
> > There is no need for Fixes tag here.
> 
> I said that already in v1 :-)
> 
> ...
> 
> > > -	if (!info || !info->mem || info->irq <= 0)
> > > +	if (!info || !info->mem)
> > 
> > This check (info->irq <= 0) covers both "invalid" interrupt numbers
> > (that's the negative errno and 0 as no interrupt) so I don't see how
> > this change makes it any better and the changelog does not clarify it
> > either.
> 
> It makes sense. The IRQ here may not be 0. We should actually fix
> the PCI code to guarantee that (platform_get_irq() guarantees that
> in platform driver).

Yeah but I mean the check above handles any "invalid" interrupt number
just fine regardless. I don't see any point changing that.

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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-01 10:47     ` Mika Westerberg
@ 2023-11-02 12:38       ` Andy Shevchenko
  2023-11-03  6:41         ` Mika Westerberg
  0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2023-11-02 12:38 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Chen Ni, lee, linux-kernel

On Wed, Nov 01, 2023 at 12:47:17PM +0200, Mika Westerberg wrote:
> On Wed, Nov 01, 2023 at 11:38:28AM +0200, Andy Shevchenko wrote:
> > On Wed, Nov 01, 2023 at 09:03:10AM +0200, Mika Westerberg wrote:
> > > On Wed, Nov 01, 2023 at 06:26:43AM +0000, Chen Ni wrote:

...

> > > > -	if (!info || !info->mem || info->irq <= 0)
> > > > +	if (!info || !info->mem)
> > > 
> > > This check (info->irq <= 0) covers both "invalid" interrupt numbers
> > > (that's the negative errno and 0 as no interrupt) so I don't see how
> > > this change makes it any better and the changelog does not clarify it
> > > either.
> > 
> > It makes sense. The IRQ here may not be 0. We should actually fix
> > the PCI code to guarantee that (platform_get_irq() guarantees that
> > in platform driver).
> 
> Yeah but I mean the check above handles any "invalid" interrupt number
> just fine regardless. I don't see any point changing that.

The point is to have proper error code to be returned. Currently it's shadowed
in this check.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-02 12:38       ` Andy Shevchenko
@ 2023-11-03  6:41         ` Mika Westerberg
  2023-11-03 14:58           ` Andy Shevchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Mika Westerberg @ 2023-11-03  6:41 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Chen Ni, lee, linux-kernel

On Thu, Nov 02, 2023 at 02:38:31PM +0200, Andy Shevchenko wrote:
> > > > > -	if (!info || !info->mem || info->irq <= 0)
> > > > > +	if (!info || !info->mem)
> > > > 
> > > > This check (info->irq <= 0) covers both "invalid" interrupt numbers
> > > > (that's the negative errno and 0 as no interrupt) so I don't see how
> > > > this change makes it any better and the changelog does not clarify it
> > > > either.
> > > 
> > > It makes sense. The IRQ here may not be 0. We should actually fix
> > > the PCI code to guarantee that (platform_get_irq() guarantees that
> > > in platform driver).
> > 
> > Yeah but I mean the check above handles any "invalid" interrupt number
> > just fine regardless. I don't see any point changing that.
> 
> The point is to have proper error code to be returned. Currently it's shadowed
> in this check.

Looking at this more, this patch actually introduces a bug.

We pass pci_dev->irq from intel-lpss-pci.c and that comes directly from
PCI core that assigns it in pci_read_irq(). This value is unsigned int
for starters so it is not designed to contain an error code, secondly it
can be 0 meaning "no IRQ" either if is SRIOV device or the interrupt
line is not assigned. I actually think SRIOV is a possibility for future
LPSS devices so we should be dealing with this properly.

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

* Re: [PATCH v2] mfd: intel-lpss: Fix IRQ check
  2023-11-03  6:41         ` Mika Westerberg
@ 2023-11-03 14:58           ` Andy Shevchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2023-11-03 14:58 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Chen Ni, lee, linux-kernel

On Fri, Nov 03, 2023 at 08:41:40AM +0200, Mika Westerberg wrote:
> On Thu, Nov 02, 2023 at 02:38:31PM +0200, Andy Shevchenko wrote:
> > > > > > -	if (!info || !info->mem || info->irq <= 0)
> > > > > > +	if (!info || !info->mem)
> > > > > 
> > > > > This check (info->irq <= 0) covers both "invalid" interrupt numbers
> > > > > (that's the negative errno and 0 as no interrupt) so I don't see how
> > > > > this change makes it any better and the changelog does not clarify it
> > > > > either.
> > > > 
> > > > It makes sense. The IRQ here may not be 0. We should actually fix
> > > > the PCI code to guarantee that (platform_get_irq() guarantees that
> > > > in platform driver).
> > > 
> > > Yeah but I mean the check above handles any "invalid" interrupt number
> > > just fine regardless. I don't see any point changing that.
> > 
> > The point is to have proper error code to be returned. Currently it's shadowed
> > in this check.
> 
> Looking at this more, this patch actually introduces a bug.
> 
> We pass pci_dev->irq from intel-lpss-pci.c and that comes directly from
> PCI core that assigns it in pci_read_irq(). This value is unsigned int
> for starters so it is not designed to contain an error code, secondly it
> can be 0 meaning "no IRQ" either if is SRIOV device or the interrupt
> line is not assigned. I actually think SRIOV is a possibility for future
> LPSS devices so we should be dealing with this properly.

I could argue that this patch _reveals_ the bug in PCI that needs to be
addressed.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-11-03 14:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-01  6:26 [PATCH v2] mfd: intel-lpss: Fix IRQ check Chen Ni
2023-11-01  7:03 ` Mika Westerberg
2023-11-01  9:38   ` Andy Shevchenko
2023-11-01  9:42     ` Andy Shevchenko
2023-11-01 10:47     ` Mika Westerberg
2023-11-02 12:38       ` Andy Shevchenko
2023-11-03  6:41         ` Mika Westerberg
2023-11-03 14:58           ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox