LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Haavard Skinnemoen <hskinnemoen@atmel.com>
Cc: David Brownell <david-b@pacbell.net>,
	Andrew Victor <linux@maxim.org.za>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Patrice Vilchez <patrice.vilchez@rfo.atmel.com>,
	Richard Purdie <rpurdie@rpsys.net>,
	linux-kernel@vger.kernel.org, kernel@avr32linux.org,
	David Brownell <dbrownell@users.sourceforge.net>
Subject: Re: [PATCH -mm 2/2] PWM LED driver
Date: Mon, 28 Jan 2008 01:29:32 -0800	[thread overview]
Message-ID: <20080128012932.bfbbd97d.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080128101551.7cbc7af5@dhcp-252-066.norway.atmel.com>

On Mon, 28 Jan 2008 10:15:51 +0100 Haavard Skinnemoen <hskinnemoen@atmel.com> wrote:

> On Sun, 27 Jan 2008 21:32:32 -0800
> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Thu, 24 Jan 2008 15:33:45 +0100 Haavard Skinnemoen <hskinnemoen@atmel.com> wrote:
> > 
> > > +	if (i > 0) {
> > > +		for (i = i - 1; i >= 0; i--) {
> > > +			led_classdev_unregister(&leds[i].cdev);
> > > +			pwm_channel_free(&leds[i].pwmc);
> > > +		}
> > > +	}
> > 
> > Could be:
> > 
> > 	while (--i > 0) {
> > 		led_classdev_unregister(&leds[i].cdev);
> > 		pwm_channel_free(&leds[i].pwmc);
> > 	}
> > 
> > or thereabouts.
> 
> Almost...we need to clean up for leds[0] too. Using a postfix decrement
> should take care of that. How about the patch below?
> 
> Haavard
> 
> >From de5002ad71a1000f81817410f02a7d9fbd5d4ecd Mon Sep 17 00:00:00 2001
> From: Haavard Skinnemoen <hskinnemoen@atmel.com>
> Date: Mon, 28 Jan 2008 10:14:14 +0100
> Subject: [PATCH] PWM led driver: Simplify cleanup loop
> 
> Why use a for loop inside an if() when we can get away with a simple
> while() loop?
> 
> Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
> ---
>  drivers/leds/leds-atmel-pwm.c |    8 +++-----
>  1 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c
> index af61f55..187031c 100644
> --- a/drivers/leds/leds-atmel-pwm.c
> +++ b/drivers/leds/leds-atmel-pwm.c
> @@ -100,11 +100,9 @@ static int __init pwmled_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err:
> -	if (i > 0) {
> -		for (i = i - 1; i >= 0; i--) {
> -			led_classdev_unregister(&leds[i].cdev);
> -			pwm_channel_free(&leds[i].pwmc);
> -		}
> +	while (i-- > 0) {
> +		led_classdev_unregister(&leds[i].cdev);
> +		pwm_channel_free(&leds[i].pwmc);
>  	}

Looks OK, although I'd say that `while (--i >= 0)' is more idiomatic -
predecrement, postincrement and all that?


  reply	other threads:[~2008-01-28  9:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-24 14:33 [PATCH -mm 0/2] AVR32 PWM driver and example user Haavard Skinnemoen
2008-01-24 14:33 ` [PATCH -mm 1/2] Basic PWM driver for AVR32 and AT91 Haavard Skinnemoen
2008-01-24 14:33   ` [PATCH -mm 2/2] PWM LED driver Haavard Skinnemoen
2008-01-28  5:32     ` Andrew Morton
2008-01-28  9:15       ` Haavard Skinnemoen
2008-01-28  9:29         ` Andrew Morton [this message]
2008-01-28  9:32           ` Haavard Skinnemoen
2008-01-28  9:41           ` David Brownell
2008-01-24 20:53   ` [PATCH -mm 1/2] Basic PWM driver for AVR32 and AT91 David Brownell
2008-01-27 14:16     ` Haavard Skinnemoen

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=20080128012932.bfbbd97d.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david-b@pacbell.net \
    --cc=dbrownell@users.sourceforge.net \
    --cc=hskinnemoen@atmel.com \
    --cc=kernel@avr32linux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@maxim.org.za \
    --cc=nicolas.ferre@atmel.com \
    --cc=patrice.vilchez@rfo.atmel.com \
    --cc=rpurdie@rpsys.net \
    --subject='Re: [PATCH -mm 2/2] PWM LED driver' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).