linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: remove const modifier from gpiod_get_direction()
@ 2014-11-25  7:20 Alexandre Courbot
  2014-11-25  8:01 ` Uwe Kleine-König
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Courbot @ 2014-11-25  7:20 UTC (permalink / raw)
  To: Linus Walleij, Uwe Kleine-König
  Cc: linux-gpio, linux-kernel, gnurou, Alexandre Courbot

Although gpiod_get_direction() can be considered side-effect free for
consumers, its internals involve setting or clearing bits in the
affected GPIO descriptor, for which we need to force-cast the const
descriptor parameter. This could lead to incorrect behavior is the
compiler decide to optimize here, so remove this const parameter. The
intent is to make gpiod_get_direction() private anyway, so it does not
really matter.

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
 drivers/gpio/gpiolib-sysfs.c  | 2 +-
 drivers/gpio/gpiolib.c        | 8 +++-----
 include/linux/gpio/consumer.h | 2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 781fbed00fc3..2ac1800b58bb 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -41,7 +41,7 @@ static DEFINE_MUTEX(sysfs_lock);
 static ssize_t gpio_direction_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	const struct gpio_desc	*desc = dev_get_drvdata(dev);
+	struct gpio_desc	*desc = dev_get_drvdata(dev);
 	ssize_t			status;
 
 	mutex_lock(&sysfs_lock);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5619922ebf44..0b271ef87c09 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -148,7 +148,7 @@ static int gpiochip_find_base(int ngpio)
  *
  * This function may sleep if gpiod_cansleep() is true.
  */
-int gpiod_get_direction(const struct gpio_desc *desc)
+int gpiod_get_direction(struct gpio_desc *desc)
 {
 	struct gpio_chip	*chip;
 	unsigned		offset;
@@ -164,13 +164,11 @@ int gpiod_get_direction(const struct gpio_desc *desc)
 	if (status > 0) {
 		/* GPIOF_DIR_IN, or other positive */
 		status = 1;
-		/* 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);
+		clear_bit(FLAG_IS_OUT, &desc->flags);
 	}
 	if (status == 0) {
 		/* GPIOF_DIR_OUT */
-		set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
+		set_bit(FLAG_IS_OUT, &desc->flags);
 	}
 	return status;
 }
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 83c0a61c605d..d54d158ca327 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -66,7 +66,7 @@ __devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
 			      unsigned int index, enum gpiod_flags flags);
 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
 
-int gpiod_get_direction(const struct gpio_desc *desc);
+int gpiod_get_direction(struct gpio_desc *desc);
 int gpiod_direction_input(struct gpio_desc *desc);
 int gpiod_direction_output(struct gpio_desc *desc, int value);
 int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: remove const modifier from gpiod_get_direction()
  2014-11-25  7:20 [PATCH] gpio: remove const modifier from gpiod_get_direction() Alexandre Courbot
@ 2014-11-25  8:01 ` Uwe Kleine-König
  2014-11-25  8:09   ` Alexandre Courbot
  0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2014-11-25  8:01 UTC (permalink / raw)
  To: Alexandre Courbot; +Cc: Linus Walleij, linux-gpio, linux-kernel, gnurou

Hello Alexandre,

just some minor nitpicking on the commit log:

On Tue, Nov 25, 2014 at 04:20:45PM +0900, Alexandre Courbot wrote:
> Although gpiod_get_direction() can be considered side-effect free for
> consumers, its internals involve setting or clearing bits in the
> affected GPIO descriptor, for which we need to force-cast the const
> descriptor parameter. This could lead to incorrect behavior is the
s/ is/ if/, and I think s/parameter/variable to non-const/

> compiler decide to optimize here, so remove this const parameter. The
s/decide/decides/; s/parameter/attribute/

> intent is to make gpiod_get_direction() private anyway, so it does not
> really matter.
> 
> Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpio: remove const modifier from gpiod_get_direction()
  2014-11-25  8:01 ` Uwe Kleine-König
@ 2014-11-25  8:09   ` Alexandre Courbot
  2014-11-25  8:16     ` [PATCH v2] " Alexandre Courbot
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Courbot @ 2014-11-25  8:09 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Linus Walleij, linux-gpio, linux-kernel, gnurou

On 11/25/2014 05:01 PM, Uwe Kleine-König wrote:
> Hello Alexandre,
>
> just some minor nitpicking on the commit log:
>
> On Tue, Nov 25, 2014 at 04:20:45PM +0900, Alexandre Courbot wrote:
>> Although gpiod_get_direction() can be considered side-effect free for
>> consumers, its internals involve setting or clearing bits in the
>> affected GPIO descriptor, for which we need to force-cast the const
>> descriptor parameter. This could lead to incorrect behavior is the
> s/ is/ if/, and I think s/parameter/variable to non-const/
>
>> compiler decide to optimize here, so remove this const parameter. The
> s/decide/decides/; s/parameter/attribute/
>
>> intent is to make gpiod_get_direction() private anyway, so it does not
>> really matter.
>>
>> Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks ; I should have proof-read myself...

Sending a v2 with a fixed log and your Ack so Linus can just pick the 
patch as-is.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] gpio: remove const modifier from gpiod_get_direction()
  2014-11-25  8:09   ` Alexandre Courbot
@ 2014-11-25  8:16     ` Alexandre Courbot
  2014-11-28 13:44       ` Linus Walleij
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Courbot @ 2014-11-25  8:16 UTC (permalink / raw)
  To: Linus Walleij, Uwe Kleine-König
  Cc: linux-gpio, linux-kernel, gnurou, Alexandre Courbot

Although gpiod_get_direction() can be considered side-effect free for
consumers, its internals involve setting or clearing bits in the
affected GPIO descriptor, for which we need to force-cast the const
descriptor variable to non-const. This could lead to incorrect behavior
if the compiler decides to optimize here, so remove this const
attribute. The intent is to make gpiod_get_direction() private anyway,
so it does not really matter.

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Changes since v1:
- Fixed poor grammar in commit log
- Added Uwe's Ack

 drivers/gpio/gpiolib-sysfs.c  | 2 +-
 drivers/gpio/gpiolib.c        | 8 +++-----
 include/linux/gpio/consumer.h | 2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 781fbed00fc3..2ac1800b58bb 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -41,7 +41,7 @@ static DEFINE_MUTEX(sysfs_lock);
 static ssize_t gpio_direction_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
-	const struct gpio_desc	*desc = dev_get_drvdata(dev);
+	struct gpio_desc	*desc = dev_get_drvdata(dev);
 	ssize_t			status;
 
 	mutex_lock(&sysfs_lock);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5619922ebf44..0b271ef87c09 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -148,7 +148,7 @@ static int gpiochip_find_base(int ngpio)
  *
  * This function may sleep if gpiod_cansleep() is true.
  */
-int gpiod_get_direction(const struct gpio_desc *desc)
+int gpiod_get_direction(struct gpio_desc *desc)
 {
 	struct gpio_chip	*chip;
 	unsigned		offset;
@@ -164,13 +164,11 @@ int gpiod_get_direction(const struct gpio_desc *desc)
 	if (status > 0) {
 		/* GPIOF_DIR_IN, or other positive */
 		status = 1;
-		/* 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);
+		clear_bit(FLAG_IS_OUT, &desc->flags);
 	}
 	if (status == 0) {
 		/* GPIOF_DIR_OUT */
-		set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
+		set_bit(FLAG_IS_OUT, &desc->flags);
 	}
 	return status;
 }
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 83c0a61c605d..d54d158ca327 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -66,7 +66,7 @@ __devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
 			      unsigned int index, enum gpiod_flags flags);
 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
 
-int gpiod_get_direction(const struct gpio_desc *desc);
+int gpiod_get_direction(struct gpio_desc *desc);
 int gpiod_direction_input(struct gpio_desc *desc);
 int gpiod_direction_output(struct gpio_desc *desc, int value);
 int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] gpio: remove const modifier from gpiod_get_direction()
  2014-11-25  8:16     ` [PATCH v2] " Alexandre Courbot
@ 2014-11-28 13:44       ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2014-11-28 13:44 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Uwe Kleine-König, linux-gpio, linux-kernel, Alexandre Courbot

On Tue, Nov 25, 2014 at 9:16 AM, Alexandre Courbot <acourbot@nvidia.com> wrote:

> Although gpiod_get_direction() can be considered side-effect free for
> consumers, its internals involve setting or clearing bits in the
> affected GPIO descriptor, for which we need to force-cast the const
> descriptor variable to non-const. This could lead to incorrect behavior
> if the compiler decides to optimize here, so remove this const
> attribute. The intent is to make gpiod_get_direction() private anyway,
> so it does not really matter.
>
> Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Changes since v1:
> - Fixed poor grammar in commit log
> - Added Uwe's Ack

Patch applied after crying blood of the quoted-printable encoding
of this mail.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-28 13:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-25  7:20 [PATCH] gpio: remove const modifier from gpiod_get_direction() Alexandre Courbot
2014-11-25  8:01 ` Uwe Kleine-König
2014-11-25  8:09   ` Alexandre Courbot
2014-11-25  8:16     ` [PATCH v2] " Alexandre Courbot
2014-11-28 13:44       ` Linus Walleij

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).