mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: H Hartley Sweeten <hartleys@visionengravers.com>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gpiolib: introduce for_each_gpio_in_chip macro
Date: Tue, 4 Aug 2009 14:14:26 -0700	[thread overview]
Message-ID: <200908041414.26112.david-b@pacbell.net> (raw)
In-Reply-To: <200907311027.06370.hartleys@visionengravers.com>

On Friday 31 July 2009, H Hartley Sweeten wrote:
> gpiolib: introduce for_each_gpio_in_chip macro
> 
> There are a number of places in gpiolib where all the gpio's handled by a
> chip are walked thru using a for() loop.  This introduces a for_each_*
> macro to clarify the code.

I'd rather not.  There are four such loops, and these are
really simple iterators.  Such a macro IMO just obfuscates,
when it's just hiding such trivial index ops.

NAK.

> Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
> 
> ---
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 51a8d41..b060f73 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -56,6 +56,11 @@ struct gpio_desc {
>  };
>  static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];
>  
> +#define for_each_gpio_in_chip(__gpio, __chip)			\
> +	for ((__gpio) = (__chip)->base;				\
> +		(__gpio) < (__chip)->base + (__chip)->ngpio;	\
> +		(__gpio)++)
> +
>  static inline void desc_set_label(struct gpio_desc *d, const char *label)
>  {
>  #ifdef CONFIG_DEBUG_FS
> @@ -694,14 +699,14 @@ int gpiochip_add(struct gpio_chip *chip)
>  	}
>  
>  	/* these GPIO numbers must not be managed by another gpio_chip */
> -	for (id = base; id < base + chip->ngpio; id++) {
> +	for_each_gpio_in_chip(id, chip) {
>  		if (gpio_desc[id].chip != NULL) {
>  			status = -EBUSY;
>  			break;
>  		}
>  	}
>  	if (status == 0) {
> -		for (id = base; id < base + chip->ngpio; id++) {
> +		for_each_gpio_in_chip(id, chip) {
>  			gpio_desc[id].chip = chip;
>  
>  			/* REVISIT:  most hardware initializes GPIOs as
> @@ -744,14 +749,14 @@ int gpiochip_remove(struct gpio_chip *chip)
>  
>  	spin_lock_irqsave(&gpio_lock, flags);
>  
> -	for (id = chip->base; id < chip->base + chip->ngpio; id++) {
> +	for_each_gpio_in_chip(id, chip) {
>  		if (test_bit(FLAG_REQUESTED, &gpio_desc[id].flags)) {
>  			status = -EBUSY;
>  			break;
>  		}
>  	}
>  	if (status == 0) {
> -		for (id = chip->base; id < chip->base + chip->ngpio; id++)
> +		for_each_gpio_in_chip(id, chip)
>  			gpio_desc[id].chip = NULL;
>  	}
>  
> 
> 




  reply	other threads:[~2009-08-05  0:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-31 17:27 H Hartley Sweeten
2009-08-04 21:14 ` David Brownell [this message]
2009-08-05  0:48   ` H Hartley Sweeten
2009-08-06  3:31     ` Ben Nizette
2009-09-19  0:03       ` Jaya Kumar
2009-09-19  0:42         ` H Hartley Sweeten
2009-09-19  4:40           ` Jaya Kumar

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=200908041414.26112.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=hartleys@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®