Skip to contentSkip to conversation

netlink: avoid memset of 0 bytes sparse warning

PATCH Applied Patrick McHardy 2 participants 2 messages Nov 19, 2008 – Nov 20, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

commit d30196c4cab8442451794d25a8d8a072dadca2eb

Author: Patrick McHardy <[email protected]>
Date:   Wed Nov 19 14:55:11 2008 +0100

netlink: avoid memset of 0 bytes sparse warning

A netlink attribute padding of zero triggers this sparse warning:

include/linux/netlink.h:245:8: warning: memset with byte count of 0

Avoid the memset when the size parameter is constant and requires no padding.

include/linux/netlink.h +2 -1
index 9ff1b54..51b09a1 100644
@@ -242,7 +242,8 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)
 	nlh->nlmsg_flags = flags;
 	nlh->nlmsg_pid = pid;
 	nlh->nlmsg_seq = seq;
-	memset(NLMSG_DATA(nlh) + len, 0, NLMSG_ALIGN(size) - size);
+	if (!__builtin_constant_p(size) || NLMSG_ALIGN(size) - size != 0)
+		memset(NLMSG_DATA(nlh) + len, 0, NLMSG_ALIGN(size) - size);
 	return nlh;
 }
 
maintainer Applied
#1 lore raw

From: Patrick McHardy <[email protected]>
Date: Wed, 19 Nov 2008 14:56:12 +0100

Quoted 9 lines

netlink: avoid memset of 0 bytes sparse warning

A netlink attribute padding of zero triggers this sparse warning:

include/linux/netlink.h:245:8: warning: memset with byte count of 0

Avoid the memset when the size parameter is constant and requires no padding.

Applied to net-next-2.6, but I totally disagree with this sparse warning.

GCC even elides the memset entirely if it can determine the length is constant and 0.