summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2013-02-15 00:46:15 -0500
committerGrant Likely <grant.likely@secretlab.ca>2013-03-02 08:20:19 -0500
commitdef634338d3ffb32fbe9b0a2d70cc24ef909cd4f (patch)
tree14da05000274ad6d6972d6c474d22362fa1b30e0 /drivers/gpio/gpiolib.c
parentbcabdef12da49878789464ad7239e97d83ea5ef5 (diff)
gpiolib: use const parameters when possible
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> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1a8a7a8f803f..a33bfc23e9f5 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);
88static void gpiod_free(struct gpio_desc *desc); 88static void gpiod_free(struct gpio_desc *desc);
89static int gpiod_direction_input(struct gpio_desc *desc); 89static int gpiod_direction_input(struct gpio_desc *desc);
90static int gpiod_direction_output(struct gpio_desc *desc, int value); 90static int gpiod_direction_output(struct gpio_desc *desc, int value);
91static int gpiod_get_direction(const struct gpio_desc *desc);
91static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); 92static int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
92static int gpiod_get_value_cansleep(struct gpio_desc *desc); 93static int gpiod_get_value_cansleep(const struct gpio_desc *desc);
93static void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); 94static void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
94static int gpiod_get_value(struct gpio_desc *desc); 95static int gpiod_get_value(const struct gpio_desc *desc);
95static void gpiod_set_value(struct gpio_desc *desc, int value); 96static void gpiod_set_value(struct gpio_desc *desc, int value);
96static int gpiod_cansleep(struct gpio_desc *desc); 97static int gpiod_cansleep(const struct gpio_desc *desc);
97static int gpiod_to_irq(struct gpio_desc *desc); 98static int gpiod_to_irq(const struct gpio_desc *desc);
98static int gpiod_export(struct gpio_desc *desc, bool direction_may_change); 99static int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
99static int gpiod_export_link(struct device *dev, const char *name, 100static int gpiod_export_link(struct device *dev, const char *name,
100 struct gpio_desc *desc); 101 struct gpio_desc *desc);
@@ -172,7 +173,7 @@ static int gpio_ensure_requested(struct gpio_desc *desc)
172} 173}
173 174
174/* caller holds gpio_lock *OR* gpio is marked as requested */ 175/* caller holds gpio_lock *OR* gpio is marked as requested */
175static struct gpio_chip *gpiod_to_chip(struct gpio_desc *desc) 176static struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
176{ 177{
177 return desc ? desc->chip : NULL; 178 return desc ? desc->chip : NULL;
178} 179}
@@ -207,7 +208,7 @@ static int gpiochip_find_base(int ngpio)
207} 208}
208 209
209/* caller ensures gpio is valid and requested, chip->get_direction may sleep */ 210/* caller ensures gpio is valid and requested, chip->get_direction may sleep */
210static int gpiod_get_direction(struct gpio_desc *desc) 211static int gpiod_get_direction(const struct gpio_desc *desc)
211{ 212{
212 struct gpio_chip *chip; 213 struct gpio_chip *chip;
213 unsigned offset; 214 unsigned offset;
@@ -223,11 +224,13 @@ static int gpiod_get_direction(struct gpio_desc *desc)
223 if (status > 0) { 224 if (status > 0) {
224 /* GPIOF_DIR_IN, or other positive */ 225 /* GPIOF_DIR_IN, or other positive */
225 status = 1; 226 status = 1;
226 clear_bit(FLAG_IS_OUT, &desc->flags); 227 /* FLAG_IS_OUT is just a cache of the result of get_direction(),
228 * so it does not affect constness per se */
229 clear_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
227 } 230 }
228 if (status == 0) { 231 if (status == 0) {
229 /* GPIOF_DIR_OUT */ 232 /* GPIOF_DIR_OUT */
230 set_bit(FLAG_IS_OUT, &desc->flags); 233 set_bit(FLAG_IS_OUT, &((struct gpio_desc *)desc)->flags);
231 } 234 }
232 return status; 235 return status;
233} 236}
@@ -263,7 +266,7 @@ static DEFINE_MUTEX(sysfs_lock);
263static ssize_t gpio_direction_show(struct device *dev, 266static ssize_t gpio_direction_show(struct device *dev,
264 struct device_attribute *attr, char *buf) 267 struct device_attribute *attr, char *buf)
265{ 268{
266 struct gpio_desc *desc = dev_get_drvdata(dev); 269 const struct gpio_desc *desc = dev_get_drvdata(dev);
267 ssize_t status; 270 ssize_t status;
268 271
269 mutex_lock(&sysfs_lock); 272 mutex_lock(&sysfs_lock);
@@ -1830,7 +1833,7 @@ EXPORT_SYMBOL_GPL(gpio_set_debounce);
1830 * It returns the zero or nonzero value provided by the associated 1833 * It returns the zero or nonzero value provided by the associated
1831 * gpio_chip.get() method; or zero if no such method is provided. 1834 * gpio_chip.get() method; or zero if no such method is provided.
1832 */ 1835 */
1833static int gpiod_get_value(struct gpio_desc *desc) 1836static int gpiod_get_value(const struct gpio_desc *desc)
1834{ 1837{
1835 struct gpio_chip *chip; 1838 struct gpio_chip *chip;
1836 int value; 1839 int value;
@@ -1948,7 +1951,7 @@ EXPORT_SYMBOL_GPL(__gpio_set_value);
1948 * This is used directly or indirectly to implement gpio_cansleep(). It 1951 * This is used directly or indirectly to implement gpio_cansleep(). It
1949 * returns nonzero if access reading or writing the GPIO value can sleep. 1952 * returns nonzero if access reading or writing the GPIO value can sleep.
1950 */ 1953 */
1951static int gpiod_cansleep(struct gpio_desc *desc) 1954static int gpiod_cansleep(const struct gpio_desc *desc)
1952{ 1955{
1953 if (!desc) 1956 if (!desc)
1954 return 0; 1957 return 0;
@@ -1971,7 +1974,7 @@ EXPORT_SYMBOL_GPL(__gpio_cansleep);
1971 * It returns the number of the IRQ signaled by this (input) GPIO, 1974 * It returns the number of the IRQ signaled by this (input) GPIO,
1972 * or a negative errno. 1975 * or a negative errno.
1973 */ 1976 */
1974static int gpiod_to_irq(struct gpio_desc *desc) 1977static int gpiod_to_irq(const struct gpio_desc *desc)
1975{ 1978{
1976 struct gpio_chip *chip; 1979 struct gpio_chip *chip;
1977 int offset; 1980 int offset;
@@ -1994,7 +1997,7 @@ EXPORT_SYMBOL_GPL(__gpio_to_irq);
1994 * Common examples include ones connected to I2C or SPI chips. 1997 * Common examples include ones connected to I2C or SPI chips.
1995 */ 1998 */
1996 1999
1997static int gpiod_get_value_cansleep(struct gpio_desc *desc) 2000static int gpiod_get_value_cansleep(const struct gpio_desc *desc)
1998{ 2001{
1999 struct gpio_chip *chip; 2002 struct gpio_chip *chip;
2000 int value; 2003 int value;