diff mbox

[06/10] gpio: mockup: refuse to accept an odd number of GPIO ranges

Message ID 1495701227-28809-7-git-send-email-brgl@bgdev.pl
State New
Headers show

Commit Message

Bartosz Golaszewski May 25, 2017, 8:33 a.m. UTC
Currently we ignore the last odd range value, since each chip is
described by two values. Be more strict and require the user to
pass an even number of ranges.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/gpio/gpio-mockup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko May 27, 2017, 5:29 p.m. UTC | #1
On Thu, May 25, 2017 at 11:33 AM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> Currently we ignore the last odd range value, since each chip is
> described by two values. Be more strict and require the user to
> pass an even number of ranges.

> -       if (gpio_mockup_params_nr < 2)
> +       if (gpio_mockup_params_nr < 2 || (gpio_mockup_params_nr % 2))

     if (((gpio_mockup_params_nr + 1) & ~3) < 3)

3 might have a suffix regarding to the type of variable.
Andy Shevchenko May 27, 2017, 5:30 p.m. UTC | #2
On Sat, May 27, 2017 at 8:29 PM, Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Thu, May 25, 2017 at 11:33 AM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>> Currently we ignore the last odd range value, since each chip is
>> described by two values. Be more strict and require the user to
>> pass an even number of ranges.
>
>> -       if (gpio_mockup_params_nr < 2)
>> +       if (gpio_mockup_params_nr < 2 || (gpio_mockup_params_nr % 2))
>
>      if (((gpio_mockup_params_nr + 1) & ~3) < 3)
>
> 3 might have a suffix regarding to the type of variable.

Oh, ignore that, sorry, for a noise.
diff mbox

Patch

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index b197b93..d771112 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -346,7 +346,7 @@  static int gpio_mockup_probe(struct platform_device *pdev)
 	int ret, i, base, ngpio;
 	char *chip_name;
 
-	if (gpio_mockup_params_nr < 2)
+	if (gpio_mockup_params_nr < 2 || (gpio_mockup_params_nr % 2))
 		return -EINVAL;
 
 	chips = devm_kzalloc(dev,