Skip to contentSkip to conversation

kmemcheck: make bitfield annotations be valid C

PATCH In review Vegard Nossum 4 participants 6 messages May 15, 2009 – Jun 7, 2009

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

PATCH 1/1 kmemcheck: make bitfield annotations be valid C

Quoted 1 line

From bb8926742d87da95aeb373bc2d4b35a554c5001b Mon Sep 17 00:00:00 2001

From: Vegard Nossum <[email protected]>
Date: Fri, 15 May 2009 21:34:36 +0200
Subject: [PATCH] kmemcheck: make bitfield annotations be valid C

According to Al Viro, the syntax we were using (putting #ifdef inside macro arguments) was not valid C. He also suggested using begin/end markers instead, which is what we do now.

---
 drivers/ieee1394/csr1212.c       |    2 +-
 drivers/ieee1394/nodemgr.c       |    8 ++--
 drivers/misc/c2port/core.c       |    2 +-
 include/linux/c2port.h           |    8 ++--
 include/linux/kmemcheck.h        |   91 +++++++++++++++++++------------------
 include/linux/ring_buffer.h      |    6 +-
 include/linux/skbuff.h           |   34 +++++++-------
 include/net/inet_sock.h          |   22 +++++-----
 include/net/inet_timewait_sock.h |   12 +++---
 include/net/sock.h               |   10 ++--
 kernel/trace/ring_buffer.c       |    4 +-
 net/core/skbuff.c                |   12 +++---
 net/core/sock.c                  |    2 +-
 net/ipv4/inet_timewait_sock.c    |    2 +-
 14 files changed, 109 insertions(+), 106 deletions(-)
drivers/ieee1394/csr1212.c +1 -1
index 5e0fab1..e76cac6 100644
@@ -388,7 +388,7 @@ csr1212_new_descriptor_leaf(u8 dtype, u32 specifier_id,
 	if (!kv)
 		return NULL;
 
-	kmemcheck_annotate_bitfield(kv->value.leaf.data[0]);
+	kmemcheck_annotate_variable(kv->value.leaf.data[0]);
 	CSR1212_DESCRIPTOR_LEAF_SET_TYPE(kv, dtype);
 	CSR1212_DESCRIPTOR_LEAF_SET_SPECIFIER_ID(kv, specifier_id);
 
drivers/ieee1394/nodemgr.c +4 -4
index 065f249..5122b5a 100644
@@ -41,9 +41,9 @@ struct nodemgr_csr_info {
 	nodeid_t nodeid;
 	unsigned int generation;
 
-	kmemcheck_define_bitfield(flags, {
-		unsigned int speed_unverified:1;
-	});
+	kmemcheck_bitfield_begin(flags);
+	unsigned int speed_unverified:1;
+	kmemcheck_bitfield_end(flags);
 };
 
 
@@ -1297,9 +1297,9 @@ static void nodemgr_node_scan_one(struct hpsb_host *host,
 	u8 *speed;
 
 	ci = kmalloc(sizeof(*ci), GFP_KERNEL);
+	kmemcheck_annotate_bitfield(ci, flags);
 	if (!ci)
 		return;
-	kmemcheck_annotate_bitfield(ci->flags);
 
 	ci->host = host;
 	ci->nodeid = nodeid;
drivers/misc/c2port/core.c +1 -1
index fc15042..b5346b4 100644
@@ -892,9 +892,9 @@ struct c2port_device *c2port_device_register(char *name,
 		return ERR_PTR(-EINVAL);
 
 	c2dev = kmalloc(sizeof(struct c2port_device), GFP_KERNEL);
+	kmemcheck_annotate_bitfield(c2dev, flags);
 	if (unlikely(!c2dev))
 		return ERR_PTR(-ENOMEM);
-	kmemcheck_annotate_bitfield(c2dev->flags);
 
 	ret = idr_pre_get(&c2port_idr, GFP_KERNEL);
 	if (!ret) {
include/linux/c2port.h +4 -4
index 2556499..2a5cd86 100644
@@ -21,10 +21,10 @@
 /* Main struct */
 struct c2port_ops;
 struct c2port_device {
-	kmemcheck_define_bitfield(flags, {
-		unsigned int access:1;
-		unsigned int flash_access:1;
-	});
+	kmemcheck_bitfield_begin(flags);
+	unsigned int access:1;
+	unsigned int flash_access:1;
+	kmemcheck_bitfield_end(flags);
 
 	int id;
 	char name[C2PORT_NAME_LEN];
include/linux/kmemcheck.h +47 -44

109 lines not on this page · raw message

include/linux/ring_buffer.h +3 -3
index ae5b210..771ee90 100644
@@ -12,9 +12,9 @@ struct ring_buffer_iter;
  * Don't refer to this struct directly, use functions below.
  */
 struct ring_buffer_event {
-	kmemcheck_define_bitfield(bitfield, {
-		u32		type:2, len:3, time_delta:27;
-	});
+	kmemcheck_bitfield_begin(bitfield);
+	u32		type:2, len:3, time_delta:27;
+	kmemcheck_bitfield_end(bitfield);
 
 	u32		array[];
 };
include/linux/skbuff.h +17 -17
index e0ce2e0..ed6537f 100644
@@ -347,18 +347,18 @@ struct sk_buff {
 		};
 	};
 	__u32			priority;
-	kmemcheck_define_bitfield(flags1, {
-		__u8			local_df:1,
-					cloned:1,
-					ip_summed:2,
-					nohdr:1,
-					nfctinfo:3;
-		__u8			pkt_type:3,
-					fclone:2,
-					ipvs_property:1,
-					peeked:1,
-					nf_trace:1;
-	});
+	kmemcheck_bitfield_begin(flags1);
+	__u8			local_df:1,
+				cloned:1,
+				ip_summed:2,
+				nohdr:1,
+				nfctinfo:3;
+	__u8			pkt_type:3,
+				fclone:2,
+				ipvs_property:1,
+				peeked:1,
+				nf_trace:1;
+	kmemcheck_bitfield_end(flags1);
 	__be16			protocol;
 
 	void			(*destructor)(struct sk_buff *skb);
@@ -379,15 +379,15 @@ struct sk_buff {
 #endif
 #endif
 
-	kmemcheck_define_bitfield(flags2, {
+	kmemcheck_bitfield_begin(flags2);
 #ifdef CONFIG_IPV6_NDISC_NODETYPE
-		__u8			ndisc_nodetype:2;
+	__u8			ndisc_nodetype:2;
 #endif
 #if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE)
-		__u8			do_not_encrypt:1;
-		__u8			requeue:1;
+	__u8			do_not_encrypt:1;
+	__u8			requeue:1;
 #endif
-	});
+	kmemcheck_bitfield_end(flags2);
 
 	/* 0/13/14 bit hole */
 
include/net/inet_sock.h +11 -11
index 9d172f7..cbcda0b 100644
@@ -67,16 +67,16 @@ struct inet_request_sock {
 	__be32			loc_addr;
 	__be32			rmt_addr;
 	__be16			rmt_port;
-	kmemcheck_define_bitfield(flags, {
-		u16			snd_wscale : 4,
-					rcv_wscale : 4,
-					tstamp_ok  : 1,
-					sack_ok	   : 1,
-					wscale_ok  : 1,
-					ecn_ok	   : 1,
-					acked	   : 1,
-					no_srccheck: 1;
-	});
+	kmemcheck_bitfield_begin(flags);
+	u16			snd_wscale : 4,
+				rcv_wscale : 4,
+				tstamp_ok  : 1,
+				sack_ok	   : 1,
+				wscale_ok  : 1,
+				ecn_ok	   : 1,
+				acked	   : 1,
+				no_srccheck: 1;
+	kmemcheck_bitfield_end(flags);
 	struct ip_options	*opt;
 };
 
@@ -204,7 +204,7 @@ static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops
 	struct inet_request_sock *ireq = inet_rsk(req);
 
 	if (req != NULL) {
-		kmemcheck_annotate_bitfield(ireq->flags);
+		kmemcheck_annotate_bitfield(ireq, flags);
 		ireq->opt = NULL;
 	}
 
include/net/inet_timewait_sock.h +6 -6
index a88cb10..b63b80f 100644
@@ -128,12 +128,12 @@ struct inet_timewait_sock {
 	__be32			tw_rcv_saddr;
 	__be16			tw_dport;
 	__u16			tw_num;
-	kmemcheck_define_bitfield(flags, {
-		/* And these are ours. */
-		__u8			tw_ipv6only:1,
-					tw_transparent:1;
-		/* 14 bits hole, try to pack */
-	});
+	kmemcheck_bitfield_begin(flags);
+	/* And these are ours. */
+	__u8			tw_ipv6only:1,
+				tw_transparent:1;
+	/* 14 bits hole, try to pack */
+	kmemcheck_bitfield_end(flags);
 	__u16			tw_ipv6_offset;
 	unsigned long		tw_ttd;
 	struct inet_bind_bucket	*tw_tb;
include/net/sock.h +5 -5
index da2ea5f..d933da0 100644
@@ -218,11 +218,11 @@ struct sock {
 #define sk_hash			__sk_common.skc_hash
 #define sk_prot			__sk_common.skc_prot
 #define sk_net			__sk_common.skc_net
-	kmemcheck_define_bitfield(flags, {
-		unsigned char		sk_shutdown : 2,
-					sk_no_check : 2,
-					sk_userlocks : 4;
-	});
+	kmemcheck_bitfield_begin(flags);
+	unsigned char		sk_shutdown : 2,
+				sk_no_check : 2,
+				sk_userlocks : 4;
+	kmemcheck_bitfield_end(flags);
 	unsigned char		sk_protocol;
 	unsigned short		sk_type;
 	int			sk_rcvbuf;
kernel/trace/ring_buffer.c +2 -2
index d26c74a..c22506f 100644
@@ -1259,7 +1259,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
 		if (tail < BUF_PAGE_SIZE) {
 			/* Mark the rest of the page with padding */
 			event = __rb_page_index(tail_page, tail);
-			kmemcheck_annotate_bitfield(event->bitfield);
+			kmemcheck_annotate_bitfield(event, bitfield);
 			rb_event_set_padding(event);
 		}
 
@@ -1289,7 +1289,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
 		return NULL;
 
 	event = __rb_page_index(tail_page, tail);
-	kmemcheck_annotate_bitfield(event->bitfield);
+	kmemcheck_annotate_bitfield(event, bitfield);
 	rb_update_event(event, type, length);
 
 	/*
net/core/skbuff.c +6 -6
index 8052d32..54d3e2f 100644
@@ -202,8 +202,8 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
 	skb->data = data;
 	skb_reset_tail_pointer(skb);
 	skb->end = skb->tail + size;
-	kmemcheck_annotate_bitfield(skb->flags1);
-	kmemcheck_annotate_bitfield(skb->flags2);
+	kmemcheck_annotate_bitfield(skb, flags1);
+	kmemcheck_annotate_bitfield(skb, flags2);
 	/* make sure we initialize shinfo sequentially */
 	shinfo = skb_shinfo(skb);
 	atomic_set(&shinfo->dataref, 1);
@@ -220,8 +220,8 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
 		struct sk_buff *child = skb + 1;
 		atomic_t *fclone_ref = (atomic_t *) (child + 1);
 
-		kmemcheck_annotate_bitfield(child->flags1);
-		kmemcheck_annotate_bitfield(child->flags2);
+		kmemcheck_annotate_bitfield(child, flags1);
+		kmemcheck_annotate_bitfield(child, flags2);
 		skb->fclone = SKB_FCLONE_ORIG;
 		atomic_set(fclone_ref, 1);
 
@@ -637,8 +637,8 @@ struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
 		if (!n)
 			return NULL;
 
-		kmemcheck_annotate_bitfield(n->flags1);
-		kmemcheck_annotate_bitfield(n->flags2);
+		kmemcheck_annotate_bitfield(n, flags1);
+		kmemcheck_annotate_bitfield(n, flags2);
 		n->fclone = SKB_FCLONE_UNAVAILABLE;
 	}
 
net/core/sock.c +1 -1
index 9730820..ce72c0a 100644
@@ -941,7 +941,7 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
 		sk = kmalloc(prot->obj_size, priority);
 
 	if (sk != NULL) {
-		kmemcheck_annotate_bitfield(sk->flags);
+		kmemcheck_annotate_bitfield(sk, flags);
 
 		if (security_sk_alloc(sk, family, priority))
 			goto out_free;
net/ipv4/inet_timewait_sock.c +1 -1
index 3369237..03169fc 100644
@@ -118,7 +118,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat
 	if (tw != NULL) {
 		const struct inet_sock *inet = inet_sk(sk);
 
-		kmemcheck_annotate_bitfield(tw->flags);
+		kmemcheck_annotate_bitfield(tw, flags);
 
 		/* Give us an identity. */
 		tw->tw_daddr	    = inet->daddr;
Signature · 1 line
1.6.0.6
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Vegard Nossum

From bb8926742d87da95aeb373bc2d4b35a554c5001b Mon Sep 17 00:00:00 2001
From: Vegard Nossum <[email protected]>
Date: Fri, 15 May 2009 21:34:36 +0200
Subject: [PATCH] kmemcheck: make bitfield annotations be valid C

According to Al Viro, the syntax we were using (putting #ifdef inside macro arguments) was not valid C. He also suggested using begin/end markers instead, which is what we do now.

Al, are you okay with this?

#2 lore raw

(adding viro to cc)

Quoted 17 lines · Pekka Enberg
Quoted 11 lines · Vegard Nossum

From bb8926742d87da95aeb373bc2d4b35a554c5001b Mon Sep 17 00:00:00 2001
From: Vegard Nossum <[email protected]>
Date: Fri, 15 May 2009 21:34:36 +0200
Subject: [PATCH] kmemcheck: make bitfield annotations be valid C

According to Al Viro, the syntax we were using (putting #ifdef inside macro arguments) was not valid C. He also suggested using begin/end markers instead, which is what we do now.

Al, are you okay with this?

#3 lore raw
In reply to Pekka Enberg
Quoted 10 lines · Pekka Enberg
Quoted 9 lines · Vegard Nossum

From bb8926742d87da95aeb373bc2d4b35a554c5001b Mon Sep 17 00:00:00 2001
From: Vegard Nossum <[email protected]>
Date: Fri, 15 May 2009 21:34:36 +0200
Subject: [PATCH] kmemcheck: make bitfield annotations be valid C

According to Al Viro, the syntax we were using (putting #ifdef inside macro arguments) was not valid C. He also suggested using begin/end markers instead, which is what we do now.

Quoted 6 lines
Quoted 2 lines

Al, are you okay with this?

Looks sane

#4 lore raw
Quoted 11 lines · Al Viro
Quoted 10 lines · Pekka Enberg
Quoted 9 lines · Vegard Nossum

From bb8926742d87da95aeb373bc2d4b35a554c5001b Mon Sep 17 00:00:00 2001
From: Vegard Nossum <[email protected]>
Date: Fri, 15 May 2009 21:34:36 +0200
Subject: [PATCH] kmemcheck: make bitfield annotations be valid C

According to Al Viro, the syntax we were using (putting #ifdef inside macro arguments) was not valid C. He also suggested using begin/end markers instead, which is what we do now.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Al, are you okay with this?

Looks sane

Thanks.

This removes the blocker bug from kmemcheck and we can try to push it in the .31 merge window. Does the level and amount of bit-field annotations look unduly troublesome to you? If we merge kmemcheck then we'll have these type annotations forever.

Ingo

#5 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

According to Al Viro, the syntax we were using (putting #ifdef inside macro arguments) was not valid C. He also suggested using begin/end markers instead, which is what we do now.

Al, are you okay with this?

Quoted 8 lines
Quoted 1 line

Looks sane

Thanks.

This removes the blocker bug from kmemcheck and we can try to push it in the .31 merge window. Does the level and amount of bit-field annotations look unduly troublesome to you? If we merge kmemcheck then we'll have these type annotations forever.

What had been posted in this thread didn't look over the top for me, but it's really a question for maintainers of the affected code...