lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Tue, 28 Nov 2023 16:29:43 -0300
From: Pedro Tammela <pctammela@...atatu.com>
To: Marcelo Ricardo Leitner <mleitner@...hat.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 28/11/2023 16:11, Marcelo Ricardo Leitner wrote:
> 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
> 

Interesting, I didn't even notice those macros.
I believe it helps with code maintainability.

Do note, I saw a place that the action array is expected to be not 
contiguous. So any sed-like replacement must be done with care.

When we know for sure it's contiguous, I'm all in for macros!



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ