summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2013-02-09 09:41:49 +0000
committerGrant Likely <grant.likely@secretlab.ca>2013-02-11 22:21:28 +0000
commit362432aed5e5b497a8cf7b20c268ba71df93c045 (patch)
tree4a87f9533b3310c0bbd2a87477bf52bb0286cf41 /drivers/gpio
parent6c0b4e6c85d085bd92966bc2b8da73e2d7f35929 (diff)
gpiolib: Fix locking on gpio debugfs files
The debugfs files really need to hold the gpiolib spinlock before accessing the list. Otherwise chip addition/removal will cause an oops. Cc: Alexandre Courbot <acourbot@nvidia.com> Cc: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5050693dcc35..4b3f388bcc6d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2053,29 +2053,35 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos)
{
+ unsigned long flags;
struct gpio_chip *chip = NULL;
loff_t index = *pos;
- /* REVISIT this isn't locked against gpio_chip removal ... */
-
s->private = "";
+ spin_lock_irqsave(&gpio_lock, flags);
list_for_each_entry(chip, &gpio_chips, list)
- if (index-- == 0)
+ if (index-- == 0) {
+ spin_unlock_irqrestore(&gpio_lock, flags);
return chip;
+ }
+ spin_unlock_irqrestore(&gpio_lock, flags);
return NULL;
}
static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos)
{
+ unsigned long flags;
struct gpio_chip *chip = v;
void *ret = NULL;
+ spin_lock_irqsave(&gpio_lock, flags);
if (list_is_last(&chip->list, &gpio_chips))
ret = NULL;
else
ret = list_entry(chip->list.next, struct gpio_chip, list);
+ spin_unlock_irqrestore(&gpio_lock, flags);
s->private = "\n";
++*pos;