public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix sparse problems with ARRAY_SIZE
@ 2007-07-10 16:05 Adel Gadllah
  2007-07-10 16:09 ` Adel Gadllah
  0 siblings, 1 reply; 6+ messages in thread
From: Adel Gadllah @ 2007-07-10 16:05 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 253 bytes --]

ARRAY_SIZE seems to create sparse warnings when used on global 
variables. The attached patch fixes this by using a ARRAY_SIZE macro 
that does not use __must_be_array(arr) for sparse.
See: http://marc.info/?t=118103449100007&r=1&w=2

P.S: please CC me

[-- Attachment #2: array_size_sparse_fix.patch --]
[-- Type: text/x-patch, Size: 727 bytes --]

Signed-off-by: Adel Gadllah <adel.gadllah@gmail.com>

diff -upNr linux-2.6.orig/include/linux/kernel.h linux-2.6/include/linux/kernel.h
--- linux-2.6.orig/include/linux/kernel.h	2007-07-10 17:53:39.000000000 +0200
+++ linux-2.6/include/linux/kernel.h	2007-07-10 18:01:30.000000000 +0200
@@ -35,7 +35,11 @@ extern const char linux_proc_banner[];
 #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
 
+#ifdef __CHECKER_
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((x)[0]))
+#else
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#endif
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fix sparse problems with ARRAY_SIZE
  2007-07-10 16:05 [PATCH] fix sparse problems with ARRAY_SIZE Adel Gadllah
@ 2007-07-10 16:09 ` Adel Gadllah
  2007-07-10 19:40   ` Alexey Dobriyan
  0 siblings, 1 reply; 6+ messages in thread
From: Adel Gadllah @ 2007-07-10 16:09 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 315 bytes --]

Adel Gadllah wrote:
> ARRAY_SIZE seems to create sparse warnings when used on global 
> variables. The attached patch fixes this by using a ARRAY_SIZE macro 
> that does not use __must_be_array(arr) for sparse.
> See: http://marc.info/?t=118103449100007&r=1&w=2
>
> P.S: please CC me
resend the working one sorry.


[-- Attachment #2: array_size_sparse_fix.patch --]
[-- Type: text/x-patch, Size: 729 bytes --]

Signed-off-by: Adel Gadllah <adel.gadllah@gmail.com>

diff -upNr linux-2.6.orig/include/linux/kernel.h linux-2.6/include/linux/kernel.h
--- linux-2.6.orig/include/linux/kernel.h	2007-07-10 17:53:39.000000000 +0200
+++ linux-2.6/include/linux/kernel.h	2007-07-10 18:01:30.000000000 +0200
@@ -35,7 +35,11 @@ extern const char linux_proc_banner[];
 #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
 
+#ifdef __CHECKER_
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#else
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#endif
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fix sparse problems with ARRAY_SIZE
  2007-07-10 16:09 ` Adel Gadllah
@ 2007-07-10 19:40   ` Alexey Dobriyan
  2007-07-10 20:58     ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey Dobriyan @ 2007-07-10 19:40 UTC (permalink / raw)
  To: Adel Gadllah; +Cc: linux-kernel

On Tue, Jul 10, 2007 at 06:09:48PM +0200, Adel Gadllah wrote:
> --- linux-2.6.orig/include/linux/kernel.h
> +++ linux-2.6/include/linux/kernel.h
> @@ -35,7 +35,11 @@ extern const char linux_proc_banner[];
>  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
>  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
>  
> +#ifdef __CHECKER_
> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> +#else
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> +#endif

Al Viro recently gave a hint that he have patches for sparse to not give
spurious ARRAY_SIZE warnings.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fix sparse problems with ARRAY_SIZE
  2007-07-10 19:40   ` Alexey Dobriyan
@ 2007-07-10 20:58     ` Al Viro
  2007-07-10 22:40       ` Al Viro
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2007-07-10 20:58 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Adel Gadllah, linux-kernel

On Tue, Jul 10, 2007 at 11:40:33PM +0400, Alexey Dobriyan wrote:
> On Tue, Jul 10, 2007 at 06:09:48PM +0200, Adel Gadllah wrote:
> > --- linux-2.6.orig/include/linux/kernel.h
> > +++ linux-2.6/include/linux/kernel.h
> > @@ -35,7 +35,11 @@ extern const char linux_proc_banner[];
> >  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> >  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> >  
> > +#ifdef __CHECKER_
> > +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> > +#else
> >  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> > +#endif
> 
> Al Viro recently gave a hint that he have patches for sparse to not give
> spurious ARRAY_SIZE warnings.

I do.  Right now it's either 2 or 4 patches away from mainline sparse,
depending on reordering...  I'm splitting the last patch in series,
hopefully will reorder and send tonight.

Basically, it's a matter of getting __builtin_compatible_types_p()
implementation (really - evaluate.c:type_difference()) somewhere sane.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fix sparse problems with ARRAY_SIZE
  2007-07-10 20:58     ` Al Viro
@ 2007-07-10 22:40       ` Al Viro
  2007-07-12 10:27         ` Adel Gadllah
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2007-07-10 22:40 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Adel Gadllah, linux-kernel

On Tue, Jul 10, 2007 at 09:58:18PM +0100, Al Viro wrote:
> On Tue, Jul 10, 2007 at 11:40:33PM +0400, Alexey Dobriyan wrote:
> > On Tue, Jul 10, 2007 at 06:09:48PM +0200, Adel Gadllah wrote:
> > > --- linux-2.6.orig/include/linux/kernel.h
> > > +++ linux-2.6/include/linux/kernel.h
> > > @@ -35,7 +35,11 @@ extern const char linux_proc_banner[];
> > >  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> > >  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> > >  
> > > +#ifdef __CHECKER_
> > > +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> > > +#else
> > >  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> > > +#endif
> > 
> > Al Viro recently gave a hint that he have patches for sparse to not give
> > spurious ARRAY_SIZE warnings.
> 
> I do.  Right now it's either 2 or 4 patches away from mainline sparse,
> depending on reordering...  I'm splitting the last patch in series,
> hopefully will reorder and send tonight.
> 
> Basically, it's a matter of getting __builtin_compatible_types_p()
> implementation (really - evaluate.c:type_difference()) somewhere sane.

Try git://git.kernel.org/pub/scm/linux/kernel/git/viro/sparse.git/,
the branch is type_difference

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] fix sparse problems with ARRAY_SIZE
  2007-07-10 22:40       ` Al Viro
@ 2007-07-12 10:27         ` Adel Gadllah
  0 siblings, 0 replies; 6+ messages in thread
From: Adel Gadllah @ 2007-07-12 10:27 UTC (permalink / raw)
  To: Al Viro; +Cc: Alexey Dobriyan, linux-kernel

Al Viro wrote:
> On Tue, Jul 10, 2007 at 09:58:18PM +0100, Al Viro wrote:
>   
>> On Tue, Jul 10, 2007 at 11:40:33PM +0400, Alexey Dobriyan wrote:
>>     
>>> On Tue, Jul 10, 2007 at 06:09:48PM +0200, Adel Gadllah wrote:
>>>       
>>>> --- linux-2.6.orig/include/linux/kernel.h
>>>> +++ linux-2.6/include/linux/kernel.h
>>>> @@ -35,7 +35,11 @@ extern const char linux_proc_banner[];
>>>>  #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
>>>>  #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
>>>>  
>>>> +#ifdef __CHECKER_
>>>> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
>>>> +#else
>>>>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
>>>> +#endif
>>>>         
>>> Al Viro recently gave a hint that he have patches for sparse to not give
>>> spurious ARRAY_SIZE warnings.
>>>       
>> I do.  Right now it's either 2 or 4 patches away from mainline sparse,
>> depending on reordering...  I'm splitting the last patch in series,
>> hopefully will reorder and send tonight.
>>
>> Basically, it's a matter of getting __builtin_compatible_types_p()
>> implementation (really - evaluate.c:type_difference()) somewhere sane.
>>     
>
> Try git://git.kernel.org/pub/scm/linux/kernel/git/viro/sparse.git/,
> the branch is type_difference
>
>   
ok a proper fix is always better than a workaround ;)
it seems that ARRAY_SIZE is defined multiple times....
seem wrong... shouldn't all users include linux/kernel.h and use that one?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-07-12 10:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-10 16:05 [PATCH] fix sparse problems with ARRAY_SIZE Adel Gadllah
2007-07-10 16:09 ` Adel Gadllah
2007-07-10 19:40   ` Alexey Dobriyan
2007-07-10 20:58     ` Al Viro
2007-07-10 22:40       ` Al Viro
2007-07-12 10:27         ` Adel Gadllah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox