Skip to content

Commit 23cf00d

Browse files
M-Vaittinenbrgl
authored andcommitted
gpio: sysfs: Obey valid_mask
Do not allow exporting GPIOs which are set invalid by the driver's valid mask. Fixes: 726cb3b ("gpiolib: Support 'gpio-reserved-ranges' property") Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
1 parent 6cb59af commit 23cf00d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/gpio/gpiolib-sysfs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ static ssize_t export_store(struct class *class,
458458
long gpio;
459459
struct gpio_desc *desc;
460460
int status;
461+
struct gpio_chip *gc;
462+
int offset;
461463

462464
status = kstrtol(buf, 0, &gpio);
463465
if (status < 0)
@@ -469,6 +471,12 @@ static ssize_t export_store(struct class *class,
469471
pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
470472
return -EINVAL;
471473
}
474+
gc = desc->gdev->chip;
475+
offset = gpio_chip_hwgpio(desc);
476+
if (!gpiochip_line_is_valid(gc, offset)) {
477+
pr_warn("%s: GPIO %ld masked\n", __func__, gpio);
478+
return -EINVAL;
479+
}
472480

473481
/* No extra locking here; FLAG_SYSFS just signifies that the
474482
* request and export were done by on behalf of userspace, so

0 commit comments

Comments
 (0)