Skip to content

Commit 11e47bb

Browse files
author
Bartosz Golaszewski
committed
gpio: sim: set a limit on the number of GPIOs
With the removal of ARCH_NR_GPIOS in commit 7b61212 ("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 <[email protected]> Link: https://lore.kernel.org/oe-lkp/[email protected] Fixes: 7b61212 ("gpiolib: Get rid of ARCH_NR_GPIOS") Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent bdbbae2 commit 11e47bb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/gpio/gpio-sim.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "gpiolib.h"
3333

34+
#define GPIO_SIM_NGPIO_MAX 1024
3435
#define GPIO_SIM_PROP_MAX 4 /* Max 3 properties + sentinel. */
3536
#define GPIO_SIM_NUM_ATTRS 3 /* value, pull and sentinel */
3637

@@ -371,6 +372,9 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
371372
if (ret)
372373
return ret;
373374

375+
if (num_lines > GPIO_SIM_NGPIO_MAX)
376+
return -ERANGE;
377+
374378
ret = fwnode_property_read_string(swnode, "gpio-sim,label", &label);
375379
if (ret) {
376380
label = devm_kasprintf(dev, GFP_KERNEL, "%s-%s",

0 commit comments

Comments
 (0)