Skip to content

Commit 553a127

Browse files
Ethan Tidmorejoergroedel
authored andcommitted
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 Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com> Fixes: 5c0ebbd ("iommu/riscv: Add RISC-V IOMMU platform device driver") Reviewed-by: Andrew Jones <andrew.jones@oss.qualcomm.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent b2e5684 commit 553a127

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/iommu/riscv/iommu-platform.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ static int riscv_iommu_platform_probe(struct platform_device *pdev)
115115
fallthrough;
116116

117117
case RISCV_IOMMU_CAPABILITIES_IGS_WSI:
118-
iommu->irqs_count = platform_irq_count(pdev);
119-
if (iommu->irqs_count <= 0)
118+
ret = platform_irq_count(pdev);
119+
if (ret <= 0)
120120
return dev_err_probe(dev, -ENODEV,
121121
"no IRQ resources provided\n");
122+
123+
iommu->irqs_count = ret;
124+
122125
if (iommu->irqs_count > RISCV_IOMMU_INTR_COUNT)
123126
iommu->irqs_count = RISCV_IOMMU_INTR_COUNT;
124127

0 commit comments

Comments
 (0)