Skip to contentSkip to conversation

iommu/mediatek: Fix unsigned domid comparison with less than zero

PATCH Applied Colin King 3 participants 3 messages Feb 4, 2021 – Feb 5, 2021

Subsystems (4)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH v2 1/1 iommu/mediatek: Fix unsigned domid comparison with less than zero

From: Colin Ian King <[email protected]>

Currently the check for domid < 0 is always false because domid is unsigned. Fix this by casting domid to an int before making the comparison.

Addresses-Coverity: ("Unsigned comparison against 0")

---

V2: cast domid rather than making it an int. Replace L with : in
the commit message.

---
 drivers/iommu/mtk_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/mtk_iommu.c +1 -1
index 0ad14a7604b1..1f262621ef19 100644
@@ -645,7 +645,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
 	struct iommu_resv_region *region;
 	int prot = IOMMU_WRITE | IOMMU_READ;
 
-	if (domid < 0)
+	if ((int)domid < 0)
 		return;
 	curdom = data->plat_data->iova_region + domid;
 	for (i = 0; i < data->plat_data->iova_region_nr; i++) {
Signature · 1 line
2.29.2
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 22 lines · Colin King

From: Colin Ian King <[email protected]>

Currently the check for domid < 0 is always false because domid is unsigned. Fix this by casting domid to an int before making the comparison.

Addresses-Coverity: ("Unsigned comparison against 0")

---

V2: cast domid rather than making it an int. Replace L with : in
the commit message.

---
 drivers/iommu/mtk_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/mtk_iommu.c +0 -0
index 0ad14a7604b1..1f262621ef19 100644

drivers/iommu/mtk_iommu.c static void mtk_iommu_get_resv_regions(struct device *dev, · line 651

Quoted 8 lines
drivers/iommu/mtk_iommu.c +1 -1
@@ -645,7 +645,7 @@ static void mtk_iommu_get_resv_regions(struct device *dev,
 	struct iommu_resv_region *region;
 	int prot = IOMMU_WRITE | IOMMU_READ;
 
-	if (domid < 0)
+	if ((int)domid < 0)
 		return;
 	curdom = data->plat_data->iova_region + domid;
 	for (i = 0; i < data->plat_data->iova_region_nr; i++) {

Thanks, Colin.

Will