iommu/riscv: Fix signedness bug
Subsystems (3)
PATCH 1/1 iommu/riscv: Fix signedness bug
The function platform_irq_count() returns negative error codes and iommu->irqs_count is an unsigned integer, so the check (iommu->irqs_count <= 0) is always impossible.
Make the return value of platform_irq_count() be assigned to ret, check for error, and then assign iommu->irqs_count to ret.
Detected by Smatch:drivers/iommu/riscv/iommu-platform.c:119 riscv_iommu_platform_probe() warn:
'iommu->irqs_count' unsigned <= 0
--- drivers/iommu/riscv/iommu-platform.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/riscv/iommu-platform.c +5 -2
@@ -115,10 +115,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev) fallthrough;case RISCV_IOMMU_CAPABILITIES_IGS_WSI : - iommu->irqs_count =platform_irq_count (pdev); -if (iommu->irqs_count <=0 ) + ret =platform_irq_count (pdev); +if (ret <=0 )return dev_err_probe (dev, -ENODEV ,"no IRQ resources provided\n" ); + + iommu->irqs_count = ret; +if (iommu->irqs_count >RISCV_IOMMU_INTR_COUNT ) iommu->irqs_count =RISCV_IOMMU_INTR_COUNT ;
Signature · 1 line
2.53.0
Quoted 4 lines · Ethan Tidmore
The function
platform_irq_count()returns negative error codes andiommu->irqs_countis an unsigned integer, so the check (iommu->irqs_count<= 0) is always impossible.
Quoted 8 lines
Make the return value of
platform_irq_count()be assigned to ret, check for error, and then assigniommu->irqs_countto ret.Detected by Smatch:
drivers/iommu/riscv/iommu-platform.c:119riscv_iommu_platform_probe()warn:
'iommu->irqs_count' unsigned <= 0Fixes 7217cee35aadb ("iommu/riscv: Skip IRQ count check when using MSI interrupts")
This isn't the correct fixes tag. It should be
Quoted 28 lines
Signed-off-by Ethan Tidmore <[email protected]>--- drivers/iommu/riscv/iommu-platform.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/iommu/riscv/iommu-platform.c +5
-2@@ -115,10 +115,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev) fallthrough;case RISCV_IOMMU_CAPABILITIES_IGS_WSI : - iommu->irqs_count =platform_irq_count (pdev); -if (iommu->irqs_count <=0 ) + ret =platform_irq_count (pdev); +if (ret <=0 )return dev_err_probe (dev, -ENODEV ,"no IRQ resources provided\n" ); + + iommu->irqs_count = ret; +if (iommu->irqs_count >RISCV_IOMMU_INTR_COUNT ) iommu->irqs_count =RISCV_IOMMU_INTR_COUNT ;Signature · 1 line
2.53.0
Otherwise,
Quoted 2 lines · Ethan Tidmore
drivers/iommu/riscv/iommu-platform.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Applied, thanks.
Quoted 5 lines · Joerg Roedel
Quoted 2 lines · Ethan Tidmore
drivers/iommu/riscv/iommu-platform.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Applied, thanks.
There's a v2 of this patch with the fixes tag fixed
https://lore.kernel.org/all/[email protected]/
Thanks,
drew
Joerg Roedel
maintainerQuoted 10 lines · Andrew Jones
Quoted 5 lines · Joerg Roedel
Quoted 2 lines · Ethan Tidmore
drivers/iommu/riscv/iommu-platform.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Applied, thanks.
There's a v2 of this patch with the fixes tag fixed
I updated the Fixes tag when applying. So it should be fine, but please double-check.
-Joerg