[PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg

From: Lee Jones

Date: Thu Dec 03 2026 - 15:57:22 EST


When a caller leaves config->ngpio as 0 so gpiochip_get_ngpios() reads
chip->ngpio from firmware and also leaves config->ngpio_per_reg as 0,
gpio_regmap_register() falls back to setting gpio->ngpio_per_reg from
config->ngpio (0) instead of chip->ngpio. Subsequent calls to
gpio_regmap_simple_xlate() divide by zero.

Use chip->ngpio as the default value for gpio->ngpio_per_reg.

Fixes: db305161880a ("gpio: regmap: Allow ngpio to be read from the property")
Closes: https://sashiko.dev/#/bug/linux-85577bd9-c441-47ec-b415-cd40acf50e01
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/gpio/gpio-regmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index ac6ad56f4479..65e87177baf0 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -523,7 +523,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
/* if not set, assume there is only one register */
gpio->ngpio_per_reg = config->ngpio_per_reg;
if (!gpio->ngpio_per_reg)
- gpio->ngpio_per_reg = config->ngpio;
+ gpio->ngpio_per_reg = chip->ngpio;

/* if not set, assume they are consecutive */
gpio->reg_stride = config->reg_stride;
--
2.56.1.911.g883d8bcb20-goog