From 3ded8a3190cf79670f0320c2bc4a611a35d014de Mon Sep 17 00:00:00 2001 From: Daniel Mentz Date: Mon, 3 Feb 2025 14:37:02 -0800 Subject: [PATCH] ANDROID: KVM: arm64: iommu: Avoid use of uninitialized variable in smmu_map_pages When the while condition is first evaluated, the variable named ret may be used uninitialized. Additionally, it is not necessary to make it part of the while condition, because the only place where this variable is changed is an assignment after the call to map_pages, and there is already an if statement that checks its value. Bug: 394152442 Fixes: a737b7d0e721 ("ANDROID: KVM: arm64: iommu: Reduce the logic in generic code") Change-Id: I3a214f5ac424bc13b2443097cd6a2a05a6397393 Signed-off-by: Daniel Mentz Signed-off-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c index 6265e7af812f..77d84b398142 100644 --- a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c @@ -1425,7 +1425,7 @@ static int smmu_map_pages(struct kvm_hyp_iommu_domain *domain, unsigned long iov { size_t mapped; size_t granule; - int ret; + int ret = 0; struct hyp_arm_smmu_v3_domain *smmu_domain = domain->priv; struct io_pgtable *pgtable = smmu_domain->pgtable; @@ -1437,7 +1437,7 @@ static int smmu_map_pages(struct kvm_hyp_iommu_domain *domain, unsigned long iov return -EINVAL; hyp_spin_lock(&smmu_domain->pgt_lock); - while (pgcount && !ret) { + while (pgcount) { mapped = 0; ret = pgtable->ops.map_pages(&pgtable->ops, iova, paddr, pgsize, pgcount, prot, 0, &mapped); @@ -1453,7 +1453,7 @@ static int smmu_map_pages(struct kvm_hyp_iommu_domain *domain, unsigned long iov } hyp_spin_unlock(&smmu_domain->pgt_lock); - return 0; + return ret; } static size_t smmu_unmap_pages(struct kvm_hyp_iommu_domain *domain, unsigned long iova,