lkml.org 
[lkml]   [2008]   [Aug]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH] bitfields API
On Thu, Aug 28, 2008 at 9:02 PM, Pekka J Enberg <penberg@cs.helsinki.fi> wrote:
> Why not do something like this (as suggested by Ingo, I think)? Yeah, the
> macro should go into kmemcheck.h but I don't have a tree handy...
>
> Pekka
>
> Index: linux-2.6/include/linux/bitfield.h
> ===================================================================
> --- /dev/null
> +++ linux-2.6/include/linux/bitfield.h
> @@ -0,0 +1,10 @@
> +#ifndef __LINUX_BITFIELD_H
> +#define __LINUX_BITFIELD_H
> +
> +#ifdef CONFIG_KMEMCHECK
> +#define KMEMCHECK_BIT_FIELD(field) do { field = 0; } while (0)
> +#else
> +#define KMEMCHECK_BIT_FIELD(field) do { } while (0)
> +#endif /* CONFIG_KMEMCHECK */
> +
> +#endif /* __LINUX_BITFIELD_H */
>
> Index: linux-2.6/net/core/skbuff.c
> ===================================================================
> --- linux-2.6.orig/net/core/skbuff.c
> +++ linux-2.6/net/core/skbuff.c
> @@ -55,6 +55,7 @@
> #include <linux/rtnetlink.h>
> #include <linux/init.h>
> #include <linux/scatterlist.h>
> +#include <linux/bitfield.h>
>
> #include <net/protocol.h>
> #include <net/dst.h>
> @@ -209,6 +210,11 @@ struct sk_buff *__alloc_skb(unsigned int
> skb->data = data;
> skb_reset_tail_pointer(skb);
> skb->end = skb->tail + size;
> + KMEMCHECK_BIT_FIELD(skb->local_df);
> + KMEMCHECK_BIT_FIELD(skb->cloned);
> + KMEMCHECK_BIT_FIELD(skb->ip_summed);
> + KMEMCHECK_BIT_FIELD(skb->nohdr);
> + KMEMCHECK_BIT_FIELD(skb->nfctinfo);
> /* make sure we initialize shinfo sequentially */
> shinfo = skb_shinfo(skb);
> atomic_set(&shinfo->dataref, 1);
>

That looks good to me. If the extra lines are okay with net people, we
can put this in the fixlets branch and make it the norm for dealing
with bitfields in kmemcheck.

One thing to keep in mind that if the members of the bitfield does not
span the entire width of the bitfield, the remaining bits must also be
assigned (as an extra "filler" member), otherwise GCC will not
optimize it to a single store. But that is not an issue in this
particular case since all the bits are used.


Vegard

--
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
-- E. W. Dijkstra, EWD1036


\
 
 \ /
  Last update: 2008-08-28 21:43    [W:0.041 / U:7.716 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site