dmaengine: tegra210-adma: fix of_irq_get() error check
Subsystems (3)
PATCH 1/1 dmaengine: tegra210-adma: fix of_irq_get() error check
of_irq_get() may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then call request_irq(0, ...) in tegra_adma_alloc_chan_resources() and never get valid channel interrupt.
Check for 'tdc->irq <= 0' instead and return -ENXIO from the driver's probe iff of_irq_get() returned 0.
--- drivers/dma/tegra210-adma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/tegra210-adma.c +2 -2
@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i); tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq; +if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }
Forgot to mention that the patch is against the 'fixes' branch of Vinod's 'slave-dma.git' repo.
Quoted 8 lines · Sergei Shtylyov
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.
Quoted 6 lines
Fixes f46b195799b5 ("dmaengine: tegra-adma: Add support for Tegra210 ADMA")--- drivers/dma/tegra210-adma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Yeah, that interface isn't very optimal. The problem with it, and we've had this kind before, is that every driver ends up having to implement a fallback for == 0 with the result of everyone returning a different error code.
Perhaps a good long-term solution would be to fix of_irq_get() to only return positive for valid interrupts and negative error codes, so that nobody has to deal with == 0 anymore.
That's obviously going to be a fairly big undertaking, so I'm fine with fixing up the individual callsites first.
Quoted 5 lines
Index:
slave-dma/drivers/dma/tegra210-adma.c
===================================================================
drivers/dma/tegra210-adma.c static int tegra_adma_probe(struct platf · line 724
Quoted 10 lines
drivers/dma/tegra210-adma.c +2
-2@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i); tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq; +if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }
I think in this particular case it would be better to just call platform_get_irq(), which already implements the equivalent.
Thierry
Hello!
Quoted 11 lines · Thierry Reding
Quoted 11 lines
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.Fixes f46b195799b5 ("dmaengine: tegra-adma: Add support for Tegra210 ADMA")
Quoted 8 lines
Quoted 3 lines
--- drivers/dma/tegra210-adma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Yeah, that interface isn't very optimal. The problem with it, and we've had this kind before, is that every driver ends up having to implement a fallback for == 0 with the result of everyone returning a different error code.
Agreed.
Quoted 3 lines
Perhaps a good long-term solution would be to fix
of_irq_get()to only return positive for valid interrupts and negative error codes, so that nobody has to deal with == 0 anymore.
See http://marc.info/?t=146447243300002&r=1 for my attempt to do this
back in 2016.
Quoted 10 lines
That's obviously going to be a fairly big undertaking, so I'm fine with fixing up the individual callsites first.
Quoted 7 lines
Index:
slave-dma/drivers/dma/tegra210-adma.c
===================================================================drivers/dma/tegra210-adma.c +0
-0@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i);
Quoted 11 lines
drivers/dma/tegra210-adma.c static int tegra_adma_probe(struct platf · line 724
Quoted 8 lines
drivers/dma/tegra210-adma.c +2
-2tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq; +if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }I think in this particular case it would be better to just call
platform_get_irq(), which already implements the equivalent.
OK, I'll try looking into that...
Quoted 1 line
Thierry
MBR, Sergei
Quoted 10 lines · Sergei Shtylyov
Quoted 10 lines
Quoted 10 lines
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.Fixes f46b195799b5 ("dmaengine: tegra-adma: Add support for Tegra210 ADMA")
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Index:
slave-dma/drivers/dma/tegra210-adma.c
===================================================================drivers/dma/tegra210-adma.c +0
-2@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i); tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq;
Quoted 8 lines
Quoted 8 lines
drivers/dma/tegra210-adma.c static int tegra_adma_probe(struct platf · line 724
Quoted 5 lines
drivers/dma/tegra210-adma.c +2
-0+if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }I think in this particular case it would be better to just call
platform_get_irq(), which already implements the equivalent.
Not that platform_get_irq() was no better (if not worse indeed, as it
could return 0 both on failure ad success), until I fixed it back in 2016:
Quoted 2 lines
OK, I'll try looking into that...
I've looked at the commit history and no, I don't agree to useplatform_get_irq(): my platform_get_irq() fix landed in mainline later than this driver, so fixing this bug in stable kernels would ensue an extra dependency...
Quoted 1 line
Quoted 1 line
Thierry
MBR, Sergei
Thierry Reding
Acked-byQuoted 38 lines · Sergei Shtylyov
Quoted 10 lines · Sergei Shtylyov
Quoted 10 lines
Quoted 10 lines
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.Fixes f46b195799b5 ("dmaengine: tegra-adma: Add support for Tegra210 ADMA")[...]
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Index:
slave-dma/drivers/dma/tegra210-adma.c
===================================================================drivers/dma/tegra210-adma.c +0
-2@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i); tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq;Quoted 8 lines
Quoted 8 lines
drivers/dma/tegra210-adma.c static int tegra_adma_probe(struct platf · line 723
Quoted 5 lines
drivers/dma/tegra210-adma.c +2
-0+if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }I think in this particular case it would be better to just call
platform_get_irq(), which already implements the equivalent.Not that
platform_get_irq()was no better (if not worse indeed, as it
could return 0 both on failure ad success), until I fixed it back in 2016:Quoted 1 line
Quoted 6 lines
Quoted 1 line
OK, I'll try looking into that...
I've looked at the commit history and no, I don't agree to use
platform_get_irq(): myplatform_get_irq()fix landed in mainline later than this driver, so fixing this bug in stable kernels would ensue an extra dependency...
Well, surely the platform_get_irq() function should also be fixed in stable kernels, so that all callers can be fixed at the same time.
That said, this does fix a bug, and it fixes it in the least invasive way, and the damage I'm complaining about is preexisting, so:
Quoted 30 lines · Thierry Reding
Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.Fixes f46b195799b5 ("dmaengine: tegra-adma: Add support for Tegra210 ADMA")[...]
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Index:
slave-dma/drivers/dma/tegra210-adma.c
===================================================================drivers/dma/tegra210-adma.c static int tegra_adma_probe(struct platf · line 723
Quoted 9 lines
drivers/dma/tegra210-adma.c +2
-2@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i); tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq; +if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }I think in this particular case it would be better to just call
platform_get_irq(), which already implements the equivalent.
Quoted 1 line
Quoted 1 line
Not that
platform_get_irq()was no better (if not worse indeed, as it
s/Not/Note/.
Quoted 1 line
Quoted 1 line
could return 0 both on failure ad success), until I fixed it back in 2016:
s/ad/and/.
Quoted 11 lines
Quoted 8 lines
Quoted 1 line
OK, I'll try looking into that...
I've looked at the commit history and no, I don't agree to use
platform_get_irq(): myplatform_get_irq()fix landed in mainline later than this driver, so fixing this bug in stable kernels would ensue an extra dependency...Well, surely the
platform_get_irq()function should also be fixed in stable kernels, so that all callers can be fixed at the same time.
It has been fixed in 3.16.y, 4.4.y and 4.8.y so far. I haven't received
other stable mails yet.
Quoted 4 lines
That said, this does fix a bug, and it fixes it in the least invasive way, and the damage I'm complaining about is preexisting, so:
Acked-by Thierry Reding <[email protected]>
Thank you!
MBR, Sergei
Jon Hunter
Acked-byQuoted 48 lines · Thierry Reding
* PGP Signed by an unknown key
Quoted 38 lines · Sergei Shtylyov
Quoted 10 lines · Sergei Shtylyov
Quoted 10 lines
Quoted 10 lines
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.Fixes f46b195799b5 ("dmaengine: tegra-adma: Add support for Tegra210 ADMA")[...]
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Index:
slave-dma/drivers/dma/tegra210-adma.c
===================================================================drivers/dma/tegra210-adma.c +0
-2@@ -717,8 +717,8 @@ static int tegra_adma_probe(struct platf tdc->chan_addr = tdma->base_addr +ADMA_CH_REG_OFFSET (i); tdc->irq =of_irq_get (pdev->dev.of_node, i); -if (tdc->irq <0 ) { - ret = tdc->irq;Quoted 8 lines
Quoted 8 lines
drivers/dma/tegra210-adma.c static int tegra_adma_probe(struct platf · line 723
Quoted 5 lines
drivers/dma/tegra210-adma.c +2
-0+if (tdc->irq <=0 ) { + ret = tdc->irq ?: -ENXIO ; goto irq_dispose; }I think in this particular case it would be better to just call
platform_get_irq(), which already implements the equivalent.Not that
platform_get_irq()was no better (if not worse indeed, as it
could return 0 both on failure ad success), until I fixed it back in 2016:Quoted 1 line
Quoted 6 lines
Quoted 1 line
OK, I'll try looking into that...
I've looked at the commit history and no, I don't agree to use
platform_get_irq(): myplatform_get_irq()fix landed in mainline later than this driver, so fixing this bug in stable kernels would ensue an extra dependency...
Quoted 7 lines
Well, surely the
platform_get_irq()function should also be fixed in stable kernels, so that all callers can be fixed at the same time.That said, this does fix a bug, and it fixes it in the least invasive way, and the damage I'm complaining about is preexisting, so:
Acked-by Thierry Reding <[email protected]>
FWIW ...
Thanks!
Jon
Signature · 1 line
nvpublic
Vinod Koul
AppliedQuoted 7 lines · Sergei Shtylyov
of_irq_get()may return 0 as well as negative error number on failure, while the driver only checks for the negative values. The driver would then callrequest_irq(0, ...)integra_adma_alloc_chan_resources()and never get valid channel interrupt.Check for '
tdc->irq<= 0' instead and return-ENXIOfrom the driver's probe iffof_irq_get()returned 0.
Applied, thanks
Signature · 1 line
~Vinod