From: Joao Martins <joao.m.mart...@oracle.com>

[ Upstream commit 14c4acc5ed22c21f9821103be7c48efdf9763584 ]

After commit 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after
programming IRTE"), smatch warns:

        drivers/iommu/amd/iommu.c:3870 amd_iommu_deactivate_guest_mode()
        warn: variable dereferenced before check 'entry' (see line 3867)

Fix this by moving the @valid assignment to after @entry has been checked
for NULL.

Fixes: 26e495f34107 ("iommu/amd: Restore IRTE.RemapEn bit after programming 
IRTE")
Reported-by: Dan Carpenter <dan.carpen...@oracle.com>
Signed-off-by: Joao Martins <joao.m.mart...@oracle.com>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
Cc: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
Link: https://lore.kernel.org/r/20200910171621.12879-1-joao.m.mart...@oracle.com
Signed-off-by: Joerg Roedel <jroe...@suse.de>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 drivers/iommu/amd_iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index cdafc652d9d1a..fa91d856a43ee 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -4431,12 +4431,14 @@ int amd_iommu_deactivate_guest_mode(void *data)
        struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
        struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
        struct irq_cfg *cfg = ir_data->cfg;
-       u64 valid = entry->lo.fields_remap.valid;
+       u64 valid;
 
        if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
            !entry || !entry->lo.fields_vapic.guest_mode)
                return 0;
 
+       valid = entry->lo.fields_remap.valid;
+
        entry->lo.val = 0;
        entry->hi.val = 0;
 
-- 
2.25.1



Reply via email to