Skip to contentSkip to conversation

iommu/riscv: Fix signedness bug

PATCH Applied Ethan Tidmore 2 participants 2 messages Mar 26 – Apr 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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

Fixes 5c0ebbd3c6c6 ("iommu/riscv: Add RISC-V IOMMU platform device driver")

---
v2:
- Add correct Fixes tag.
- Add RB tag from Andrew Jones

 drivers/iommu/riscv/iommu-platform.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/riscv/iommu-platform.c +5 -2
index 8f15b06e8499..399ba8fe1b3e 100644
@@ -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
#1 lore raw
This patch was applied to riscv/linux.git (fixes) by Joerg Roedel <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Joerg Roedel <[email protected]>:

Quoted 8 lines · On Thu, 26 Mar 2026 12:57:38 -0500 you wrote:

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.

[...]

Here is the summary with links:
- [v2] iommu/riscv: Fix signedness bug

    https://git.kernel.org/riscv/c/553a127cb665

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html