net: Use nlmsg_{multicast, unicast} that contain if statement
Subsystems (2)
cover net: Use nlmsg_{multicast, unicast} that contain if statement
Patch1: use nlmsg_{multicast, unicast} instead of netlink_ {broadcast,unicast} in rtnetlink.
Patch2: The caller no need deal with the if statements and use the rename function.
Yajun Deng (2):
rtnetlink: use nlmsg_{multicast, unicast} instead of
netlink_{broadcast,unicast}net/sched: Remove unnecessary judgment statements
include/linux/rtnetlink.h | 2 +- net/core/rtnetlink.c | 13 +++++++------ net/sched/act_api.c | 20 ++++++-------------- net/sched/cls_api.c | 28 +++++++++++----------------- net/sched/sch_api.c | 18 ++++++------------ 5 files changed, 31 insertions(+), 50 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/2 rtnetlink: use nlmsg_{multicast, unicast} instead of netlink_{broadcast,unicast}
It has a 'NETLINK_CB(' statement in nlmsg_multicast() and has 'if (err' in nlmsg_{multicast, unicast}, use nlmsg_{multicast, unicast} instead of netlink_{broadcast,unicast}. so the caller would not deal with the 'if (err >0 )' statement. Add the return value for nlmsg_multicast. As also, rename rtnetlink_send() to rtnl_send(), this makes style uniform.
--- include/linux/rtnetlink.h | 2 +- net/core/rtnetlink.c | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-)
include/linux/rtnetlink.h +1 -1
@@ -9,7 +9,7 @@#include <linux/refcount.h> #include <uapi/linux/rtnetlink.h> -extern int rtnetlink_send (struct sk_buff *skb,struct net *net,u32 pid,u32 group,int echo); +extern int rtnl_send (struct sk_buff *skb,struct net *net,u32 pid,u32 group,int echo);extern int rtnl_unicast (struct sk_buff *skb,struct net *net,u32 pid);extern void rtnl_notify (struct sk_buff *skb,struct net *net,u32 pid,u32 group,struct nlmsghdr *nlh,gfp_t flags);
net/core/rtnetlink.c +7 -6
@@ -707,17 +707,18 @@ static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)return err; } -int rtnetlink_send (struct sk_buff *skb,struct net *net,u32 pid,unsigned int group,int echo) +int rtnl_send (struct sk_buff *skb,struct net *net,u32 pid,unsigned int group,int echo) {struct sock *rtnl = net->rtnl;int err =0 ; -NETLINK_CB (skb).dst_group = group; -if (echo) + err =nlmsg_multicast (rtnl, skb, pid, group,GFP_KERNEL ); + +if (echo) {refcount_inc (&skb->users); -netlink_broadcast (rtnl, skb, pid, group,GFP_KERNEL ); -if (echo) - err =netlink_unicast (rtnl, skb, pid,MSG_DONTWAIT ); + err =nlmsg_unicast (rtnl, skb, pid); + } +return err; }
Signature · 1 line
2.32.0
Re: [PATCH 1/2] rtnetlink: use nlmsg_{multicast, unicast} instead of netlink_{broadcast,unicast}
Quoted 37 lines · Yajun Deng
It has a 'NETLINK_CB(' statement in
nlmsg_multicast()and has 'if (err' in nlmsg_{multicast, unicast}, use nlmsg_{multicast, unicast} instead of netlink_{broadcast,unicast}. so the caller would not deal with the 'if (err >0 )' statement. Add the return value fornlmsg_multicast. As also, renamertnetlink_send()tortnl_send(), this makes style uniform.Signed-off-by Yajun Deng <[email protected]>--- include/linux/rtnetlink.h | 2 +- net/core/rtnetlink.c | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-)include/linux/rtnetlink.h +1
-1@@ -9,7 +9,7 @@#include <linux/refcount.h> #include <uapi/linux/rtnetlink.h> -extern int rtnetlink_send (struct sk_buff *skb,struct net *net,u32 pid,u32 group,int echo); +extern int rtnl_send (struct sk_buff *skb,struct net *net,u32 pid,u32 group,int echo);extern int rtnl_unicast (struct sk_buff *skb,struct net *net,u32 pid);extern void rtnl_notify (struct sk_buff *skb,struct net *net,u32 pid,u32 group,struct nlmsghdr *nlh,gfp_t flags);net/core/rtnetlink.c +1
-1@@ -707,17 +707,18 @@ static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)return err; } -int rtnetlink_send (struct sk_buff *skb,struct net *net,u32 pid,unsigned int group,int echo) +int rtnl_send (struct sk_buff *skb,struct net *net,u32 pid,unsigned int group,int echo)
net/core/rtnetlink.c static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev) · line 718
Quoted 10 lines
net/core/rtnetlink.c +3
-2{struct sock *rtnl = net->rtnl;int err =0 ; -NETLINK_CB (skb).dst_group = group; -if (echo) + err =nlmsg_multicast (rtnl, skb, pid, group,GFP_KERNEL ); + +if (echo) {refcount_inc (&skb->users);
You also moved this refcount_inc() down after nlmsg_multicast(). Are you sure it is safe?
And the name rtnl_send() is bad given that rtnl_unicast() follows it...
Thanks.