dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "H. Nikolaus Schaller" <hns@goldelico.com>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org,
	linux-sound@vger.kernel.org, robh@kernel.org,
	conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH v2 02/20] gpio: twl4030: Support REGEN GPIO
Date: Tue, 24 Nov 2026 07:43:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-230662@kernel.org> (raw)
In-Reply-To: <5fe8b5155067e0b1fc9b34c53e3b89a40e53234c.1795505160.git.hns@goldelico.com>

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 <hns@goldelico.com>

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/cover.1795505160.git.hns@goldelico.com?part=2

  reply	other threads:[~2026-11-24  7:43 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  7:25 [PATCH v2 00/20] ARM: omap3: pandora: Modernize audio and backlight to use Device Tree to finally remove pdata-quirks H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 01/20] dt-bindings: gpio: twl4030: Document REGEN GPIO H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 02/20] gpio: twl4030: Support " H. Nikolaus Schaller
2026-11-24  7:43   ` sashiko-bot [this message]
2026-11-24  7:25 ` [PATCH v2 03/20] ASoC: twl4030: Allow APLL rate selection through set_sysclk() H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 04/20] dt-bindings: sound: pcm1754: Describe PCM1773 H. Nikolaus Schaller
2026-11-24 12:05   ` Mark Brown
2026-11-24 14:33     ` [Letux-kernel] " H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 05/20] ASoC: codecs: pcm1754: Add PCM1773 support H. Nikolaus Schaller
2026-11-24 14:48   ` Mark Brown
2026-11-24  7:25 ` [PATCH v2 06/20] dt-bindings: sound: Document OpenPandora sound card H. Nikolaus Schaller
2026-11-24  7:40   ` sashiko-bot
2026-11-24 13:40     ` Rob Herring
2026-11-24 12:04   ` Mark Brown
2026-11-24 13:35   ` Rob Herring (Arm)
2026-11-24 14:42     ` H. Nikolaus Schaller
2026-11-24 14:45   ` Krzysztof Kozlowski
2026-11-24 14:50     ` H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 07/20] ASoC: ti: omap3pandora: Convert sound card to DT H. Nikolaus Schaller
2026-11-24  7:45   ` sashiko-bot
2026-11-24 14:48   ` Mark Brown
2026-11-24 14:55     ` H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 08/20] dt-bindings: mfd: twl4030: Document 64-cycle PWM H. Nikolaus Schaller
2026-11-24 14:40   ` Krzysztof Kozlowski
2026-11-24 14:49     ` H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 09/20] pwm: twl: Support 64-cycle PWM frame H. Nikolaus Schaller
2026-11-24  7:37   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 10/20] dt-bindings: backlight: pwm: Document enable guard H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 11/20] backlight: pwm: Support enable guard period H. Nikolaus Schaller
2026-11-24  7:36   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 12/20] drm/panel: td043mtea1: Attach DT backlight H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 13/20] ARM: dts: omap3pandora: Disable unused DMA channels H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 14/20] ARM: dts: omap3-pandora: Model LCD power enable dependencies H. Nikolaus Schaller
2026-11-24  7:45   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 15/20] ARM: dts: omap3pandora: Enable audio interfaces H. Nikolaus Schaller
2026-11-24  7:25 ` [PATCH v2 16/20] ARM: dts: omap3pandora: Describe PCM1773 H. Nikolaus Schaller
2026-11-24  7:40   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 17/20] ARM: dts: omap3pandora: Describe sound card H. Nikolaus Schaller
2026-11-24  7:47   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 18/20] ARM: dts: omap3pandora: Switch backlight to PWM H. Nikolaus Schaller
2026-11-24  7:46   ` sashiko-bot
2026-11-24  7:25 ` [PATCH v2 19/20] backlight: Remove legacy Pandora driver H. Nikolaus Schaller
2026-11-24  7:26 ` [PATCH v2 20/20] ARM: OMAP2+: Remove Pandora platform-data quirks H. Nikolaus Schaller
2026-11-24 13:38 ` [PATCH v2 00/20] ARM: omap3: pandora: Modernize audio and backlight to use Device Tree to finally remove pdata-quirks Mark Brown
2026-11-24 14:52   ` H. Nikolaus Schaller
2026-11-24 15:13 ` Rob Herring
2026-11-24 15:27   ` H. Nikolaus Schaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-230662@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hns@goldelico.com \
    --cc=lee@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox