diff options
author | Alexandre Courbot <acourbot@nvidia.com> | 2014-11-25 03:16:31 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-11-28 08:43:36 -0500 |
commit | 8e53b0f190af2954309bbad76a78177ead15d824 (patch) | |
tree | 51c650de7dbdb9672c3cba25a6bf03baaf033137 /drivers | |
parent | 14e85c0e69d5c7fdbd963edbbec1dc5cdd385200 (diff) |
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: 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>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/gpiolib-sysfs.c | 2 | ||||
-rw-r--r-- | drivers/gpio/gpiolib.c | 8 |
2 files changed, 4 insertions, 6 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); | |||
41 | static ssize_t gpio_direction_show(struct device *dev, | 41 | static ssize_t gpio_direction_show(struct device *dev, |
42 | struct device_attribute *attr, char *buf) | 42 | struct device_attribute *attr, char *buf) |
43 | { | 43 | { |
44 | const struct gpio_desc *desc = dev_get_drvdata(dev); | 44 | struct gpio_desc *desc = dev_get_drvdata(dev); |
45 | ssize_t status; | 45 | ssize_t status; |
46 | 46 | ||
47 | mutex_lock(&sysfs_lock); | 47 | 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) | |||
148 | * | 148 | * |
149 | * This function may sleep if gpiod_cansleep() is true. | 149 | * This function may sleep if gpiod_cansleep() is true. |
150 | */ | 150 | */ |
151 | int gpiod_get_direction(const struct gpio_desc *desc) | 151 | int gpiod_get_direction(struct gpio_desc *desc) |
152 | { | 152 | { |
153 | struct gpio_chip *chip; | 153 | struct gpio_chip *chip; |
154 | unsigned offset; | 154 | unsigned offset; |
@@ -164,13 +164,11 @@ int gpiod_get_direction(const struct gpio_desc *desc) | |||
164 | if (status > 0) { | 164 | if (status > 0) { |
165 | /* GPIOF_DIR_IN, or other positive */ | 165 | /* GPIOF_DIR_IN, or other positive */ |
166 | status = 1; | 166 | status = 1; |
167 | /* FLAG_IS_OUT is just a cache of the result of get_direction(), | 167 | clear_bit(FLAG_IS_OUT, &desc->flags); |
168 | * so it does not affect constness per se */ | ||
169 | clear_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags); | ||
170 | } | 168 | } |
171 | if (status == 0) { | 169 | if (status == 0) { |
172 | /* GPIOF_DIR_OUT */ | 170 | /* GPIOF_DIR_OUT */ |
173 | set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags); | 171 | set_bit(FLAG_IS_OUT, &desc->flags); |
174 | } | 172 | } |
175 | return status; | 173 | return status; |
176 | } | 174 | } |