summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-sim.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2022-12-12 14:07:48 +0100
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2022-12-14 09:53:20 +0100
commit11e47bbd700f31bd1ee9f8863381bc9e741c0e97 (patch)
treeb473952fb5ec31d0979d850d0ce236102281b345 /drivers/gpio/gpio-sim.c
parentbdbbae241a04f387ba910b8609f95fad5f1470c7 (diff)
downloadlinux-stable-11e47bbd700f31bd1ee9f8863381bc9e741c0e97.tar.gz
linux-stable-11e47bbd700f31bd1ee9f8863381bc9e741c0e97.tar.bz2
linux-stable-11e47bbd700f31bd1ee9f8863381bc9e741c0e97.zip
gpio: sim: set a limit on the number of GPIOs
With the removal of ARCH_NR_GPIOS in commit 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") the gpiolib core no longer sanitizes the number of GPIOs for us. This causes the gpio-sim selftests to now fail when setting the number of GPIOs to 99999 and expecting the probe() to fail. Set a sane limit of 1024 on the number of simulated GPIOs and bail out of probe if it's exceeded. Reported-by: kernel test robot <oliver.sang@intel.com> Link: https://lore.kernel.org/oe-lkp/202212112236.756f5db9-oliver.sang@intel.com Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-sim.c')
-rw-r--r--drivers/gpio/gpio-sim.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 1020c2feb249..60514bc5454f 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -31,6 +31,7 @@
#include "gpiolib.h"
+#define GPIO_SIM_NGPIO_MAX 1024
#define GPIO_SIM_PROP_MAX 4 /* Max 3 properties + sentinel. */
#define GPIO_SIM_NUM_ATTRS 3 /* value, pull and sentinel */
@@ -371,6 +372,9 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
if (ret)
return ret;
+ if (num_lines > GPIO_SIM_NGPIO_MAX)
+ return -ERANGE;
+
ret = fwnode_property_read_string(swnode, "gpio-sim,label", &label);
if (ret) {
label = devm_kasprintf(dev, GFP_KERNEL, "%s-%s",