iommu/amd: Free domain id in error path
authorVasant Hegde <vasant.hegde@amd.com>
Mon, 12 Sep 2022 06:32:44 +0000 (06:32 +0000)
committerJoerg Roedel <jroedel@suse.de>
Mon, 26 Sep 2022 11:25:20 +0000 (13:25 +0200)
Call domain_id_free() in error path.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Link: https://lore.kernel.org/r/20220912063248.7909-2-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/iommu.c

index 6bfcac8de1f4f8708ad25a4591ad169a54f4f4d9..c55f4a129b1e2614ce00b564d180c69c106235b6 100644 (file)
@@ -2027,8 +2027,10 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode)
 
        if (mode != PAGE_MODE_NONE) {
                pt_root = (void *)get_zeroed_page(GFP_KERNEL);
-               if (!pt_root)
+               if (!pt_root) {
+                       domain_id_free(domain->id);
                        return -ENOMEM;
+               }
        }
 
        amd_iommu_domain_set_pgtable(domain, pt_root, mode);
@@ -2092,8 +2094,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
                goto out_err;
 
        pgtbl_ops = alloc_io_pgtable_ops(pgtable, &domain->iop.pgtbl_cfg, domain);
-       if (!pgtbl_ops)
+       if (!pgtbl_ops) {
+               domain_id_free(domain->id);
                goto out_err;
+       }
 
        return domain;
 out_err: