Commit 9c4ba9466117b16a2b85034bb87db528aaeb3f07

Authored by David Brownell
Committed by Linus Torvalds
1 parent 49946f6814

gpiolib: decouple might_sleep_if() from DEBUG

Be more consistent about runtime programming interface abuse warnings,
which can reduce some confusion and trigger bugfixes.  Based on an
observation and patch from Jani Nikula.

Also update doc to highlight some sleeping-call issues and to match some
recent changes.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Jani Nikula <ext-jani.1.nikula@nokia.com>
Cc: "Ryan Mallon" <ryan@bluewatersys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 35 additions and 12 deletions Side-by-side Diff

Documentation/gpio.txt
... ... @@ -158,10 +158,11 @@
158 158 Spinlock-Safe GPIO access
159 159 -------------------------
160 160 Most GPIO controllers can be accessed with memory read/write instructions.
161   -That doesn't need to sleep, and can safely be done from inside IRQ handlers.
162   -(That includes hardirq contexts on RT kernels.)
  161 +Those don't need to sleep, and can safely be done from inside hard
  162 +(nonthreaded) IRQ handlers and similar contexts.
163 163  
164   -Use these calls to access such GPIOs:
  164 +Use the following calls to access such GPIOs,
  165 +for which gpio_cansleep() will always return false (see below):
165 166  
166 167 /* GPIO INPUT: return zero or nonzero */
167 168 int gpio_get_value(unsigned gpio);
... ... @@ -210,9 +211,31 @@
210 211 /* GPIO OUTPUT, might sleep */
211 212 void gpio_set_value_cansleep(unsigned gpio, int value);
212 213  
213   -Other than the fact that these calls might sleep, and will not be ignored
214   -for GPIOs that can't be accessed from IRQ handlers, these calls act the
215   -same as the spinlock-safe calls.
  214 +
  215 +Accessing such GPIOs requires a context which may sleep, for example
  216 +a threaded IRQ handler, and those accessors must be used instead of
  217 +spinlock-safe accessors without the cansleep() name suffix.
  218 +
  219 +Other than the fact that these accessors might sleep, and will work
  220 +on GPIOs that can't be accessed from hardIRQ handlers, these calls act
  221 +the same as the spinlock-safe calls.
  222 +
  223 + ** IN ADDITION ** calls to setup and configure such GPIOs must be made
  224 +from contexts which may sleep, since they may need to access the GPIO
  225 +controller chip too: (These setup calls are usually made from board
  226 +setup or driver probe/teardown code, so this is an easy constraint.)
  227 +
  228 + gpio_direction_input()
  229 + gpio_direction_output()
  230 + gpio_request()
  231 +
  232 +## gpio_request_one()
  233 +## gpio_request_array()
  234 +## gpio_free_array()
  235 +
  236 + gpio_free()
  237 + gpio_set_debounce()
  238 +
216 239  
217 240  
218 241 Claiming and Releasing GPIOs
drivers/gpio/gpiolib.c
... ... @@ -1272,7 +1272,7 @@
1272 1272 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) {
1273 1273 if (chip->free) {
1274 1274 spin_unlock_irqrestore(&gpio_lock, flags);
1275   - might_sleep_if(extra_checks && chip->can_sleep);
  1275 + might_sleep_if(chip->can_sleep);
1276 1276 chip->free(chip, gpio - chip->base);
1277 1277 spin_lock_irqsave(&gpio_lock, flags);
1278 1278 }
... ... @@ -1410,7 +1410,7 @@
1410 1410  
1411 1411 spin_unlock_irqrestore(&gpio_lock, flags);
1412 1412  
1413   - might_sleep_if(extra_checks && chip->can_sleep);
  1413 + might_sleep_if(chip->can_sleep);
1414 1414  
1415 1415 if (status) {
1416 1416 status = chip->request(chip, gpio);
... ... @@ -1463,7 +1463,7 @@
1463 1463  
1464 1464 spin_unlock_irqrestore(&gpio_lock, flags);
1465 1465  
1466   - might_sleep_if(extra_checks && chip->can_sleep);
  1466 + might_sleep_if(chip->can_sleep);
1467 1467  
1468 1468 if (status) {
1469 1469 status = chip->request(chip, gpio);
... ... @@ -1521,7 +1521,7 @@
1521 1521  
1522 1522 spin_unlock_irqrestore(&gpio_lock, flags);
1523 1523  
1524   - might_sleep_if(extra_checks && chip->can_sleep);
  1524 + might_sleep_if(chip->can_sleep);
1525 1525  
1526 1526 return chip->set_debounce(chip, gpio, debounce);
1527 1527  
... ... @@ -1571,7 +1571,7 @@
1571 1571 struct gpio_chip *chip;
1572 1572  
1573 1573 chip = gpio_to_chip(gpio);
1574   - WARN_ON(extra_checks && chip->can_sleep);
  1574 + WARN_ON(chip->can_sleep);
1575 1575 return chip->get ? chip->get(chip, gpio - chip->base) : 0;
1576 1576 }
1577 1577 EXPORT_SYMBOL_GPL(__gpio_get_value);
... ... @@ -1590,7 +1590,7 @@
1590 1590 struct gpio_chip *chip;
1591 1591  
1592 1592 chip = gpio_to_chip(gpio);
1593   - WARN_ON(extra_checks && chip->can_sleep);
  1593 + WARN_ON(chip->can_sleep);
1594 1594 chip->set(chip, gpio - chip->base, value);
1595 1595 }
1596 1596 EXPORT_SYMBOL_GPL(__gpio_set_value);