]> git.baikalelectronics.ru Git - kernel.git/commitdiff
gpio: sysfs: Obey valid_mask
authorMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Mon, 29 Mar 2021 11:41:12 +0000 (14:41 +0300)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 31 Mar 2021 18:32:38 +0000 (20:32 +0200)
Do not allow exporting GPIOs which are set invalid
by the driver's valid mask.

Fixes: b1a5bd48f96a ("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>
drivers/gpio/gpiolib-sysfs.c

index 26c5466b81799f39fc7c0b1add4a5fe586e0909c..ae49bb23c6ed1eb0dbfa311b64ff1f500f1ab12f 100644 (file)
@@ -458,6 +458,8 @@ static ssize_t export_store(struct class *class,
        long                    gpio;
        struct gpio_desc        *desc;
        int                     status;
+       struct gpio_chip        *gc;
+       int                     offset;
 
        status = kstrtol(buf, 0, &gpio);
        if (status < 0)
@@ -469,6 +471,12 @@ static ssize_t export_store(struct class *class,
                pr_warn("%s: invalid GPIO %ld\n", __func__, gpio);
                return -EINVAL;
        }
+       gc = desc->gdev->chip;
+       offset = gpio_chip_hwgpio(desc);
+       if (!gpiochip_line_is_valid(gc, offset)) {
+               pr_warn("%s: GPIO %ld masked\n", __func__, gpio);
+               return -EINVAL;
+       }
 
        /* No extra locking here; FLAG_SYSFS just signifies that the
         * request and export were done by on behalf of userspace, so