@@ -546,9 +546,33 @@ static void del_sw_flow_group(struct fs_node *node)
546
546
WARN_ON (err );
547
547
}
548
548
549
- static struct fs_fte * alloc_fte (struct mlx5_flow_act * flow_act ,
550
- u32 * match_value ,
551
- unsigned int index )
549
+ static int insert_fte (struct mlx5_flow_group * fg , struct fs_fte * fte )
550
+ {
551
+ int index ;
552
+ int ret ;
553
+
554
+ index = ida_simple_get (& fg -> fte_allocator , 0 , fg -> max_ftes , GFP_KERNEL );
555
+ if (index < 0 )
556
+ return index ;
557
+
558
+ fte -> index = index + fg -> start_index ;
559
+ ret = rhashtable_insert_fast (& fg -> ftes_hash ,
560
+ & fte -> hash ,
561
+ rhash_fte );
562
+ if (ret )
563
+ goto err_ida_remove ;
564
+
565
+ tree_add_node (& fte -> node , & fg -> node );
566
+ list_add_tail (& fte -> node .list , & fg -> node .children );
567
+ return 0 ;
568
+
569
+ err_ida_remove :
570
+ ida_simple_remove (& fg -> fte_allocator , index );
571
+ return ret ;
572
+ }
573
+
574
+ static struct fs_fte * alloc_fte (u32 * match_value ,
575
+ struct mlx5_flow_act * flow_act )
552
576
{
553
577
struct fs_fte * fte ;
554
578
@@ -559,51 +583,13 @@ static struct fs_fte *alloc_fte(struct mlx5_flow_act *flow_act,
559
583
memcpy (fte -> val , match_value , sizeof (fte -> val ));
560
584
fte -> node .type = FS_TYPE_FLOW_ENTRY ;
561
585
fte -> flow_tag = flow_act -> flow_tag ;
562
- fte -> index = index ;
563
586
fte -> action = flow_act -> action ;
564
587
fte -> encap_id = flow_act -> encap_id ;
565
588
fte -> modify_id = flow_act -> modify_id ;
566
589
567
- return fte ;
568
- }
569
-
570
- static struct fs_fte * alloc_insert_fte (struct mlx5_flow_group * fg ,
571
- u32 * match_value ,
572
- struct mlx5_flow_act * flow_act )
573
- {
574
- struct fs_fte * fte ;
575
- int index ;
576
- int ret ;
577
-
578
- index = ida_simple_get (& fg -> fte_allocator , 0 ,
579
- fg -> max_ftes ,
580
- GFP_KERNEL );
581
- if (index < 0 )
582
- return ERR_PTR (index );
583
-
584
- fte = alloc_fte (flow_act , match_value , index + fg -> start_index );
585
- if (IS_ERR (fte )) {
586
- ret = PTR_ERR (fte );
587
- goto err_ida_remove ;
588
- }
589
-
590
- ret = rhashtable_insert_fast (& fg -> ftes_hash ,
591
- & fte -> hash ,
592
- rhash_fte );
593
- if (ret )
594
- goto err_free ;
595
-
596
590
tree_init_node (& fte -> node , del_hw_fte , del_sw_fte );
597
- tree_add_node (& fte -> node , & fg -> node );
598
- list_add_tail (& fte -> node .list , & fg -> node .children );
599
591
600
592
return fte ;
601
-
602
- err_free :
603
- kfree (fte );
604
- err_ida_remove :
605
- ida_simple_remove (& fg -> fte_allocator , index );
606
- return ERR_PTR (ret );
607
593
}
608
594
609
595
static void dealloc_flow_group (struct mlx5_flow_group * fg )
@@ -1589,6 +1575,11 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
1589
1575
bool take_write = false;
1590
1576
struct fs_fte * fte ;
1591
1577
u64 version ;
1578
+ int err ;
1579
+
1580
+ fte = alloc_fte (spec -> match_value , flow_act );
1581
+ if (IS_ERR (fte ))
1582
+ return ERR_PTR (- ENOMEM );
1592
1583
1593
1584
list_for_each_entry (iter , match_head , list ) {
1594
1585
nested_down_read_ref_node (& iter -> g -> node , FS_LOCK_PARENT );
@@ -1620,6 +1611,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
1620
1611
flow_act , dest , dest_num , fte_tmp );
1621
1612
up_write_ref_node (& fte_tmp -> node );
1622
1613
tree_put_node (& fte_tmp -> node );
1614
+ kfree (fte );
1623
1615
return rule ;
1624
1616
}
1625
1617
@@ -1655,13 +1647,14 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
1655
1647
1656
1648
if (!g -> node .active )
1657
1649
continue ;
1658
- fte = alloc_insert_fte (g , spec -> match_value , flow_act );
1659
- if (IS_ERR ( fte ) ) {
1660
- if (PTR_ERR ( fte ) == - ENOSPC )
1650
+ err = insert_fte (g , fte );
1651
+ if (err ) {
1652
+ if (err == - ENOSPC )
1661
1653
continue ;
1662
1654
list_for_each_entry (iter , match_head , list )
1663
1655
up_write_ref_node (& iter -> g -> node );
1664
- return (void * )fte ;
1656
+ kfree (fte );
1657
+ return ERR_PTR (err );
1665
1658
}
1666
1659
1667
1660
nested_down_write_ref_node (& fte -> node , FS_LOCK_CHILD );
@@ -1677,6 +1670,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
1677
1670
out :
1678
1671
list_for_each_entry (iter , match_head , list )
1679
1672
up_write_ref_node (& iter -> g -> node );
1673
+ kfree (fte );
1680
1674
return rule ;
1681
1675
}
1682
1676
@@ -1746,12 +1740,18 @@ _mlx5_add_flow_rules(struct mlx5_flow_table *ft,
1746
1740
if (err )
1747
1741
goto err_release_fg ;
1748
1742
1749
- fte = alloc_insert_fte ( g , spec -> match_value , flow_act );
1743
+ fte = alloc_fte ( spec -> match_value , flow_act );
1750
1744
if (IS_ERR (fte )) {
1751
1745
err = PTR_ERR (fte );
1752
1746
goto err_release_fg ;
1753
1747
}
1754
1748
1749
+ err = insert_fte (g , fte );
1750
+ if (err ) {
1751
+ kfree (fte );
1752
+ goto err_release_fg ;
1753
+ }
1754
+
1755
1755
nested_down_write_ref_node (& fte -> node , FS_LOCK_CHILD );
1756
1756
up_write_ref_node (& g -> node );
1757
1757
rule = add_rule_fg (g , spec -> match_value , flow_act , dest ,
0 commit comments