@@ -874,6 +874,21 @@ static u64 find_existing_ddw(struct device_node *pdn, int *window_shift)
874
874
return dma_addr ;
875
875
}
876
876
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
+
877
892
static int find_existing_ddw_windows (void )
878
893
{
879
894
int len ;
@@ -886,18 +901,15 @@ static int find_existing_ddw_windows(void)
886
901
887
902
for_each_node_with_property (pdn , DIRECT64_PROPNAME ) {
888
903
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 )) {
895
905
remove_ddw (pdn , true);
896
906
continue ;
897
907
}
898
908
899
- window -> device = pdn ;
900
- window -> prop = direct64 ;
909
+ window = ddw_list_new_entry (pdn , direct64 );
910
+ if (!window )
911
+ break ;
912
+
901
913
spin_lock (& direct_window_list_lock );
902
914
list_add (& window -> list , & direct_window_list );
903
915
spin_unlock (& direct_window_list_lock );
@@ -1307,7 +1319,7 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
1307
1319
dev_dbg (& dev -> dev , "created tce table LIOBN 0x%x for %pOF\n" ,
1308
1320
create .liobn , dn );
1309
1321
1310
- window = kzalloc ( sizeof ( * window ), GFP_KERNEL );
1322
+ window = ddw_list_new_entry ( pdn , ddwprop );
1311
1323
if (!window )
1312
1324
goto out_clear_window ;
1313
1325
@@ -1326,8 +1338,6 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
1326
1338
goto out_free_window ;
1327
1339
}
1328
1340
1329
- window -> device = pdn ;
1330
- window -> prop = ddwprop ;
1331
1341
spin_lock (& direct_window_list_lock );
1332
1342
list_add (& window -> list , & direct_window_list );
1333
1343
spin_unlock (& direct_window_list_lock );
0 commit comments