[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALnP8Zbh1Jep5daNKZhBAKBZ3Y1R2MZgzapa1r=9ZmKhei1Qcg@mail.gmail.com>
Date: Tue, 28 Nov 2023 11:11:15 -0800
From: Marcelo Ricardo Leitner <mleitner@...hat.com>
To: Pedro Tammela <pctammela@...atatu.com>
Cc: netdev@...r.kernel.org, davem@...emloft.net, edumazet@...gle.com,
kuba@...nel.org, pabeni@...hat.com, jhs@...atatu.com,
xiyou.wangcong@...il.com, jiri@...nulli.us, vladbu@...dia.com
Subject: Re: [PATCH RFC net-next 3/4] net/sched: act_api: stop loop over ops
array on NULL in tcf_action_init
On Tue, Nov 28, 2023 at 01:06:30PM -0300, Pedro Tammela wrote:
> @@ -1510,10 +1510,8 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
> err:
> tcf_action_destroy(actions, flags & TCA_ACT_FLAGS_BIND);
> err_mod:
> - for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
> - if (ops[i])
> - module_put(ops[i]->owner);
> - }
> + for (i = 0; i < TCA_ACT_MAX_PRIO && ops[i]; i++)
> + module_put(ops[i]->owner);
> return err;
I was going to say:
Maybe it's time for a helper macro for this.
$ git grep TCA_ACT_MAX_PRIO
include/net/pkt_cls.h: for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) =
(exts)->actions[i]); i++)
include/net/pkt_cls.h: for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) =
actions[i]); i++)
...
net/sched/act_api.c: for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
net/sched/act_api.c: for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
net/sched/act_api.c: for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
net/sched/act_api.c: for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
...
net/sched/act_api.c: for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
net/sched/act_api.c: for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
net/sched/act_api.c: for (i = 0; i < TCA_ACT_MAX_PRIO; i++) {
net/sched/act_api.c: for (i = 0; i < TCA_ACT_MAX_PRIO && actions[i]; i++) {
...
But then, that's exactly what the first 2 hits are :)
So AFAICT this loop can be written as:
struct struct tc_action_ops *op;
tcf_act_for_each_action(i, op, ops)
module_put(op->owner);
Thoughts? It would be iterating over struct tc_action_ops and not
tc_action, as in tcf_act_for_each_action() (which is the only user of
this macro today), but that seems okay.
Marcelo
Powered by blists - more mailing lists