From: Thomas Graf Date: Sat, 25 Nov 2006 01:14:07 +0000 (-0800) Subject: [DECNET] address: Calculate accurate message size for netlink notifications X-Git-Tag: v2.6.20-rc1~34^2~40^2~157 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=a6f01cace3a6532c6f22d8e2fdefed3632ea61b2;p=karo-tx-linux.git [DECNET] address: Calculate accurate message size for netlink notifications Signed-off-by: Thomas Graf Signed-off-by: David S. Miller --- diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c index 5b451e196fb9..2459a8d236a0 100644 --- a/net/decnet/dn_dev.c +++ b/net/decnet/dn_dev.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -711,6 +711,14 @@ static int dn_dev_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *a return rv; } +static inline size_t dn_ifaddr_nlmsg_size(void) +{ + return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) + + nla_total_size(IFNAMSIZ) /* IFA_LABEL */ + + nla_total_size(2) /* IFA_ADDRESS */ + + nla_total_size(2); /* IFA_LOCAL */ +} + static int dn_dev_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa, u32 pid, u32 seq, int event, unsigned int flags) { @@ -744,18 +752,15 @@ rtattr_failure: static void rtmsg_ifa(int event, struct dn_ifaddr *ifa) { struct sk_buff *skb; - int payload = sizeof(struct ifaddrmsg) + 128; int err = -ENOBUFS; - skb = alloc_skb(nlmsg_total_size(payload), GFP_KERNEL); + skb = alloc_skb(dn_ifaddr_nlmsg_size(), GFP_KERNEL); if (skb == NULL) goto errout; err = dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0); - if (err < 0) { - kfree_skb(skb); - goto errout; - } + /* failure implies BUG in dn_ifaddr_nlmsg_size() */ + BUG_ON(err < 0); err = rtnl_notify(skb, 0, RTNLGRP_DECnet_IFADDR, NULL, GFP_KERNEL); errout: