Skip to contentSkip to conversation

gpio: sim: set a limit on the number of GPIOs

PATCH Applied Bartosz Golaszewski 1 participant 2 messages Dec 12, 2022 – Dec 14, 2022 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: sim: set a limit on the number of GPIOs

From: Bartosz Golaszewski <[email protected]>

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.

---
 drivers/gpio/gpio-sim.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpio-sim.c +4 -0
index 1020c2feb249..60514bc5454f 100644
@@ -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",
Signature · 1 line
2.37.2
author Applied
#1 lore raw
Quoted 42 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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.

---
 drivers/gpio/gpio-sim.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpio/gpio-sim.c +4 -1
index 1020c2feb249..60514bc5454f 100644
@@ -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",
--
Quoted 2 lines

2.37.2

Applied this, as it needs to go into the big PR for this merge window.

Bart