public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Constantin Baranov <const@const.mimas.ru>,
	linux-kernel@vger.kernel.org, Richard Purdie <rpurdie@rpsys.net>
Subject: Re: [PATCH 2.6.27-rc3] led: driver for LEDs on PCEngines ALIX.2 and ALIX.3 boards
Date: Sun, 24 Aug 2008 12:08:52 +0200	[thread overview]
Message-ID: <48B13334.9060406@s5r6.in-berlin.de> (raw)
In-Reply-To: <20080822115150.6b3907a4.akpm@linux-foundation.org>

Andrew Morton wrote:
> On Tue, 19 Aug 2008 22:23:41 +0500
> Constantin Baranov <const@const.mimas.ru> wrote:
>> --- linux-2.6.27-rc3/drivers/leds/leds-alix.c	1970-01-01 04:00:00.000000000 +0400
>> +++ linux-2.6.27-rc3-alix/drivers/leds/leds-alix.c	2008-08-19 21:59:05.207153570 +0500
...
>> +static int __init alix_led_probe(struct platform_device *pdev)
>> +{
>> +	int i;
>> +	int ret = 0;
>> +	
>> +	for (i = 0; i < ARRAY_SIZE(alix_leds) && ret >= 0; i++)
>> +		ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
>> +
>> +	if (ret < 0) {
>> +		for (i = i - 2; i >= 0; i--)
> 
> this is off-by-one, surely.
> 
> If we get here with i==1, we'll loop 4 billion times.
> 
>> +			led_classdev_unregister(&alix_leds[i].cdev);
>> +	}
>> +
>> +	return ret;
>> +}
...
> How's this look?
...
> @@ -92,7 +95,7 @@ static int __init alix_led_probe(struct 
>  		ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
>  
>  	if (ret < 0) {
> -		for (i = i - 2; i >= 0; i--)
> +		while (--i >= 0)
>  			led_classdev_unregister(&alix_leds[i].cdev);
>  	}


Really?  Constantin's code looks correct to me.  He increments i once 
more after failure.

Perhaps write it easier to read; i.e. in the same way as most error 
return checks everywhere in the kernel:

	for (i = 0; i < ARRAY_SIZE(alix_leds); i++) {
		ret = led_classdev_register(...etc...);
		if (ret < 0)
			break;
	}

	if (ret < 0)
		while (i--)
			led_classdev_unregister(&alix_leds[i].cdev);


Or		while (--i >= 0)

or		for (i--; i >= 0; i--)
-- 
Stefan Richter
-=====-==--- =--- ==---
http://arcgraph.de/sr/

  parent reply	other threads:[~2008-08-24 10:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-19 17:23 [PATCH 2.6.27-rc3] led: driver for LEDs on PCEngines ALIX.2 and ALIX.3 boards Constantin Baranov
2008-08-22 18:51 ` Andrew Morton
2008-08-22 19:44   ` Willy Tarreau
2008-08-22 21:08   ` Constantin Baranov
2008-08-22 21:31     ` Andrew Morton
2008-08-23 17:11       ` Constantin Baranov
2008-08-24  5:36         ` Andrew Morton
2008-08-24 10:08   ` Stefan Richter [this message]
2008-08-24 10:33     ` Stefan Richter

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=48B13334.9060406@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=akpm@linux-foundation.org \
    --cc=const@const.mimas.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox