2024-06-04 19:05:52

by Mostafa Saleh

[permalink] [raw]
Subject: [PATCH] iommu/arm-smmu-v3: Avoid uninitialized asid in case of error

Static checker is complaining about the ASID possibly set uninitialized.
This only happens in case of error and this value would be ignored anyway.

A simple fix would be just to initialize the local variable to zero,
this path will only be reached on the first attach to a domain where
the CD is already initialized to zero.
This avoids having to bloat the function with an error path.

Reported-by: Dan Carpenter <[email protected]>
Closes:https://lore.kernel.org/linux-iommu/[email protected]/T/#u
Signed-off-by: Mostafa Saleh <[email protected]>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index ab415e107054..f456bcf1890b 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2302,7 +2302,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu,
struct arm_smmu_domain *smmu_domain)
{
int ret;
- u32 asid;
+ u32 asid = 0;
struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;

refcount_set(&cd->refs, 1);
--
2.45.1.288.g0e0cd299f1-goog



2024-06-04 19:09:26

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] iommu/arm-smmu-v3: Avoid uninitialized asid in case of error

On Tue, Jun 04, 2024 at 06:52:18PM +0000, Mostafa Saleh wrote:
> A simple fix would be just to initialize the local variable to zero,
> this path will only be reached on the first attach to a domain where
> the CD is already initialized to zero.
> This avoids having to bloat the function with an error path.

Yep. Since everyone automatically zeroes stack variables these days,
this patch doesn't have any impact on runtime at all. It's free. It
just silences warning.

regards,
dan carpenter


2024-06-05 15:46:27

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] iommu/arm-smmu-v3: Avoid uninitialized asid in case of error

On Tue, 04 Jun 2024 18:52:18 +0000, Mostafa Saleh wrote:
> Static checker is complaining about the ASID possibly set uninitialized.
> This only happens in case of error and this value would be ignored anyway.
>
> A simple fix would be just to initialize the local variable to zero,
> this path will only be reached on the first attach to a domain where
> the CD is already initialized to zero.
> This avoids having to bloat the function with an error path.
>
> [...]

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-v3: Avoid uninitialized asid in case of error
https://git.kernel.org/will/c/d3867e714831

Cheers,
--
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev