diff mbox series

iommu/arm-smmu-v3: Avoid uninitialized asid in case of error

Message ID 20240604185218.2602058-1-smostafa@google.com (mailing list archive)
State New, archived
Headers show
Series iommu/arm-smmu-v3: Avoid uninitialized asid in case of error | expand

Commit Message

Mostafa Saleh June 4, 2024, 6:52 p.m. UTC
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 <dan.carpenter@linaro.org>
Closes:https://lore.kernel.org/linux-iommu/849e3d77-0a3c-43c4-878d-a0e061c8cd61@moroto.mountain/T/#u
Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe June 4, 2024, 6:55 p.m. UTC | #1
On Tue, Jun 04, 2024 at 06:52:18PM +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.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes:https://lore.kernel.org/linux-iommu/849e3d77-0a3c-43c4-878d-a0e061c8cd61@moroto.mountain/T/#u
> Signed-off-by: Mostafa Saleh <smostafa@google.com>
> ---
>  drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks this TODO is in my pile of emails :\

Fixes: 04905c17f648 ("iommu/arm-smmu-v3: Build the whole CD in arm_smmu_make_s1_cd()")
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

(mind the missing space 'Closes:')

Jason
Dan Carpenter June 4, 2024, 7:09 p.m. UTC | #2
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
Will Deacon June 5, 2024, 3:45 p.m. UTC | #3
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,
diff mbox series

Patch

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);