aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlink/af_netlink.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2006-11-10 17:10:15 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:22:11 -0500
commit339bf98ffc6a8d8eb16fc532ac57ffbced2f8a68 (patch)
tree499ad948863d2753ca10283dcf006ad28954538e /net/netlink/af_netlink.c
parenta94f723d595ee085f81b1788d18e031af7eeba91 (diff)
[NETLINK]: Do precise netlink message allocations where possible
Account for the netlink message header size directly in nlmsg_new() instead of relying on the caller calculate it correctly. Replaces error handling of message construction functions when constructing notifications with bug traps since a failure implies a bug in calculating the size of the skb. Signed-off-by: Thomas Graf <tgraf@suug.ch> Acked-by: Paul Moore <paul.moore@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/netlink/af_netlink.c')
-rw-r--r--net/netlink/af_netlink.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index d527c8977b1f..f61d81b3c61c 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1148,7 +1148,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
1148 if (len > sk->sk_sndbuf - 32) 1148 if (len > sk->sk_sndbuf - 32)
1149 goto out; 1149 goto out;
1150 err = -ENOBUFS; 1150 err = -ENOBUFS;
1151 skb = nlmsg_new(len, GFP_KERNEL); 1151 skb = alloc_skb(len, GFP_KERNEL);
1152 if (skb==NULL) 1152 if (skb==NULL)
1153 goto out; 1153 goto out;
1154 1154
@@ -1435,14 +1435,13 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
1435 struct sk_buff *skb; 1435 struct sk_buff *skb;
1436 struct nlmsghdr *rep; 1436 struct nlmsghdr *rep;
1437 struct nlmsgerr *errmsg; 1437 struct nlmsgerr *errmsg;
1438 int size; 1438 size_t payload = sizeof(*errmsg);
1439 1439
1440 if (err == 0) 1440 /* error messages get the original request appened */
1441 size = nlmsg_total_size(sizeof(*errmsg)); 1441 if (err)
1442 else 1442 payload += nlmsg_len(nlh);
1443 size = nlmsg_total_size(sizeof(*errmsg) + nlmsg_len(nlh));
1444 1443
1445 skb = nlmsg_new(size, GFP_KERNEL); 1444 skb = nlmsg_new(payload, GFP_KERNEL);
1446 if (!skb) { 1445 if (!skb) {
1447 struct sock *sk; 1446 struct sock *sk;
1448 1447