Skip to content

Commit ba7d263

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Consolidate logic to allocate protection domain
Move the logic into the common caller function to simplify the code. No functional changes intended. Signed-off-by: Suravee Suthikulpanit <[email protected]> Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 75e6d7e commit ba7d263

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,12 +2046,6 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode)
20462046

20472047
BUG_ON(mode < PAGE_MODE_NONE || mode > PAGE_MODE_6_LEVEL);
20482048

2049-
spin_lock_init(&domain->lock);
2050-
domain->id = domain_id_alloc();
2051-
if (!domain->id)
2052-
return -ENOMEM;
2053-
INIT_LIST_HEAD(&domain->dev_list);
2054-
20552049
if (mode != PAGE_MODE_NONE) {
20562050
pt_root = (void *)get_zeroed_page(GFP_KERNEL);
20572051
if (!pt_root) {
@@ -2067,12 +2061,6 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode)
20672061

20682062
static int protection_domain_init_v2(struct protection_domain *domain)
20692063
{
2070-
spin_lock_init(&domain->lock);
2071-
domain->id = domain_id_alloc();
2072-
if (!domain->id)
2073-
return -ENOMEM;
2074-
INIT_LIST_HEAD(&domain->dev_list);
2075-
20762064
domain->flags |= PD_GIOV_MASK;
20772065

20782066
domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
@@ -2112,6 +2100,13 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
21122100
if (!domain)
21132101
return NULL;
21142102

2103+
domain->id = domain_id_alloc();
2104+
if (!domain->id)
2105+
goto out_err;
2106+
2107+
spin_lock_init(&domain->lock);
2108+
INIT_LIST_HEAD(&domain->dev_list);
2109+
21152110
switch (pgtable) {
21162111
case AMD_IOMMU_V1:
21172112
ret = protection_domain_init_v1(domain, mode);

0 commit comments

Comments
 (0)