]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
gpio: mockup: verify that ngpio > 0
authorBartosz Golaszewski <brgl@bgdev.pl>
Mon, 27 Nov 2017 10:48:49 +0000 (11:48 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Sat, 2 Dec 2017 21:42:28 +0000 (22:42 +0100)
Improve the module params sanitization: bail out from init if the user
tries to pass a non-positive number of GPIO lines for any mockup chip.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpio-mockup.c

index 68a0c1e06a16359c935d8a73c87252ea30fd20d2..532f5807390beb41160e752efbef080af33f5174 100644 (file)
@@ -335,6 +335,15 @@ static int __init gpio_mockup_init(void)
        /* Each chip is described by two values. */
        num_chips = gpio_mockup_params_nr / 2;
 
+       /*
+        * The second value in the <base GPIO - number of GPIOS> pair must
+        * always be greater than 0.
+        */
+       for (i = 0; i < num_chips; i++) {
+               if (gpio_mockup_ranges[i * 2 + 1] < 0)
+                       return -EINVAL;
+       }
+
        gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup-event", NULL);
        if (IS_ERR_OR_NULL(gpio_mockup_dbg_dir))
                gpio_mockup_err("error creating debugfs directory\n");