Skip to content

Commit bb3a6b7

Browse files
Jiang Liujoergroedel
authored andcommitted
iommu/vt-d: Factor out dmar_alloc_dev_scope() for later reuse
Factor out function dmar_alloc_dev_scope() from dmar_parse_dev_scope() for later reuse. Signed-off-by: Jiang Liu <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 7e7dfab commit bb3a6b7

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

drivers/iommu/dmar.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,9 @@ static int __init dmar_parse_one_dev_scope(struct acpi_dmar_device_scope *scope,
117117
return 0;
118118
}
119119

120-
int __init dmar_parse_dev_scope(void *start, void *end, int *cnt,
121-
struct pci_dev ***devices, u16 segment)
120+
void *dmar_alloc_dev_scope(void *start, void *end, int *cnt)
122121
{
123122
struct acpi_dmar_device_scope *scope;
124-
void * tmp = start;
125-
int index;
126-
int ret;
127123

128124
*cnt = 0;
129125
while (start < end) {
@@ -138,15 +134,24 @@ int __init dmar_parse_dev_scope(void *start, void *end, int *cnt,
138134
start += scope->length;
139135
}
140136
if (*cnt == 0)
141-
return 0;
137+
return NULL;
138+
139+
return kcalloc(*cnt, sizeof(struct pci_dev *), GFP_KERNEL);
140+
}
141+
142+
int __init dmar_parse_dev_scope(void *start, void *end, int *cnt,
143+
struct pci_dev ***devices, u16 segment)
144+
{
145+
struct acpi_dmar_device_scope *scope;
146+
int index, ret;
142147

143-
*devices = kcalloc(*cnt, sizeof(struct pci_dev *), GFP_KERNEL);
144-
if (!*devices)
148+
*devices = dmar_alloc_dev_scope(start, end, cnt);
149+
if (*cnt == 0)
150+
return 0;
151+
else if (!*devices)
145152
return -ENOMEM;
146153

147-
start = tmp;
148-
index = 0;
149-
while (start < end) {
154+
for (index = 0; start < end; start += scope->length) {
150155
scope = start;
151156
if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT ||
152157
scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE) {
@@ -158,7 +163,6 @@ int __init dmar_parse_dev_scope(void *start, void *end, int *cnt,
158163
}
159164
index ++;
160165
}
161-
start += scope->length;
162166
}
163167

164168
return 0;

include/linux/dmar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern int dmar_table_init(void);
6969
extern int dmar_dev_scope_init(void);
7070
extern int dmar_parse_dev_scope(void *start, void *end, int *cnt,
7171
struct pci_dev ***devices, u16 segment);
72+
extern void *dmar_alloc_dev_scope(void *start, void *end, int *cnt);
7273
extern void dmar_free_dev_scope(struct pci_dev ***devices, int *cnt);
7374

7475
/* Intel IOMMU detection */

0 commit comments

Comments
 (0)