Skip to contentSkip to conversation

iommu/riscv: Fix unsigned comparison with negative error code

PATCH In review Alper Ak 3 participants 3 messages Dec 22, 2025 – Jan 10

Subsystems (3)
lore
Share & tools
lore

Alper Ak

author
#0 lore raw

PATCH 1/1 iommu/riscv: Fix unsigned comparison with negative error code

platform_irq_count() can return -EPROBE_DEFER, but irqs_count is unsigned. This causes the negative value to wrap around and bypass the error check.

Store the return value in a signed integer first and check for errors before assigning to irqs_count.

---
 drivers/iommu/riscv/iommu-platform.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/iommu/riscv/iommu-platform.c +7 -2
index 83a28c83f991..5ec8efedbf12 100644
@@ -68,8 +68,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)
 	iommu->caps = riscv_iommu_readq(iommu, RISCV_IOMMU_REG_CAPABILITIES);
 	iommu->fctl = riscv_iommu_readl(iommu, RISCV_IOMMU_REG_FCTL);
 
-	iommu->irqs_count = platform_irq_count(pdev);
-	if (iommu->irqs_count <= 0)
+	ret = platform_irq_count(pdev);
+	if (ret < 0)
+		return ret;
+
+	iommu->irqs_count = ret;
+
+	if (!iommu->irqs_count)
 		return dev_err_probe(dev, -ENODEV,
 				     "no IRQ resources provided\n");
 	if (iommu->irqs_count > RISCV_IOMMU_INTR_COUNT)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Alper Ak

platform_irq_count() can return -EPROBE_DEFER, but irqs_count is unsigned. This causes the negative value to wrap around and bypass the error check.

Store the return value in a signed integer first and check for errors before assigning to irqs_count.

Quoted 6 lines
---
  drivers/iommu/riscv/iommu-platform.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)

Thanks,
Nutty

Quoted 20 lines
drivers/iommu/riscv/iommu-platform.c +7 -2
index 83a28c83f991..5ec8efedbf12 100644
@@ -68,8 +68,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)
  	iommu->caps = riscv_iommu_readq(iommu, RISCV_IOMMU_REG_CAPABILITIES);
  	iommu->fctl = riscv_iommu_readl(iommu, RISCV_IOMMU_REG_FCTL);
 
-	iommu->irqs_count = platform_irq_count(pdev);
-	if (iommu->irqs_count <= 0)
+	ret = platform_irq_count(pdev);
+	if (ret < 0)
+		return ret;
+
+	iommu->irqs_count = ret;
+
+	if (!iommu->irqs_count)
  		return dev_err_probe(dev, -ENODEV,
  				     "no IRQ resources provided\n");
  	if (iommu->irqs_count > RISCV_IOMMU_INTR_COUNT)
maintainer
#2 lore raw
In reply to Alper Ak

drivers/iommu/riscv/iommu-platform.c static int riscv_iommu_platform_probe(struct platform_device *pdev) · line 79

Quoted 11 lines · Alper Ak
drivers/iommu/riscv/iommu-platform.c +7 -2
-	iommu->irqs_count = platform_irq_count(pdev);
-	if (iommu->irqs_count <= 0)
+	ret = platform_irq_count(pdev);
+	if (ret < 0)
+		return ret;
+
+	iommu->irqs_count = ret;
+
+	if (!iommu->irqs_count)
 		return dev_err_probe(dev, -ENODEV,
 				     "no IRQ resources provided\n");

Separate the ret < 0 and ret == 0 checks is wrong, just check them in one if statement and return the dev_err_probe() value as before.

-Joerg