Skip to content

Commit 485534b

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Remove conditions from domain free paths
Don't use tlb as some flag to indicate if protection_domain_alloc() completed. Have protection_domain_alloc() unwind itself in the normal kernel style and require protection_domain_free() only be called on successful results of protection_domain_alloc(). Also, the amd_iommu_domain_free() op is never called by the core code with a NULL argument, so remove all the NULL tests as well. Reviewed-by: Vasant Hegde <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9ac0b33 commit 485534b

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,17 +2253,9 @@ static void cleanup_domain(struct protection_domain *domain)
22532253

22542254
void protection_domain_free(struct protection_domain *domain)
22552255
{
2256-
if (!domain)
2257-
return;
2258-
22592256
WARN_ON(!list_empty(&domain->dev_list));
2260-
2261-
if (domain->iop.pgtbl.cfg.tlb)
2262-
free_io_pgtable_ops(&domain->iop.pgtbl.ops);
2263-
2264-
if (domain->id)
2265-
domain_id_free(domain->id);
2266-
2257+
free_io_pgtable_ops(&domain->iop.pgtbl.ops);
2258+
domain_id_free(domain->id);
22672259
kfree(domain);
22682260
}
22692261

@@ -2279,7 +2271,7 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
22792271

22802272
domain->id = domain_id_alloc();
22812273
if (!domain->id)
2282-
goto out_err;
2274+
goto err_free;
22832275

22842276
spin_lock_init(&domain->lock);
22852277
INIT_LIST_HEAD(&domain->dev_list);
@@ -2302,7 +2294,7 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
23022294
pgtable = AMD_IOMMU_V1;
23032295
break;
23042296
default:
2305-
goto out_err;
2297+
goto err_id;
23062298
}
23072299

23082300
switch (pgtable) {
@@ -2313,17 +2305,19 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
23132305
domain->pd_mode = PD_MODE_V2;
23142306
break;
23152307
default:
2316-
goto out_err;
2308+
goto err_id;
23172309
}
23182310

23192311
pgtbl_ops =
23202312
alloc_io_pgtable_ops(pgtable, &domain->iop.pgtbl.cfg, domain);
23212313
if (!pgtbl_ops)
2322-
goto out_err;
2314+
goto err_id;
23232315

23242316
return domain;
2325-
out_err:
2326-
protection_domain_free(domain);
2317+
err_id:
2318+
domain_id_free(domain->id);
2319+
err_free:
2320+
kfree(domain);
23272321
return NULL;
23282322
}
23292323

@@ -2412,9 +2406,6 @@ void amd_iommu_domain_free(struct iommu_domain *dom)
24122406
struct protection_domain *domain;
24132407
unsigned long flags;
24142408

2415-
if (!dom)
2416-
return;
2417-
24182409
domain = to_pdomain(dom);
24192410

24202411
spin_lock_irqsave(&domain->lock, flags);

0 commit comments

Comments
 (0)