Skip to content

Commit 4aee43f

Browse files
author
Paolo Abeni
committed
Merge branch 'net-sched-act_api-contiguous-action-arrays'
Pedro Tammela says: ==================== net/sched: act_api: contiguous action arrays When dealing with action arrays in act_api it's natural to ask if they are always contiguous (no NULL pointers in between). Yes, they are in all cases so far, so make use of the already present tcf_act_for_each_action macro to explicitly document this assumption. There was an instance where it was not, but it was refactorable (patch 2) to make the array contiguous. v1->v2: - Respin - Added Jamal's acked-by ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 030033d + f9bfc8e commit 4aee43f

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

net/sched/act_api.c

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,7 @@ int tcf_action_destroy(struct tc_action *actions[], int bind)
11181118
struct tc_action *a;
11191119
int ret = 0, i;
11201120

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) {
11231122
actions[i] = NULL;
11241123
ops = a->ops;
11251124
ret = __tcf_idr_release(a, bind, true);
@@ -1136,18 +1135,29 @@ static int tcf_action_put(struct tc_action *p)
11361135
return __tcf_action_put(p, false);
11371136
}
11381137

1139-
/* Put all actions in this array, skip those NULL's. */
11401138
static void tcf_action_put_many(struct tc_action *actions[])
11411139
{
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;
11421153
int i;
11431154

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;
11471157

1148-
if (!a)
1158+
if (init_res[i] == ACT_P_CREATED)
11491159
continue;
1150-
ops = a->ops;
1160+
11511161
if (tcf_action_put(a))
11521162
module_put(ops->owner);
11531163
}
@@ -1211,8 +1221,7 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[],
12111221
int err = -EINVAL, i;
12121222
struct nlattr *nest;
12131223

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) {
12161225
nest = nla_nest_start_noflag(skb, i + 1);
12171226
if (nest == NULL)
12181227
goto nla_put_failure;
@@ -1276,14 +1285,12 @@ static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
12761285

12771286
void tcf_idr_insert_many(struct tc_action *actions[])
12781287
{
1288+
struct tc_action *a;
12791289
int i;
12801290

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) {
12831292
struct tcf_idrinfo *idrinfo;
12841293

1285-
if (!a)
1286-
continue;
12871294
idrinfo = a->idrinfo;
12881295
mutex_lock(&idrinfo->lock);
12891296
/* 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,
14971504
err:
14981505
tcf_action_destroy(actions, flags & TCA_ACT_FLAGS_BIND);
14991506
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);
15041509
return err;
15051510
}
15061511

@@ -1753,10 +1758,10 @@ static int tca_action_flush(struct net *net, struct nlattr *nla,
17531758

17541759
static int tcf_action_delete(struct net *net, struct tc_action *actions[])
17551760
{
1761+
struct tc_action *a;
17561762
int i;
17571763

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) {
17601765
const struct tc_action_ops *ops = a->ops;
17611766
/* Actions can be deleted concurrently so we must save their
17621767
* 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[])
17681773
if (tcf_action_put(a)) {
17691774
/* last reference, action was deleted concurrently */
17701775
module_put(ops->owner);
1771-
} else {
1776+
} else {
17721777
int ret;
17731778

17741779
/* now do the delete */
@@ -1977,7 +1982,7 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
19771982
struct netlink_ext_ack *extack)
19781983
{
19791984
size_t attr_size = 0;
1980-
int loop, ret, i;
1985+
int loop, ret;
19811986
struct tc_action *actions[TCA_ACT_MAX_PRIO] = {};
19821987
int init_res[TCA_ACT_MAX_PRIO] = {};
19831988

@@ -1990,13 +1995,11 @@ static int tcf_action_add(struct net *net, struct nlattr *nla,
19901995

19911996
if (ret < 0)
19921997
return ret;
1998+
19931999
ret = tcf_add_notify(net, n, actions, portid, attr_size, extack);
19942000

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);
20002003

20012004
return ret;
20022005
}

0 commit comments

Comments
 (0)