linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely@secretlab.ca>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Ryan Mallon <rmallon@gmail.com>,
	linux-kernel@vger.kernel.org, gnurou@gmail.com,
	Alexandre Courbot <acourbot@nvidia.com>
Subject: Re: [PATCH 2/4] gpiolib: use const parameters when possible
Date: Tue, 26 Feb 2013 17:49:12 +0000	[thread overview]
Message-ID: <20130226174913.06E5C3E114E@localhost> (raw)
In-Reply-To: <1360907177-6468-3-git-send-email-acourbot@nvidia.com>

On Fri, 15 Feb 2013 14:46:15 +0900, Alexandre Courbot <acourbot@nvidia.com> wrote:
> Constify descriptor parameter of gpiod_* functions for those that
> should obviously not modify it. This includes value or direction get,
> cansleep, and IRQ number query.
> 
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>

Applied, thanks.

g.

> ---
>  drivers/gpio/gpiolib.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 1a8a7a8..a33bfc2 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -88,13 +88,14 @@ static int gpiod_request(struct gpio_desc *desc, const char *label);
>  static void gpiod_free(struct gpio_desc *desc);
>  static int gpiod_direction_input(struct gpio_desc *desc);
>  static int gpiod_direction_output(struct gpio_desc *desc, int value);
> +static int gpiod_get_direction(const struct gpio_desc *desc);
>  static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
> -static int gpiod_get_value_cansleep(struct gpio_desc *desc);
> +static int gpiod_get_value_cansleep(const struct gpio_desc *desc);
>  static void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
> -static int gpiod_get_value(struct gpio_desc *desc);
> +static int gpiod_get_value(const struct gpio_desc *desc);
>  static void gpiod_set_value(struct gpio_desc *desc, int value);
> -static int gpiod_cansleep(struct gpio_desc *desc);
> -static int gpiod_to_irq(struct gpio_desc *desc);
> +static int gpiod_cansleep(const struct gpio_desc *desc);
> +static int gpiod_to_irq(const struct gpio_desc *desc);
>  static int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
>  static int gpiod_export_link(struct device *dev, const char *name,
>  			     struct gpio_desc *desc);
> @@ -172,7 +173,7 @@ static int gpio_ensure_requested(struct gpio_desc *desc)
>  }
>  
>  /* caller holds gpio_lock *OR* gpio is marked as requested */
> -static struct gpio_chip *gpiod_to_chip(struct gpio_desc *desc)
> +static struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
>  {
>  	return desc ? desc->chip : NULL;
>  }
> @@ -207,7 +208,7 @@ static int gpiochip_find_base(int ngpio)
>  }
>  
>  /* caller ensures gpio is valid and requested, chip->get_direction may sleep  */
> -static int gpiod_get_direction(struct gpio_desc *desc)
> +static int gpiod_get_direction(const struct gpio_desc *desc)
>  {
>  	struct gpio_chip	*chip;
>  	unsigned		offset;
> @@ -223,11 +224,13 @@ static int gpiod_get_direction(struct gpio_desc *desc)
>  	if (status > 0) {
>  		/* GPIOF_DIR_IN, or other positive */
>  		status = 1;
> -		clear_bit(FLAG_IS_OUT, &desc->flags);
> +		/* FLAG_IS_OUT is just a cache of the result of get_direction(),
> +		 * so it does not affect constness per se */
> +		clear_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
>  	}
>  	if (status == 0) {
>  		/* GPIOF_DIR_OUT */
> -		set_bit(FLAG_IS_OUT, &desc->flags);
> +		set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
>  	}
>  	return status;
>  }
> @@ -263,7 +266,7 @@ static DEFINE_MUTEX(sysfs_lock);
>  static ssize_t gpio_direction_show(struct device *dev,
>  		struct device_attribute *attr, char *buf)
>  {
> -	struct gpio_desc	*desc = dev_get_drvdata(dev);
> +	const struct gpio_desc	*desc = dev_get_drvdata(dev);
>  	ssize_t			status;
>  
>  	mutex_lock(&sysfs_lock);
> @@ -1830,7 +1833,7 @@ EXPORT_SYMBOL_GPL(gpio_set_debounce);
>   * It returns the zero or nonzero value provided by the associated
>   * gpio_chip.get() method; or zero if no such method is provided.
>   */
> -static int gpiod_get_value(struct gpio_desc *desc)
> +static int gpiod_get_value(const struct gpio_desc *desc)
>  {
>  	struct gpio_chip	*chip;
>  	int value;
> @@ -1948,7 +1951,7 @@ EXPORT_SYMBOL_GPL(__gpio_set_value);
>   * This is used directly or indirectly to implement gpio_cansleep().  It
>   * returns nonzero if access reading or writing the GPIO value can sleep.
>   */
> -static int gpiod_cansleep(struct gpio_desc *desc)
> +static int gpiod_cansleep(const struct gpio_desc *desc)
>  {
>  	if (!desc)
>  		return 0;
> @@ -1971,7 +1974,7 @@ EXPORT_SYMBOL_GPL(__gpio_cansleep);
>   * It returns the number of the IRQ signaled by this (input) GPIO,
>   * or a negative errno.
>   */
> -static int gpiod_to_irq(struct gpio_desc *desc)
> +static int gpiod_to_irq(const struct gpio_desc *desc)
>  {
>  	struct gpio_chip	*chip;
>  	int			offset;
> @@ -1994,7 +1997,7 @@ EXPORT_SYMBOL_GPL(__gpio_to_irq);
>   * Common examples include ones connected to I2C or SPI chips.
>   */
>  
> -static int gpiod_get_value_cansleep(struct gpio_desc *desc)
> +static int gpiod_get_value_cansleep(const struct gpio_desc *desc)
>  {
>  	struct gpio_chip	*chip;
>  	int value;
> -- 
> 1.8.1.3
> 

-- 
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

  reply	other threads:[~2013-02-26 19:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15  5:46 [PATCH v2 0/4] gpiolib: some fixup patches Alexandre Courbot
2013-02-15  5:46 ` [PATCH 1/4] gpiolib: check descriptors validity before use Alexandre Courbot
2013-02-26 17:48   ` Grant Likely
2013-02-15  5:46 ` [PATCH 2/4] gpiolib: use const parameters when possible Alexandre Courbot
2013-02-26 17:49   ` Grant Likely [this message]
2013-02-15  5:46 ` [PATCH 3/4] gpiolib: move comment to right function Alexandre Courbot
2013-02-15  5:46 ` [PATCH 4/4] gpiolib: rename local offset variables to "hwgpio" Alexandre Courbot
2013-02-26 17:51   ` Grant Likely
2013-02-22  2:19 ` [PATCH v2 0/4] gpiolib: some fixup patches Alexandre Courbot
2013-02-26 17:53   ` Grant Likely
2013-02-27  1:22     ` Alexandre Courbot
2013-02-27  7:52       ` Grant Likely
2013-02-28  4:57         ` Alexandre Courbot
2013-02-28  6:21         ` Linus Walleij
2013-02-28  6:47           ` Grant Likely
  -- strict thread matches above, loose matches on Subject: below --
2013-02-13  7:02 [PATCH " Alexandre Courbot
2013-02-13  7:03 ` [PATCH 2/4] gpiolib: use const parameters when possible Alexandre Courbot
2014-11-17  9:09   ` Uwe Kleine-König
2014-11-19  8:33     ` Alexandre Courbot
2014-11-19  8:44       ` Uwe Kleine-König
2014-11-19  8:57         ` Alexandre Courbot
2014-11-19  9:02           ` Uwe Kleine-König
2014-11-19  9:07             ` Alexandre Courbot
2014-11-19 10:09               ` Uwe Kleine-König
2014-11-25  7:37                 ` Alexandre Courbot
2014-11-25  9:36                   ` Janusz Użycki

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=20130226174913.06E5C3E114E@localhost \
    --to=grant.likely@secretlab.ca \
    --cc=acourbot@nvidia.com \
    --cc=gnurou@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmallon@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).