Skip to content

Commit 608d94b

Browse files
GTLin08kartben
authored andcommitted
drivers/gpio: ite: Validate num_pins to prevent untrusted loop bound
Added a build assert to limit num_pins to a maximum allowable value to prevent potential out-of-bounds access or infinite loops. Signed-off-by: Tim Lin <[email protected]>
1 parent db0f20c commit 608d94b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/gpio/gpio_ite_it8xxx2_v2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
LOG_MODULE_REGISTER(gpio_it8xxx2, LOG_LEVEL_ERR);
2929

30+
#define ITE_GPIO_MAX_PINS 8
31+
3032
/*
3133
* Structure gpio_ite_cfg is about the setting of GPIO
3234
* this config will be used at initial time
@@ -530,6 +532,8 @@ static int gpio_ite_init(const struct device *dev)
530532
}
531533

532534
#define GPIO_ITE_DEV_CFG_DATA(inst) \
535+
BUILD_ASSERT(DT_INST_PROP(inst, ngpios) <= ITE_GPIO_MAX_PINS, \
536+
"The maximum number of pins per port is 8."); \
533537
static struct gpio_ite_data gpio_ite_data_##inst; \
534538
static const struct gpio_ite_cfg gpio_ite_cfg_##inst = { \
535539
.common = {.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(inst)}, \

0 commit comments

Comments
 (0)