Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] gpio: twl4030: REGEN usage_count corruption breaks REG_GPIO_CTRL power control - [Medium] gpio: twl4030: unchecked use_leds in twl_request() exposes disabled LED GPIOs --
commit 21b2429c7b13ebb306ae7f98703ac0b013d40ac3 Author: H. Nikolaus Schaller <[email protected]> gpio: twl4030: Support REGEN GPIO This commit adds optional support for exposing the TWL4030 REGEN control signal as an output-only GPIO when the ti,use-regen device tree property is present. > diff --git a/drivers/gpio/gpio-twl4030.c b/drivers/gpio/gpio-twl4030.c > index 3e06ef9e22336..30ac6f7e0e56a 100644 > --- a/drivers/gpio/gpio-twl4030.c > +++ b/drivers/gpio/gpio-twl4030.c [ ... ] > @@ -211,8 +301,16 @@ static int twl_request(struct gpio_chip *chip, unsigned > offset) > > mutex_lock(&priv->mutex); > > + /* > + * REGEN is controlled through the power-management registers > + * and does not require enabling the GPIO module. > + */ > + if (offset == TWL4030_GPIO_REGEN) > + goto done; > + > /* Support the two LED outputs as output-only GPIOs. */ > - if (offset >= TWL4030_GPIO_MAX) { > + if (offset >= TWL4030_GPIO_LED_A && > + offset <= TWL4030_GPIO_LED_B) { > u8 ledclr_mask = LEDEN_LEDAON | LEDEN_LEDAEXT > | LEDEN_LEDAPWM | LEDEN_PWM_LENGTHA; > u8 reg = TWL4030_PWMAON_REG; > @@ -249,6 +347,15 @@ static int twl_request(struct gpio_chip *chip, unsigned > offset) > goto done; > } > > + /* > + * Offsets 18/19 are reserved for the optional LEDs. If the LEDs > + * aren't enabled, they must not be treated as LED GPIOs. > + */ > + if (offset >= TWL4030_GPIO_MAX) { > + status = -EINVAL; > + goto done; > + } [Severity: Medium] Can this `offset >= TWL4030_GPIO_MAX` check ever be reached, or does twl_request() still treat offsets 18 and 19 as valid LED GPIOs when ti,use-regen is enabled without ti,use-leds? In gpio_twl4030_probe(), pdata->use_regen extends ngpio to TWL4030_GPIO_REGEN + 1 without recording whether pdata->use_leds is set. Because TWL4030_GPIO_LED_A and TWL4030_GPIO_LED_B are unconditionally matched right above this check (and TWL4030_GPIO_REGEN is handled at the top), requesting or driving offset 18 or 19 succeeds and reprograms the TWL4030_MODULE_LED registers even when ti,use-leds is not enabled. > + > /* on first use, turn GPIO module "on" */ > if (!priv->usage_count) { > struct twl4030_gpio_platform_data *pdata; > @@ -277,8 +384,18 @@ static void twl_free(struct gpio_chip *chip, unsigned > offset) > struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); > > mutex_lock(&priv->mutex); > + if (offset == TWL4030_GPIO_REGEN) > + goto out; > + > + if (offset >= TWL4030_GPIO_LED_A && > + offset <= TWL4030_GPIO_LED_B) { > + WARN_ON_ONCE(twl4030_led_set_value(offset - > + TWL4030_GPIO_LED_A, 1)); > + goto out; > + } > + > if (offset >= TWL4030_GPIO_MAX) { > - WARN_ON_ONCE(twl4030_led_set_value(offset - TWL4030_GPIO_MAX, > 1)); > + WARN_ON_ONCE(true); > goto out; > } > [Severity: High] Does jumping to `done` in twl_request() and `out` in twl_free() for TWL4030_GPIO_REGEN break REG_GPIO_CTRL power management via priv->usage_count? In twl_request(), `if (offset == TWL4030_GPIO_REGEN) goto done;` skips enabling REG_GPIO_CTRL on first use, but `done:` still sets BIT(TWL4030_GPIO_REGEN) in priv->usage_count. If REGEN is requested before any regular GPIO (0..17), `!priv->usage_count` is already false when the first regular GPIO is requested, so REG_GPIO_CTRL is never written and the GPIO module stays powered off. In twl_free(), `if (offset == TWL4030_GPIO_REGEN) goto out;` jumps past `priv->usage_count &= ~BIT(offset);`, leaving BIT(TWL4030_GPIO_REGEN) set forever once REGEN has been requested. As a result, freeing all regular GPIOs can never power down REG_GPIO_CTRL, and twl_get() continues to treat REGEN as requested after it is freed. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=2
