fix sparse problems with ARRAY_SIZE
PATCH 1/1 fix sparse problems with ARRAY_SIZE
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
include/linux/kernel.h +4 -0
@@ -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))
Quoted 4 lines · Adel Gadllah
ARRAY_SIZEseems to create sparse warnings when used on global variables. The attached patch fixes this by using aARRAY_SIZEmacro 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.
include/linux/kernel.h +4 -0
@@ -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))
include/linux/kernel.h extern const char linux_proc_banner[]; · line 42
Quoted 11 lines · Adel Gadllah
include/linux/kernel.h +4
-0@@ -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.
Quoted 7 lines · Alexey Dobriyan
Quoted 6 lines · Adel Gadllah
include/linux/kernel.h +0
-0@@ -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))
Quoted 8 lines
include/linux/kernel.h extern const char linux_proc_banner[]; · line 42
Quoted 5 lines
include/linux/kernel.h +4
-0+#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_SIZEwarnings.
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.
Quoted 17 lines · Al Viro
Quoted 7 lines · Alexey Dobriyan
Quoted 6 lines · Adel Gadllah
include/linux/kernel.h +0
-0@@ -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))Quoted 8 lines
include/linux/kernel.h extern const char linux_proc_banner[]; · line 42
Quoted 5 lines
include/linux/kernel.h +4
-0+#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_SIZEwarnings.
Quoted 6 lines
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
Quoted 25 lines · Al Viro
Quoted 23 lines · Al Viro
Quoted 8 lines · Alexey Dobriyan
Quoted 6 lines · Adel Gadllah
include/linux/kernel.h +0
-0@@ -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))Quoted 9 lines
include/linux/kernel.h extern const char linux_proc_banner[]; · line 43
Quoted 6 lines
include/linux/kernel.h +4
-0+#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_SIZEwarnings.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.
Quoted 8 lines
Quoted 3 lines
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 istype_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?