@@ -1118,8 +1118,7 @@ int tcf_action_destroy(struct tc_action *actions[], int bind)
1118
1118
struct tc_action * a ;
1119
1119
int ret = 0 , i ;
1120
1120
1121
- for (i = 0 ; i < TCA_ACT_MAX_PRIO && actions [i ]; i ++ ) {
1122
- a = actions [i ];
1121
+ tcf_act_for_each_action (i , a , actions ) {
1123
1122
actions [i ] = NULL ;
1124
1123
ops = a -> ops ;
1125
1124
ret = __tcf_idr_release (a , bind , true);
@@ -1136,18 +1135,29 @@ static int tcf_action_put(struct tc_action *p)
1136
1135
return __tcf_action_put (p , false);
1137
1136
}
1138
1137
1139
- /* Put all actions in this array, skip those NULL's. */
1140
1138
static void tcf_action_put_many (struct tc_action * actions [])
1141
1139
{
1140
+ struct tc_action * a ;
1141
+ int i ;
1142
+
1143
+ tcf_act_for_each_action (i , a , actions ) {
1144
+ const struct tc_action_ops * ops = a -> ops ;
1145
+ if (tcf_action_put (a ))
1146
+ module_put (ops -> owner );
1147
+ }
1148
+ }
1149
+
1150
+ static void tca_put_bound_many (struct tc_action * actions [], int init_res [])
1151
+ {
1152
+ struct tc_action * a ;
1142
1153
int i ;
1143
1154
1144
- for (i = 0 ; i < TCA_ACT_MAX_PRIO ; i ++ ) {
1145
- struct tc_action * a = actions [i ];
1146
- const struct tc_action_ops * ops ;
1155
+ tcf_act_for_each_action (i , a , actions ) {
1156
+ const struct tc_action_ops * ops = a -> ops ;
1147
1157
1148
- if (! a )
1158
+ if (init_res [ i ] == ACT_P_CREATED )
1149
1159
continue ;
1150
- ops = a -> ops ;
1160
+
1151
1161
if (tcf_action_put (a ))
1152
1162
module_put (ops -> owner );
1153
1163
}
@@ -1211,8 +1221,7 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[],
1211
1221
int err = - EINVAL , i ;
1212
1222
struct nlattr * nest ;
1213
1223
1214
- for (i = 0 ; i < TCA_ACT_MAX_PRIO && actions [i ]; i ++ ) {
1215
- a = actions [i ];
1224
+ tcf_act_for_each_action (i , a , actions ) {
1216
1225
nest = nla_nest_start_noflag (skb , i + 1 );
1217
1226
if (nest == NULL )
1218
1227
goto nla_put_failure ;
@@ -1276,14 +1285,12 @@ static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
1276
1285
1277
1286
void tcf_idr_insert_many (struct tc_action * actions [])
1278
1287
{
1288
+ struct tc_action * a ;
1279
1289
int i ;
1280
1290
1281
- for (i = 0 ; i < TCA_ACT_MAX_PRIO ; i ++ ) {
1282
- struct tc_action * a = actions [i ];
1291
+ tcf_act_for_each_action (i , a , actions ) {
1283
1292
struct tcf_idrinfo * idrinfo ;
1284
1293
1285
- if (!a )
1286
- continue ;
1287
1294
idrinfo = a -> idrinfo ;
1288
1295
mutex_lock (& idrinfo -> lock );
1289
1296
/* Replace ERR_PTR(-EBUSY) allocated by tcf_idr_check_alloc if
@@ -1497,10 +1504,8 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
1497
1504
err :
1498
1505
tcf_action_destroy (actions , flags & TCA_ACT_FLAGS_BIND );
1499
1506
err_mod :
1500
- for (i = 0 ; i < TCA_ACT_MAX_PRIO ; i ++ ) {
1501
- if (ops [i ])
1502
- module_put (ops [i ]-> owner );
1503
- }
1507
+ for (i = 0 ; i < TCA_ACT_MAX_PRIO && ops [i ]; i ++ )
1508
+ module_put (ops [i ]-> owner );
1504
1509
return err ;
1505
1510
}
1506
1511
@@ -1753,10 +1758,10 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
1753
1758
1754
1759
static int tcf_action_delete (struct net * net , struct tc_action * actions [])
1755
1760
{
1761
+ struct tc_action * a ;
1756
1762
int i ;
1757
1763
1758
- for (i = 0 ; i < TCA_ACT_MAX_PRIO && actions [i ]; i ++ ) {
1759
- struct tc_action * a = actions [i ];
1764
+ tcf_act_for_each_action (i , a , actions ) {
1760
1765
const struct tc_action_ops * ops = a -> ops ;
1761
1766
/* Actions can be deleted concurrently so we must save their
1762
1767
* type and id to search again after reference is released.
@@ -1768,7 +1773,7 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[])
1768
1773
if (tcf_action_put (a )) {
1769
1774
/* last reference, action was deleted concurrently */
1770
1775
module_put (ops -> owner );
1771
- } else {
1776
+ } else {
1772
1777
int ret ;
1773
1778
1774
1779
/* now do the delete */
@@ -1977,7 +1982,7 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
1977
1982
struct netlink_ext_ack * extack )
1978
1983
{
1979
1984
size_t attr_size = 0 ;
1980
- int loop , ret , i ;
1985
+ int loop , ret ;
1981
1986
struct tc_action * actions [TCA_ACT_MAX_PRIO ] = {};
1982
1987
int init_res [TCA_ACT_MAX_PRIO ] = {};
1983
1988
@@ -1990,13 +1995,11 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
1990
1995
1991
1996
if (ret < 0 )
1992
1997
return ret ;
1998
+
1993
1999
ret = tcf_add_notify (net , n , actions , portid , attr_size , extack );
1994
2000
1995
- /* only put existing actions */
1996
- for (i = 0 ; i < TCA_ACT_MAX_PRIO ; i ++ )
1997
- if (init_res [i ] == ACT_P_CREATED )
1998
- actions [i ] = NULL ;
1999
- tcf_action_put_many (actions );
2001
+ /* only put bound actions */
2002
+ tca_put_bound_many (actions , init_res );
2000
2003
2001
2004
return ret ;
2002
2005
}
0 commit comments