* netlink: avoid memset of 0 bytes sparse warning
@ 2008-11-19 13:56 Patrick McHardy
2008-11-20 12:09 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Patrick McHardy @ 2008-11-19 13:56 UTC (permalink / raw)
To: David S. Miller; +Cc: Linux Netdev List
[-- Attachment #1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2: 01.diff --]
[-- Type: text/x-patch, Size: 1022 bytes --]
commit d30196c4cab8442451794d25a8d8a072dadca2eb
Author: Patrick McHardy <kaber@trash.net>
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.
Signed-off-by: Patrick McHardy <kaber@trash.net>
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 9ff1b54..51b09a1 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -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;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: netlink: avoid memset of 0 bytes sparse warning
2008-11-19 13:56 netlink: avoid memset of 0 bytes sparse warning Patrick McHardy
@ 2008-11-20 12:09 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2008-11-20 12:09 UTC (permalink / raw)
To: kaber; +Cc: netdev
From: Patrick McHardy <kaber@trash.net>
Date: Wed, 19 Nov 2008 14:56:12 +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.
>
> Signed-off-by: Patrick McHardy <kaber@trash.net>
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-11-20 12:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19 13:56 netlink: avoid memset of 0 bytes sparse warning Patrick McHardy
2008-11-20 12:09 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).