Skip to content

Commit 92a2321

Browse files
LeoBrasmpe
authored andcommitted
powerpc/pseries/iommu: Add ddw_list_new_entry() helper
There are two functions creating direct_window_list entries in a similar way, so create a ddw_list_new_entry() to avoid duplicity and simplify those functions. Signed-off-by: Leonardo Bras <[email protected]> Reviewed-by: Alexey Kardashevskiy <[email protected]> Reviewed-by: Frederic Barrat <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4ff8677 commit 92a2321

File tree

1 file changed

+21
-11
lines changed
  • arch/powerpc/platforms/pseries

1 file changed

+21
-11
lines changed

arch/powerpc/platforms/pseries/iommu.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,21 @@ static u64 find_existing_ddw(struct device_node *pdn, int *window_shift)
874874
return dma_addr;
875875
}
876876

877+
static struct direct_window *ddw_list_new_entry(struct device_node *pdn,
878+
const struct dynamic_dma_window_prop *dma64)
879+
{
880+
struct direct_window *window;
881+
882+
window = kzalloc(sizeof(*window), GFP_KERNEL);
883+
if (!window)
884+
return NULL;
885+
886+
window->device = pdn;
887+
window->prop = dma64;
888+
889+
return window;
890+
}
891+
877892
static int find_existing_ddw_windows(void)
878893
{
879894
int len;
@@ -886,18 +901,15 @@ static int find_existing_ddw_windows(void)
886901

887902
for_each_node_with_property(pdn, DIRECT64_PROPNAME) {
888903
direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len);
889-
if (!direct64)
890-
continue;
891-
892-
window = kzalloc(sizeof(*window), GFP_KERNEL);
893-
if (!window || len < sizeof(struct dynamic_dma_window_prop)) {
894-
kfree(window);
904+
if (!direct64 || len < sizeof(*direct64)) {
895905
remove_ddw(pdn, true);
896906
continue;
897907
}
898908

899-
window->device = pdn;
900-
window->prop = direct64;
909+
window = ddw_list_new_entry(pdn, direct64);
910+
if (!window)
911+
break;
912+
901913
spin_lock(&direct_window_list_lock);
902914
list_add(&window->list, &direct_window_list);
903915
spin_unlock(&direct_window_list_lock);
@@ -1307,7 +1319,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
13071319
dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %pOF\n",
13081320
create.liobn, dn);
13091321

1310-
window = kzalloc(sizeof(*window), GFP_KERNEL);
1322+
window = ddw_list_new_entry(pdn, ddwprop);
13111323
if (!window)
13121324
goto out_clear_window;
13131325

@@ -1326,8 +1338,6 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
13261338
goto out_free_window;
13271339
}
13281340

1329-
window->device = pdn;
1330-
window->prop = ddwprop;
13311341
spin_lock(&direct_window_list_lock);
13321342
list_add(&window->list, &direct_window_list);
13331343
spin_unlock(&direct_window_list_lock);

0 commit comments

Comments
 (0)