Patchwork fix BUILD_BUG_ON() and a couple of bogus uses of it

login
register
mail settings
Submitter Andrew Morton
Date Sept. 18, 2009, 12:15 a.m.
Message ID <20090917171504.649ba29b.akpm@linux-foundation.org>
Download mbox | patch
Permalink /patch/33810/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Andrew Morton - Sept. 18, 2009, 12:15 a.m.
On Thu, 17 Sep 2009 17:01:56 -0700 (PDT)
David Miller <davem@davemloft.net> wrote:

> From: Andrew Morton <akpm@linux-foundation.org>
> Date: Thu, 17 Sep 2009 16:24:37 -0700
> 
> > sparc64:
> > 
> > In file included from arch/sparc/kernel/vio.c:17:
> > /usr/src/devel/arch/sparc/include/asm/vio.h: In function `vio_dring_avail':
> > /usr/src/devel/arch/sparc/include/asm/vio.h:261: error: bit-field `<anonymous>' width not an integer constant
> > 
> > static inline u32 vio_dring_avail(struct vio_dring_state *dr,
> > 				  unsigned int ring_size)
> > {
> > 	BUILD_BUG_ON(!is_power_of_2(ring_size));
> > 
> > 	return (dr->pending -
> > 		((dr->prod - dr->cons) & (ring_size - 1)));
> > }
> > 
> > changing it to MAYBE_BUILD_BUG_ON seems to have fixed it.
> 
> That's completely bogus.
> 
> First of all, arch/sparc/kernel/vio.c never calls this function
> so it should never be evaluated.
> 
> Second of all, all the places that do call this function only
> pass pure constants as the 'ring_size' parameter.
> 
> drivers/block/sunvdc.c:
> 
> static inline u32 vdc_tx_dring_avail(struct vio_dring_state *dr)
> {
> 	return vio_dring_avail(dr, VDC_TX_RING_SIZE);
> }
> 
> drivers/net/sunvnet.c:
> 
> static inline u32 vnet_tx_dring_avail(struct vio_dring_state *dr)
> {
> 	return vio_dring_avail(dr, VNET_TX_RING_SIZE);
> }
> 
> Making this MAYBE_BUILD_BUG_ON shouldn't be necessary.

There's a shortcoming in the current BUILD_BUG_ON() - it silently does
nothing if passed a non-constant arg.

I suspect that in the 2.6.31 code, that BUILD_BUG_ON() just does
nothing at all, and that Jan's patch is now exposing this.  It might be
compiler-version dependent too.


<tests it>

Yup, on base 2.6.31, this:
Andrew Morton - Sept. 18, 2009, 12:18 a.m.
On Thu, 17 Sep 2009 17:15:04 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:

> There's a shortcoming in the current BUILD_BUG_ON() - it silently does
> nothing if passed a non-constant arg.
> 
> I suspect that in the 2.6.31 code, that BUILD_BUG_ON() just does
> nothing at all, and that Jan's patch is now exposing this.  It might be
> compiler-version dependent too.
> 
> 
> <tests it>
> 
> Yup, on base 2.6.31, this:
> 
> --- a/arch/sparc/kernel/vio.c~a
> +++ a/arch/sparc/kernel/vio.c
> @@ -23,6 +23,8 @@ static const struct vio_device_id *vio_m
>  	const char *type, *compat;
>  	int len;
>  
> +	vio_dring_avail(NULL, 33);
> +
>  	type = dev->type;
>  	compat = dev->compat;
>  	len = dev->compat_len;
> _
> 
> compiles without error with gcc-3.4.5.

And I can't immediately find a way to make any compile-time error occur here, with
or without Jan's patch.  hm.

--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Sept. 18, 2009, 12:31 a.m.
From: Andrew Morton <akpm@linux-foundation.org>
Date: Thu, 17 Sep 2009 17:15:04 -0700

> There's a shortcoming in the current BUILD_BUG_ON() - it silently does
> nothing if passed a non-constant arg.
> 
> I suspect that in the 2.6.31 code, that BUILD_BUG_ON() just does
> nothing at all, and that Jan's patch is now exposing this.  It might be
> compiler-version dependent too.
> 
> 
> <tests it>
> 
> Yup, on base 2.6.31, this:

Ok, I'll have to either change this function to a macro or
get rid of the check.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - Sept. 18, 2009, 12:45 a.m.
From: David Miller <davem@davemloft.net>
Date: Thu, 17 Sep 2009 17:31:54 -0700 (PDT)

> From: Andrew Morton <akpm@linux-foundation.org>
> Date: Thu, 17 Sep 2009 17:15:04 -0700
> 
>> There's a shortcoming in the current BUILD_BUG_ON() - it silently does
>> nothing if passed a non-constant arg.
>> 
>> I suspect that in the 2.6.31 code, that BUILD_BUG_ON() just does
>> nothing at all, and that Jan's patch is now exposing this.  It might be
>> compiler-version dependent too.
>> 
>> 
>> <tests it>
>> 
>> Yup, on base 2.6.31, this:
> 
> Ok, I'll have to either change this function to a macro or
> get rid of the check.

I can't even get GCC to see the constant evaluated by is_power_of_2().

I give up, I'll just remove the BUILD_BUG_ON() entirely.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

--- a/arch/sparc/kernel/vio.c~a
+++ a/arch/sparc/kernel/vio.c
@@ -23,6 +23,8 @@  static const struct vio_device_id *vio_m
 	const char *type, *compat;
 	int len;
 
+	vio_dring_avail(NULL, 33);
+
 	type = dev->type;
 	compat = dev->compat;
 	len = dev->compat_len;