Commit 8e53b0f1 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Linus Walleij

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.
Reported-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 14e85c0e
...@@ -41,7 +41,7 @@ static DEFINE_MUTEX(sysfs_lock); ...@@ -41,7 +41,7 @@ static DEFINE_MUTEX(sysfs_lock);
static ssize_t gpio_direction_show(struct device *dev, static ssize_t gpio_direction_show(struct device *dev,
struct device_attribute *attr, char *buf) 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; ssize_t status;
mutex_lock(&sysfs_lock); mutex_lock(&sysfs_lock);
......
...@@ -148,7 +148,7 @@ static int gpiochip_find_base(int ngpio) ...@@ -148,7 +148,7 @@ static int gpiochip_find_base(int ngpio)
* *
* This function may sleep if gpiod_cansleep() is true. * 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; struct gpio_chip *chip;
unsigned offset; unsigned offset;
...@@ -164,13 +164,11 @@ int gpiod_get_direction(const struct gpio_desc *desc) ...@@ -164,13 +164,11 @@ int gpiod_get_direction(const struct gpio_desc *desc)
if (status > 0) { if (status > 0) {
/* GPIOF_DIR_IN, or other positive */ /* GPIOF_DIR_IN, or other positive */
status = 1; status = 1;
/* FLAG_IS_OUT is just a cache of the result of get_direction(), clear_bit(FLAG_IS_OUT, &desc->flags);
* so it does not affect constness per se */
clear_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
} }
if (status == 0) { if (status == 0) {
/* GPIOF_DIR_OUT */ /* GPIOF_DIR_OUT */
set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags); set_bit(FLAG_IS_OUT, &desc->flags);
} }
return status; return status;
} }
......
...@@ -66,7 +66,7 @@ __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, ...@@ -66,7 +66,7 @@ __devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
unsigned int index, enum gpiod_flags flags); unsigned int index, enum gpiod_flags flags);
void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 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_input(struct gpio_desc *desc);
int gpiod_direction_output(struct gpio_desc *desc, int value); int gpiod_direction_output(struct gpio_desc *desc, int value);
int gpiod_direction_output_raw(struct gpio_desc *desc, int value); int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment