Philippe De Muyter wrote:
On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:On Tue, Feb 06, 2007 at 09:52:17AM -0800, Joe Perches wrote:On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:A patch to use ARRAY_SIZE macro already defined in kernel.h Signed-off-by: Ahmed S. Darwish <[email protected]>[...]- int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); + int nelem = ARRAY_SIZE(procfsentries); int i;for (i=0; i < nelem; i++) {For these patches, perhaps you can eliminate the temporary variable and change the loop to the more common form of for (i = 0; i < ARRAY_SIZE(array); i++) {Thanks, I think it's better too. Here's the modified patch. A patch to use ARRAY_SIZE macro when appropriate. Signed-off-by: Ahmed S. Darwish <[email protected]> --- diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index d22c022..87fe89c 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -1456,10 +1456,9 @@ static struct procfsentries {static void __init proc_init(void){ - int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); int i;- for (i=0; i < nelem; i++) {+ for (i = 0; i < ARRAY_SIZE(procfsentries); i++) { struct procfsentries *p = procfsentries + i; p->procent = create_proc_entry(p->name, p->mode, NULL); if (p->procent) p->procent->read_proc = p->read_proc; @@ -1468,10 +1467,9 @@ static void __init proc_init(void)static void __exit proc_exit(void){ - int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); int i;- for (i=nelem-1; i >= 0; i--) {+ for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {I would write such decrementing loops as : for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) { Long time ago, that produced better code. I did not check recently though.
Why would you write "--i >= 0" instead of just "i--"? The size of an array can't be negative.
-- Bill Davidsen <[email protected]> "We have more to fear from the bungling of the incompetent than from the machinations of the wicked." - from Slashdot - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- From: Kai Germaschewski <[email protected]>
- Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- References:
- [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- From: "Ahmed S. Darwish" <[email protected]>
- Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- From: Joe Perches <[email protected]>
- Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- From: "Ahmed S. Darwish" <[email protected]>
- Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- From: Philippe De Muyter <[email protected]>
- [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- Prev by Date: Re: 2.6.20 BUG: soft lockup detected on CPU#0!
- Next by Date: Re: [patch] export ufs_fs.h to userspace
- Previous by thread: Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- Next by thread: Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
- Index(es):