linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: hantro: Fix check for single irq
@ 2021-08-05 19:04 Jernej Skrabec
  2021-08-05 22:03 ` Ezequiel Garcia
  2021-08-09 15:20 ` Emil Velikov
  0 siblings, 2 replies; 6+ messages in thread
From: Jernej Skrabec @ 2021-08-05 19:04 UTC (permalink / raw)
  To: ezequiel, p.zabel
  Cc: mchehab, gregkh, hverkuil-cisco, emil.velikov, linux-media,
	linux-rockchip, linux-staging, linux-kernel, Jernej Skrabec

Some cores use only one interrupt and in such case interrupt name in DT
is not needed. Driver supposedly accounted that, but due to the wrong
field check it never worked. Fix that.

Fixes: 18d6c8b7b4c9 ("media: hantro: add fallback handling for single irq/clk")
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
 drivers/staging/media/hantro/hantro_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 8a2edd67f2c6..20e508158871 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -919,7 +919,7 @@ static int hantro_probe(struct platform_device *pdev)
 		if (!vpu->variant->irqs[i].handler)
 			continue;
 
-		if (vpu->variant->num_clocks > 1) {
+		if (vpu->variant->num_irqs > 1) {
 			irq_name = vpu->variant->irqs[i].name;
 			irq = platform_get_irq_byname(vpu->pdev, irq_name);
 		} else {
-- 
2.32.0


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

* Re: [PATCH] media: hantro: Fix check for single irq
  2021-08-05 19:04 [PATCH] media: hantro: Fix check for single irq Jernej Skrabec
@ 2021-08-05 22:03 ` Ezequiel Garcia
  2021-08-06  4:44   ` Jernej Škrabec
  2021-08-09 15:20 ` Emil Velikov
  1 sibling, 1 reply; 6+ messages in thread
From: Ezequiel Garcia @ 2021-08-05 22:03 UTC (permalink / raw)
  To: Jernej Skrabec, p.zabel
  Cc: mchehab, gregkh, hverkuil-cisco, emil.velikov, linux-media,
	linux-rockchip, linux-staging, linux-kernel

Hi Jernej,

On Thu, 2021-08-05 at 21:04 +0200, Jernej Skrabec wrote:
> Some cores use only one interrupt and in such case interrupt name in DT
> is not needed. Driver supposedly accounted that, but due to the wrong
> field check it never worked. Fix that.
> 
> Fixes: 18d6c8b7b4c9 ("media: hantro: add fallback handling for single irq/clk")
> Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
> ---
>  drivers/staging/media/hantro/hantro_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 8a2edd67f2c6..20e508158871 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -919,7 +919,7 @@ static int hantro_probe(struct platform_device *pdev)
>                 if (!vpu->variant->irqs[i].handler)
>                         continue;
>  
> -               if (vpu->variant->num_clocks > 1) {
> +               if (vpu->variant->num_irqs > 1) {

Oops, thanks for spotting this.
 
How about this instead?

diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 31d8449ca1d2..af7054b04155 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -918,16 +918,15 @@ static int hantro_probe(struct platform_device *pdev)
                if (!vpu->variant->irqs[i].handler)
                        continue;
 
-               if (vpu->variant->num_clocks > 1) {
-                       irq_name = vpu->variant->irqs[i].name;
-                       irq = platform_get_irq_byname(vpu->pdev, irq_name);
-               } else {
+               irq_name = vpu->variant->irqs[i].name;
+               irq = platform_get_irq_byname(vpu->pdev, irq_name);
+               if (irq <= 0) {
                        /*
-                        * If the driver has a single IRQ, chances are there
-                        * will be no actual name in the DT bindings.
+                        * Missing interrupt-names property in device tree,
+                        * looking up interrupts by index.
                         */
                        irq_name = "default";
-                       irq = platform_get_irq(vpu->pdev, 0);
+                       irq = platform_get_irq(vpu->pdev, i);
                }
                if (irq <= 0)
                        return -ENXIO;



-- 
Kindly,
Ezequiel


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

* Re: [PATCH] media: hantro: Fix check for single irq
  2021-08-05 22:03 ` Ezequiel Garcia
@ 2021-08-06  4:44   ` Jernej Škrabec
  2021-08-06 14:13     ` Ezequiel Garcia
  0 siblings, 1 reply; 6+ messages in thread
From: Jernej Škrabec @ 2021-08-06  4:44 UTC (permalink / raw)
  To: p.zabel, Ezequiel Garcia
  Cc: mchehab, gregkh, hverkuil-cisco, emil.velikov, linux-media,
	linux-rockchip, linux-staging, linux-kernel

Dne petek, 06. avgust 2021 ob 00:03:36 CEST je Ezequiel Garcia napisal(a):
> Hi Jernej,
> 
> On Thu, 2021-08-05 at 21:04 +0200, Jernej Skrabec wrote:
> > Some cores use only one interrupt and in such case interrupt name in DT
> > is not needed. Driver supposedly accounted that, but due to the wrong
> > field check it never worked. Fix that.
> > 
> > Fixes: 18d6c8b7b4c9 ("media: hantro: add fallback handling for single
> > irq/clk") Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
> > ---
> >  drivers/staging/media/hantro/hantro_drv.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c
> > b/drivers/staging/media/hantro/hantro_drv.c index
> > 8a2edd67f2c6..20e508158871 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -919,7 +919,7 @@ static int hantro_probe(struct platform_device *pdev)
> >                 if (!vpu->variant->irqs[i].handler)
> >                         continue;
> >  
> > -               if (vpu->variant->num_clocks > 1) {
> > +               if (vpu->variant->num_irqs > 1) {
> 
> Oops, thanks for spotting this.
> 
> How about this instead?

No, original solution is more robust. With solution below, you're assuming 
that irq order in driver array is same as in DT. That doesn't matter if there 
is only one name or if names match. However, if there is a typo, either in DT 
node or in driver, driver will still happily assign clock based on index and 
that might not be correct one. Even if it works out, you can easily miss that 
you have a typo. Driver doesn't tell you which irq is used, if it is 
successfully acquired.

Best regards,
Jernej

> 
> diff --git a/drivers/staging/media/hantro/hantro_drv.c
> b/drivers/staging/media/hantro/hantro_drv.c index
> 31d8449ca1d2..af7054b04155 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -918,16 +918,15 @@ static int hantro_probe(struct platform_device *pdev)
>                 if (!vpu->variant->irqs[i].handler)
>                         continue;
> 
> -               if (vpu->variant->num_clocks > 1) {
> -                       irq_name = vpu->variant->irqs[i].name;
> -                       irq = platform_get_irq_byname(vpu->pdev, irq_name);
> -               } else {
> +               irq_name = vpu->variant->irqs[i].name;
> +               irq = platform_get_irq_byname(vpu->pdev, irq_name);
> +               if (irq <= 0) {
>                         /*
> -                        * If the driver has a single IRQ, chances are there
> -                        * will be no actual name in the DT bindings. +    
>                    * Missing interrupt-names property in device tree, +    
>                    * looking up interrupts by index.
>                          */
>                         irq_name = "default";
> -                       irq = platform_get_irq(vpu->pdev, 0);
> +                       irq = platform_get_irq(vpu->pdev, i);
>                 }
>                 if (irq <= 0)
>                         return -ENXIO;





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

* Re: [PATCH] media: hantro: Fix check for single irq
  2021-08-06  4:44   ` Jernej Škrabec
@ 2021-08-06 14:13     ` Ezequiel Garcia
  2021-08-06 15:39       ` Jernej Škrabec
  0 siblings, 1 reply; 6+ messages in thread
From: Ezequiel Garcia @ 2021-08-06 14:13 UTC (permalink / raw)
  To: Jernej Škrabec, p.zabel
  Cc: mchehab, gregkh, hverkuil-cisco, emil.velikov, linux-media,
	linux-rockchip, linux-staging, linux-kernel

On Fri, 2021-08-06 at 06:44 +0200, Jernej Škrabec wrote:
> Dne petek, 06. avgust 2021 ob 00:03:36 CEST je Ezequiel Garcia napisal(a):
> > Hi Jernej,
> > 
> > On Thu, 2021-08-05 at 21:04 +0200, Jernej Skrabec wrote:
> > > Some cores use only one interrupt and in such case interrupt name in DT
> > > is not needed. Driver supposedly accounted that, but due to the wrong
> > > field check it never worked. Fix that.
> > > 
> > > Fixes: 18d6c8b7b4c9 ("media: hantro: add fallback handling for single
> > > irq/clk") Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
> > > ---
> > >  drivers/staging/media/hantro/hantro_drv.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/staging/media/hantro/hantro_drv.c
> > > b/drivers/staging/media/hantro/hantro_drv.c index
> > > 8a2edd67f2c6..20e508158871 100644
> > > --- a/drivers/staging/media/hantro/hantro_drv.c
> > > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > > @@ -919,7 +919,7 @@ static int hantro_probe(struct platform_device *pdev)
> > >                 if (!vpu->variant->irqs[i].handler)
> > >                         continue;
> > >  
> > > -               if (vpu->variant->num_clocks > 1) {
> > > +               if (vpu->variant->num_irqs > 1) {
> > 
> > Oops, thanks for spotting this.
> > 
> > How about this instead?
> 
> No, original solution is more robust. With solution below, you're assuming 
> that irq order in driver array is same as in DT. That doesn't matter if there 
> is only one name or if names match. However, if there is a typo, either in DT 
> node or in driver, driver will still happily assign clock based on index and 
> that might not be correct one. Even if it works out, you can easily miss that 
> you have a typo. Driver doesn't tell you which irq is used, if it is 
> successfully acquired.
> 

I find it odd to iterate up to num_irqs but then
have a case for num_irqs == 1, and call
platform_get_irq(vpu->pdev, 0).

But OTOH, your fix is correct and it's a oneliner.

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel


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

* Re: [PATCH] media: hantro: Fix check for single irq
  2021-08-06 14:13     ` Ezequiel Garcia
@ 2021-08-06 15:39       ` Jernej Škrabec
  0 siblings, 0 replies; 6+ messages in thread
From: Jernej Škrabec @ 2021-08-06 15:39 UTC (permalink / raw)
  To: p.zabel, Ezequiel Garcia
  Cc: mchehab, gregkh, hverkuil-cisco, emil.velikov, linux-media,
	linux-rockchip, linux-staging, linux-kernel

Dne petek, 06. avgust 2021 ob 16:13:46 CEST je Ezequiel Garcia napisal(a):
> On Fri, 2021-08-06 at 06:44 +0200, Jernej Škrabec wrote:
> > Dne petek, 06. avgust 2021 ob 00:03:36 CEST je Ezequiel Garcia napisal(a):
> > > Hi Jernej,
> > > 
> > > On Thu, 2021-08-05 at 21:04 +0200, Jernej Skrabec wrote:
> > > > Some cores use only one interrupt and in such case interrupt name in
> > > > DT
> > > > is not needed. Driver supposedly accounted that, but due to the wrong
> > > > field check it never worked. Fix that.
> > > > 
> > > > Fixes: 18d6c8b7b4c9 ("media: hantro: add fallback handling for single
> > > > irq/clk") Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
> > > > ---
> > > >  drivers/staging/media/hantro/hantro_drv.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/staging/media/hantro/hantro_drv.c
> > > > b/drivers/staging/media/hantro/hantro_drv.c index
> > > > 8a2edd67f2c6..20e508158871 100644
> > > > --- a/drivers/staging/media/hantro/hantro_drv.c
> > > > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > > > @@ -919,7 +919,7 @@ static int hantro_probe(struct platform_device
> > > > *pdev)
> > > >                 if (!vpu->variant->irqs[i].handler)
> > > >                         continue;
> > > >  
> > > > -               if (vpu->variant->num_clocks > 1) {
> > > > +               if (vpu->variant->num_irqs > 1) {
> > > 
> > > Oops, thanks for spotting this.
> > > 
> > > How about this instead?
> > 
> > No, original solution is more robust. With solution below, you're assuming
> > that irq order in driver array is same as in DT. That doesn't matter if
> > there is only one name or if names match. However, if there is a typo,
> > either in DT node or in driver, driver will still happily assign clock
> > based on index and that might not be correct one. Even if it works out,
> > you can easily miss that you have a typo. Driver doesn't tell you which
> > irq is used, if it is successfully acquired.
> 
> I find it odd to iterate up to num_irqs but then
> have a case for num_irqs == 1, and call
> platform_get_irq(vpu->pdev, 0).

True, it was also strange for me at first, but then it's robust and simple. 
Because of that, I just fixed obvious issue.

> 
> But OTOH, your fix is correct and it's a oneliner.
> 
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> 

Thanks!

Best regards,
Jernej

> Thanks,
> Ezequiel





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

* Re: [PATCH] media: hantro: Fix check for single irq
  2021-08-05 19:04 [PATCH] media: hantro: Fix check for single irq Jernej Skrabec
  2021-08-05 22:03 ` Ezequiel Garcia
@ 2021-08-09 15:20 ` Emil Velikov
  1 sibling, 0 replies; 6+ messages in thread
From: Emil Velikov @ 2021-08-09 15:20 UTC (permalink / raw)
  To: Jernej Skrabec
  Cc: ezequiel, p.zabel, mchehab, gregkh, hverkuil-cisco, linux-media,
	linux-rockchip, linux-staging, linux-kernel

On 2021/08/05, Jernej Skrabec wrote:
> Some cores use only one interrupt and in such case interrupt name in DT
> is not needed. Driver supposedly accounted that, but due to the wrong
> field check it never worked. Fix that.
> 
> Fixes: 18d6c8b7b4c9 ("media: hantro: add fallback handling for single irq/clk")
> Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>

D'oh thanks for catching that. This commit is:
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>

-Emil

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

end of thread, other threads:[~2021-08-09 15:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 19:04 [PATCH] media: hantro: Fix check for single irq Jernej Skrabec
2021-08-05 22:03 ` Ezequiel Garcia
2021-08-06  4:44   ` Jernej Škrabec
2021-08-06 14:13     ` Ezequiel Garcia
2021-08-06 15:39       ` Jernej Škrabec
2021-08-09 15:20 ` Emil Velikov

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