public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* kernel.h: add ARRAY_AND_SIZE() macro to complement ARRAY_SIZE().
@ 2008-09-18 13:24 Ben Dooks
  2008-09-18 15:06 ` Alexey Dobriyan
  0 siblings, 1 reply; 17+ messages in thread
From: Ben Dooks @ 2008-09-18 13:24 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel; +Cc: Ben Dooks

[-- Attachment #1: simtec/simtec-kernel-array-and-size.patch --]
[-- Type: text/plain, Size: 1874 bytes --]

Move the ARRAY_AND_SIZE() macro from arch/arm/mach-pxa/generic.h
to a more useful position in include/linux/kernel.h. This macro
is very useful to registration functions that take an array and
the number of array elements in it as consecutive arguments.

The macro also should ensure that mistakes where the wrong array
is used to the ARRAY_SIZE() macro is passed. It also makes it
easier to avoid wrapping registration function arguments.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>

Index: linux-2.6.27-rc6-quilt4/arch/arm/mach-pxa/generic.h
===================================================================
--- linux-2.6.27-rc6-quilt4.orig/arch/arm/mach-pxa/generic.h	2008-09-18 14:16:47.000000000 +0100
+++ linux-2.6.27-rc6-quilt4/arch/arm/mach-pxa/generic.h	2008-09-18 14:16:52.000000000 +0100
@@ -29,8 +29,6 @@ extern int pxa_last_gpio;
 	mi->bank[__nr].size = (__size), \
 	mi->bank[__nr].node = (((unsigned)(__start) - PHYS_OFFSET) >> 27)
 
-#define ARRAY_AND_SIZE(x)	(x), ARRAY_SIZE(x)
-
 #ifdef CONFIG_PXA25x
 extern unsigned pxa25x_get_clk_frequency_khz(int);
 extern unsigned pxa25x_get_memclk_frequency_10khz(void);
Index: linux-2.6.27-rc6-quilt4/include/linux/kernel.h
===================================================================
--- linux-2.6.27-rc6-quilt4.orig/include/linux/kernel.h	2008-09-18 14:16:06.000000000 +0100
+++ linux-2.6.27-rc6-quilt4/include/linux/kernel.h	2008-09-18 14:16:31.000000000 +0100
@@ -43,6 +43,7 @@ extern const char linux_proc_banner[];
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#define ARRAY_AND_SIZE(arr) (arr), ARRAY_SIZE(arr)
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))

-- 
Ben (ben@fluff.org, http://www.fluff.org/)

  'a smiley only costs 4 bytes'

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

end of thread, other threads:[~2008-09-20 22:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-18 13:24 kernel.h: add ARRAY_AND_SIZE() macro to complement ARRAY_SIZE() Ben Dooks
2008-09-18 15:06 ` Alexey Dobriyan
2008-09-18 18:38   ` Eric Miao
2008-09-19  6:54     ` Cyrill Gorcunov
2008-09-19  7:22       ` Eric Miao
2008-09-19  7:32         ` Cyrill Gorcunov
2008-09-19 13:28         ` Stefan Richter
2008-09-19 15:28         ` Russ Dill
2008-09-19 17:55           ` Alexey Dobriyan
2008-09-20 13:05             ` Christer Weinigel
2008-09-20 13:45               ` Cyrill Gorcunov
2008-09-20 14:28                 ` Christer Weinigel
2008-09-20 14:45                   ` Cyrill Gorcunov
2008-09-20 16:38                     ` Christer Weinigel
2008-09-20 17:12                       ` Cyrill Gorcunov
2008-09-20 17:33                         ` Cyrill Gorcunov
2008-09-20 22:07               ` Chris Moore

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