Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: netlink: add the case when nlh is NULL

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>

authored by

Yajun Deng and committed by
David S. Miller
f9b282b3 b0e81817

+6 -11
+1 -1
include/net/netlink.h
··· 885 885 */ 886 886 static inline int nlmsg_report(const struct nlmsghdr *nlh) 887 887 { 888 - return !!(nlh->nlmsg_flags & NLM_F_ECHO); 888 + return nlh ? !!(nlh->nlmsg_flags & NLM_F_ECHO) : 0; 889 889 } 890 890 891 891 /**
+1 -5
net/core/rtnetlink.c
··· 726 726 struct nlmsghdr *nlh, gfp_t flags) 727 727 { 728 728 struct sock *rtnl = net->rtnl; 729 - int report = 0; 730 729 731 - if (nlh) 732 - report = nlmsg_report(nlh); 733 - 734 - nlmsg_notify(rtnl, skb, pid, group, report, flags); 730 + nlmsg_notify(rtnl, skb, pid, group, nlmsg_report(nlh), flags); 735 731 } 736 732 EXPORT_SYMBOL(rtnl_notify); 737 733
+4 -5
net/netlink/genetlink.c
··· 1485 1485 { 1486 1486 if (WARN_ON_ONCE(group >= family->n_mcgrps)) 1487 1487 return -EINVAL; 1488 + 1488 1489 group = family->mcgrp_offset + group; 1489 1490 return genlmsg_mcast(skb, portid, group, flags); 1490 1491 } ··· 1496 1495 { 1497 1496 struct net *net = genl_info_net(info); 1498 1497 struct sock *sk = net->genl_sock; 1499 - int report = 0; 1500 - 1501 - if (info->nlhdr) 1502 - report = nlmsg_report(info->nlhdr); 1503 1498 1504 1499 if (WARN_ON_ONCE(group >= family->n_mcgrps)) 1505 1500 return; 1501 + 1506 1502 group = family->mcgrp_offset + group; 1507 - nlmsg_notify(sk, skb, info->snd_portid, group, report, flags); 1503 + nlmsg_notify(sk, skb, info->snd_portid, group, 1504 + nlmsg_report(info->nlhdr), flags); 1508 1505 } 1509 1506 EXPORT_SYMBOL(genl_notify);