mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-31 06:09:56 +00:00
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 <vasant.hegde@amd.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/10-v2-831cdc4d00f3+1a315-amd_iopgtbl_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
9ac0b3380a
commit
485534bfcc
@ -2253,17 +2253,9 @@ static void cleanup_domain(struct protection_domain *domain)
|
|||||||
|
|
||||||
void protection_domain_free(struct protection_domain *domain)
|
void protection_domain_free(struct protection_domain *domain)
|
||||||
{
|
{
|
||||||
if (!domain)
|
|
||||||
return;
|
|
||||||
|
|
||||||
WARN_ON(!list_empty(&domain->dev_list));
|
WARN_ON(!list_empty(&domain->dev_list));
|
||||||
|
free_io_pgtable_ops(&domain->iop.pgtbl.ops);
|
||||||
if (domain->iop.pgtbl.cfg.tlb)
|
domain_id_free(domain->id);
|
||||||
free_io_pgtable_ops(&domain->iop.pgtbl.ops);
|
|
||||||
|
|
||||||
if (domain->id)
|
|
||||||
domain_id_free(domain->id);
|
|
||||||
|
|
||||||
kfree(domain);
|
kfree(domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2279,7 +2271,7 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
|
|||||||
|
|
||||||
domain->id = domain_id_alloc();
|
domain->id = domain_id_alloc();
|
||||||
if (!domain->id)
|
if (!domain->id)
|
||||||
goto out_err;
|
goto err_free;
|
||||||
|
|
||||||
spin_lock_init(&domain->lock);
|
spin_lock_init(&domain->lock);
|
||||||
INIT_LIST_HEAD(&domain->dev_list);
|
INIT_LIST_HEAD(&domain->dev_list);
|
||||||
@ -2302,7 +2294,7 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
|
|||||||
pgtable = AMD_IOMMU_V1;
|
pgtable = AMD_IOMMU_V1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto out_err;
|
goto err_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pgtable) {
|
switch (pgtable) {
|
||||||
@ -2313,17 +2305,19 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
|
|||||||
domain->pd_mode = PD_MODE_V2;
|
domain->pd_mode = PD_MODE_V2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto out_err;
|
goto err_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
pgtbl_ops =
|
pgtbl_ops =
|
||||||
alloc_io_pgtable_ops(pgtable, &domain->iop.pgtbl.cfg, domain);
|
alloc_io_pgtable_ops(pgtable, &domain->iop.pgtbl.cfg, domain);
|
||||||
if (!pgtbl_ops)
|
if (!pgtbl_ops)
|
||||||
goto out_err;
|
goto err_id;
|
||||||
|
|
||||||
return domain;
|
return domain;
|
||||||
out_err:
|
err_id:
|
||||||
protection_domain_free(domain);
|
domain_id_free(domain->id);
|
||||||
|
err_free:
|
||||||
|
kfree(domain);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2412,9 +2406,6 @@ void amd_iommu_domain_free(struct iommu_domain *dom)
|
|||||||
struct protection_domain *domain;
|
struct protection_domain *domain;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
if (!dom)
|
|
||||||
return;
|
|
||||||
|
|
||||||
domain = to_pdomain(dom);
|
domain = to_pdomain(dom);
|
||||||
|
|
||||||
spin_lock_irqsave(&domain->lock, flags);
|
spin_lock_irqsave(&domain->lock, flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user