All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bill Davidsen <davidsen@tmr.com>
To: Philippe De Muyter <phdm@macqel.be>
Cc: "Ahmed S. Darwish" <darwish.07@gmail.com>,
	Joe Perches <joe@perches.com>,
	kkeil@suse.de, kai.germaschewski@gmx.de,
	linux-kernel@vger.kernel.org, isdn4linux@listserv.isdn4linux.de
Subject: Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
Date: Thu, 08 Feb 2007 10:53:10 -0500	[thread overview]
Message-ID: <45CB4766.30909@tmr.com> (raw)
In-Reply-To: <20070206211813.GD2649@ingate.macqel.be>

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 <darwish.07@gmail.com>
>> [...]
>>>> -    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 <darwish.07@gmail.com>
>> ---
>> 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 <davidsen@tmr.com>
   "We have more to fear from the bungling of the incompetent than from
the machinations of the wicked."  - from Slashdot

  parent reply	other threads:[~2007-02-08 15:53 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-06 16:02 [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
2007-02-06 16:03 ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-06 16:03 ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
2007-02-06 16:56   ` Dor Laor
2007-02-06 16:56     ` Dor Laor
2007-02-06 16:04 ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
2007-02-06 16:04 ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
2007-02-06 17:52   ` Joe Perches
2007-02-06 20:41     ` Ahmed S. Darwish
2007-02-06 21:18       ` Philippe De Muyter
2007-02-07 19:41         ` Ahmed S. Darwish
2007-02-07 21:02           ` Philippe De Muyter
2007-02-08 15:53         ` Bill Davidsen [this message]
2007-02-08 16:02           ` Kai Germaschewski
2007-02-06 16:05 ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
2007-02-06 16:05 ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
2007-02-06 16:06 ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
2007-02-06 16:06 ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
2007-02-06 16:07 ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
2007-02-06 18:57   ` Roland Dreier
2007-02-06 16:07 ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
2007-02-07  6:32   ` Cornelia Huck
2007-02-06 16:08 ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
2007-02-07 18:29   ` Josh Triplett
2007-02-06 16:08 ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
2007-02-06 16:08 ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
2007-02-06 16:09 ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
2007-02-06 16:09 ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
2007-02-06 16:19   ` Evgeniy Polyakov
2007-02-06 16:10 ` [PATCH 2.6.20] drm: " Ahmed S. Darwish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45CB4766.30909@tmr.com \
    --to=davidsen@tmr.com \
    --cc=darwish.07@gmail.com \
    --cc=isdn4linux@listserv.isdn4linux.de \
    --cc=joe@perches.com \
    --cc=kai.germaschewski@gmx.de \
    --cc=kkeil@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phdm@macqel.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.