gpio: remove const modifier from gpiod_get_direction()
PATCH 1/1 gpio: remove const modifier from gpiod_get_direction()
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.
--- drivers/gpio/gpiolib-sysfs.c | 2 +- drivers/gpio/gpiolib.c | 8 +++----- include/linux/gpio/consumer.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-)
drivers/gpio/gpiolib-sysfs.c +1 -1
@@ -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);
drivers/gpio/gpiolib.c +3 -5
@@ -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; }
include/linux/gpio/consumer.h +1 -1
@@ -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);
Signature · 1 line
2.1.3
Hello Alexandre,
just some minor nitpicking on the commit log:
Quoted 4 lines · 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
s/ is/ if/, and I think s/parameter/variable to non-const/
Quoted 1 line
compiler decide to optimize here, so remove this const parameter. The
s/decide/decides/; s/parameter/attribute/
Quoted 4 lines
intent is to make
gpiod_get_direction()private anyway, so it does not really matter.Reported-by Uwe Kleine-König <[email protected]>
Thanks
Uwe
Signature · 6 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Uwe Kleine-König
Hello Alexandre,
just some minor nitpicking on the commit log:
Quoted 4 lines · 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 thes/ is/ if/, and I think s/parameter/variable to non-const/
Quoted 8 lines
Quoted 1 line
compiler decide to optimize here, so remove this const parameter. The
s/decide/decides/; s/parameter/attribute/
Quoted 4 lines
intent is to make
gpiod_get_direction()private anyway, so it does not really matter.Reported-by Uwe Kleine-König <[email protected]>Acked-by Uwe Kleine-König <[email protected]>
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. --
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 gpio: remove const modifier from gpiod_get_direction()
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.
---
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(-)
drivers/gpio/gpiolib-sysfs.c +1 -1
@@ -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);
drivers/gpio/gpiolib.c +3 -5
@@ -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; }
include/linux/gpio/consumer.h +1 -1
@@ -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);
Signature · 6 lines
2.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · 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 makegpiod_get_direction()private anyway, so it does not really matter.
Quoted 7 lines
Reported-by Uwe Kleine-König <[email protected]>Signed-off-by Alexandre Courbot <[email protected]>Acked-by Uwe Kleine-König <[email protected]>---
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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html