staging: fbtft: array underflow in fbtft_request_gpios_match()
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 18 Jul 2017 09:30:10 +0000 (12:30 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 29 Jul 2017 00:08:16 +0000 (17:08 -0700)
"val" can be negative, so we'd write before the start of the
par->gpio.db[] array.

Fixes: c296d5f9957c ("staging: fbtft: core support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/fbtft/fbtft-core.c

index b742ee7866159efd8e69f435052a69de39689279..6d0363deba6193528342bf3306a84e83979b6c24 100644 (file)
@@ -84,7 +84,7 @@ static unsigned long fbtft_request_gpios_match(struct fbtft_par *par,
                                               const struct fbtft_gpio *gpio)
 {
        int ret;
-       long val;
+       unsigned int val;
 
        fbtft_par_dbg(DEBUG_REQUEST_GPIOS_MATCH, par, "%s('%s')\n",
                      __func__, gpio->name);
@@ -108,7 +108,7 @@ static unsigned long fbtft_request_gpios_match(struct fbtft_par *par,
                par->gpio.latch = gpio->gpio;
                return GPIOF_OUT_INIT_LOW;
        } else if (gpio->name[0] == 'd' && gpio->name[1] == 'b') {
-               ret = kstrtol(&gpio->name[2], 10, &val);
+               ret = kstrtouint(&gpio->name[2], 10, &val);
                if (ret == 0 && val < 16) {
                        par->gpio.db[val] = gpio->gpio;
                        return GPIOF_OUT_INIT_LOW;