]> www.infradead.org Git - users/willy/linux.git/commitdiff
net: netlink: add the case when nlh is NULL
authorYajun Deng <yajun.deng@linux.dev>
Tue, 27 Jul 2021 03:41:41 +0000 (11:41 +0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 27 Jul 2021 10:43:50 +0000 (11:43 +0100)
Add the case when nlh is NULL in nlmsg_report(),
so that the caller doesn't need to deal with this case.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netlink.h
net/core/rtnetlink.c
net/netlink/genetlink.c

index 1ceec518ab497c2c9ced5059f2f1f5a8fb6f7873..7a2a9d3144ba6c32777594d5585597948f480404 100644 (file)
@@ -885,7 +885,7 @@ static inline int nlmsg_validate_deprecated(const struct nlmsghdr *nlh,
  */
 static inline int nlmsg_report(const struct nlmsghdr *nlh)
 {
-       return !!(nlh->nlmsg_flags & NLM_F_ECHO);
+       return nlh ? !!(nlh->nlmsg_flags & NLM_F_ECHO) : 0;
 }
 
 /**
index 670d74ab91ae0299407536d16817ff86776cc5f4..e79aaf1f713904f02bd69e49f5a7b7782ba4208a 100644 (file)
@@ -726,12 +726,8 @@ void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
                 struct nlmsghdr *nlh, gfp_t flags)
 {
        struct sock *rtnl = net->rtnl;
-       int report = 0;
 
-       if (nlh)
-               report = nlmsg_report(nlh);
-
-       nlmsg_notify(rtnl, skb, pid, group, report, flags);
+       nlmsg_notify(rtnl, skb, pid, group, nlmsg_report(nlh), flags);
 }
 EXPORT_SYMBOL(rtnl_notify);
 
index 2d6fdf40df66687836daff1c6c7a7a07dad9add9..ae58da608a31184c75ac89de9f380465f2540a51 100644 (file)
@@ -1485,6 +1485,7 @@ int genlmsg_multicast_allns(const struct genl_family *family,
 {
        if (WARN_ON_ONCE(group >= family->n_mcgrps))
                return -EINVAL;
+
        group = family->mcgrp_offset + group;
        return genlmsg_mcast(skb, portid, group, flags);
 }
@@ -1495,14 +1496,12 @@ void genl_notify(const struct genl_family *family, struct sk_buff *skb,
 {
        struct net *net = genl_info_net(info);
        struct sock *sk = net->genl_sock;
-       int report = 0;
-
-       if (info->nlhdr)
-               report = nlmsg_report(info->nlhdr);
 
        if (WARN_ON_ONCE(group >= family->n_mcgrps))
                return;
+
        group = family->mcgrp_offset + group;
-       nlmsg_notify(sk, skb, info->snd_portid, group, report, flags);
+       nlmsg_notify(sk, skb, info->snd_portid, group,
+                    nlmsg_report(info->nlhdr), flags);
 }
 EXPORT_SYMBOL(genl_notify);