* [patch net-next] net/sched: let chain_get to figure out the return value
@ 2017-05-26 7:21 Jiri Pirko
2017-05-26 14:59 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Pirko @ 2017-05-26 7:21 UTC (permalink / raw)
To: netdev; +Cc: davem, jhs, xiyou.wangcong, mlxsw
From: Jiri Pirko <jiri@mellanox.com>
Alhough I believe that this create/nocreate dance is completelly
pointless, at least make it a bit nicer and easier to read.
Push the decision on what error value is returned to chain_get function
and use ERR macros.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
net/sched/act_api.c | 4 ++--
net/sched/cls_api.c | 15 ++++++---------
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index aed6cf2..42bb75a 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -35,8 +35,8 @@ static int tcf_action_goto_chain_init(struct tc_action *a, struct tcf_proto *tp)
if (!tp)
return -EINVAL;
a->goto_chain = tcf_chain_get(tp->chain->block, chain_index, true);
- if (!a->goto_chain)
- return -ENOMEM;
+ if (IS_ERR(a->goto_chain))
+ return PTR_ERR(a->goto_chain);
return 0;
}
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 39da0c5..deec814 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -193,7 +193,7 @@ static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
chain = kzalloc(sizeof(*chain), GFP_KERNEL);
if (!chain)
- return NULL;
+ return ERR_PTR(-ENOMEM);
list_add_tail(&chain->list, &block->chain_list);
chain->block = block;
chain->index = chain_index;
@@ -231,10 +231,7 @@ struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index,
return chain;
}
}
- if (create)
- return tcf_chain_create(block, chain_index);
- else
- return NULL;
+ return create ? tcf_chain_create(block, chain_index) : ERR_PTR(-EINVAL);
}
EXPORT_SYMBOL(tcf_chain_get);
@@ -267,8 +264,8 @@ int tcf_block_get(struct tcf_block **p_block,
INIT_LIST_HEAD(&block->chain_list);
/* Create chain 0 by default, it has to be always present. */
chain = tcf_chain_create(block, 0);
- if (!chain) {
- err = -ENOMEM;
+ if (IS_ERR(chain)) {
+ err = PTR_ERR(chain);
goto err_chain_create;
}
tcf_chain_filter_chain_ptr_set(chain, p_filter_chain);
@@ -517,8 +514,8 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
}
chain = tcf_chain_get(block, chain_index,
n->nlmsg_type == RTM_NEWTFILTER);
- if (!chain) {
- err = n->nlmsg_type == RTM_NEWTFILTER ? -ENOMEM : -EINVAL;
+ if (IS_ERR(chain)) {
+ err = PTR_ERR(chain);
goto errout;
}
--
2.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch net-next] net/sched: let chain_get to figure out the return value
2017-05-26 7:21 [patch net-next] net/sched: let chain_get to figure out the return value Jiri Pirko
@ 2017-05-26 14:59 ` David Miller
2017-05-27 9:54 ` Jiri Pirko
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2017-05-26 14:59 UTC (permalink / raw)
To: jiri; +Cc: netdev, jhs, xiyou.wangcong, mlxsw
From: Jiri Pirko <jiri@resnulli.us>
Date: Fri, 26 May 2017 09:21:29 +0200
> From: Jiri Pirko <jiri@mellanox.com>
>
> Alhough I believe that this create/nocreate dance is completelly
> pointless, at least make it a bit nicer and easier to read.
> Push the decision on what error value is returned to chain_get function
> and use ERR macros.
>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
No, this is quite worse.
You're leaving pointer error values in structures. That's extremely
error prone.
And as stated in the other thread, I don't think Cong's logic is strange
or hard to understand at all.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch net-next] net/sched: let chain_get to figure out the return value
2017-05-26 14:59 ` David Miller
@ 2017-05-27 9:54 ` Jiri Pirko
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2017-05-27 9:54 UTC (permalink / raw)
To: David Miller; +Cc: netdev, jhs, xiyou.wangcong, mlxsw
Fri, May 26, 2017 at 04:59:12PM CEST, davem@davemloft.net wrote:
>From: Jiri Pirko <jiri@resnulli.us>
>Date: Fri, 26 May 2017 09:21:29 +0200
>
>> From: Jiri Pirko <jiri@mellanox.com>
>>
>> Alhough I believe that this create/nocreate dance is completelly
>> pointless, at least make it a bit nicer and easier to read.
>> Push the decision on what error value is returned to chain_get function
>> and use ERR macros.
>>
>> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>
>No, this is quite worse.
>
>You're leaving pointer error values in structures. That's extremely
>error prone.
Yet used everywhere in kernel.
>
>And as stated in the other thread, I don't think Cong's logic is strange
>or hard to understand at all.
That is why tc code looks how it does :/
But perhaps I'm slow and everything is crystal-clear to everyone else.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-05-27 9:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-26 7:21 [patch net-next] net/sched: let chain_get to figure out the return value Jiri Pirko
2017-05-26 14:59 ` David Miller
2017-05-27 9:54 ` Jiri Pirko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).