Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "John Crispin" <john@phrozen.org>
Cc: devicetree@vger.kernel.org, mfd@lists.linux.dev, robh@kernel.org,
	conor+dt@kernel.org, lee@kernel.org
Subject: Re: [PATCH v2 3/3] pwm: airoha: add support for AN7589
Date: Fri, 04 Dec 2026 19:55:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-250574@kernel.org> (raw)
In-Reply-To: <20261204193857.3801624-4-john@phrozen.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] pwm: airoha_pwm_disable() unconditionally clears SIPO
  register on AN7589
- [Medium] pwm: unchecked 4-bit bucket index in airoha_pwm_get_state()
  on AN7589
--

commit 9e34a67908ec87aef2e6fb0c34ba57a33ee1533c
Author: John Crispin <john@phrozen.org>

pwm: airoha: add support for AN7589

This commit adds SoC match data and a platform ID table to pwm-airoha to
support the 16-channel AN7589 PWM controller with a 4-bit set-id and a
separate flash enable register.

> diff --git a/drivers/pwm/pwm-airoha.c b/drivers/pwm/pwm-airoha.c
> index 0cf6b011520a2..85e17a9d69b6f 100644
> --- a/drivers/pwm/pwm-airoha.c
> +++ b/drivers/pwm/pwm-airoha.c

[ ... ]

> @@ -550,19 +595,23 @@ static int airoha_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>  	u32 addr, shift, val;
>  	u8 bucket;
>  
> +	ret = airoha_pwm_flash_enabled(pc, hwpwm);
> +	if (ret < 0)
> +		return ret;
> +
> +	state->enabled = ret;
> +	if (!state->enabled)
> +		return 0;
> +
>  	airoha_pwm_get_flash_map_addr_and_shift(hwpwm, &addr, &shift);
>  
>  	ret = regmap_read(pc->regmap, addr, &val);
>  	if (ret)
>  		return ret;
>  
> -	state->enabled = FIELD_GET(AIROHA_PWM_GPIO_FLASH_EN, val >> shift);
> -	if (!state->enabled)
> -		return 0;
> -
>  	state->polarity = PWM_POLARITY_NORMAL;
>  
> -	bucket = FIELD_GET(AIROHA_PWM_GPIO_FLASH_SET_ID, val >> shift);
> +	bucket = field_get(pc->soc->flash_set_id_mask, val >> shift);
>  	return airoha_pwm_get_bucket(pc, bucket, &state->period,
>  				     &state->duty_cycle);
>  }

[Severity: Medium]
Can bucket be >= AIROHA_PWM_NUM_BUCKETS (8) on AN7589 here?

With flash_set_id_mask widened to GENMASK(3, 0), field_get() can return
values 8..15 if firmware or hardware leaves an enabled channel programmed
with bit 3 set.  airoha_pwm_get_bucket() then reads past the 8 generator
registers (0x004c..0x0058 and 0x00a0..0x00a4) and reports bogus state.

Validating bucket < AIROHA_PWM_NUM_BUCKETS before calling
airoha_pwm_get_bucket() would prevent out-of-range register reads.

[ ... ]

> @@ -597,12 +659,37 @@ static int airoha_pwm_probe(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static const struct airoha_pwm_soc_data en7581_pwm_soc_data = {
> +	.npwm = EN7581_PWM_NUM_CHANNELS,
> +	.flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID,
> +	.flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_MAP(0),
> +	.flash_en_mask = AIROHA_PWM_GPIO_FLASH_EN,
> +	.flash_en_stride = AIROHA_PWM_REG_GPIO_FLASH_MAP_SHIFT(1),
> +};
> +
> +static const struct airoha_pwm_soc_data an7589_pwm_soc_data = {
> +	.npwm = AN7589_PWM_NUM_CHANNELS,
> +	.flash_set_id_mask = AIROHA_PWM_GPIO_FLASH_SET_ID_WIDE,
> +	.flash_en_reg = AIROHA_PWM_REG_GPIO_FLASH_EN,
> +	.flash_en_mask = BIT(0),
> +	.flash_en_stride = 1,
> +};

[Severity: Medium]
Will disabling a PWM channel on AN7589 still clear
AIROHA_PWM_REG_SIPO_FLASH_MODE_CFG even though AN7589 has no SIPO
channels?

drivers/pwm/pwm-airoha.c:airoha_pwm_disable() {
    ...
	/* If no SIPO is used, disable the shift register chip */
	if (!bitmap_read(pc->initialized,
			 AIROHA_PWM_NUM_GPIO, AIROHA_PWM_NUM_SIPO))
		regmap_clear_bits(pc->regmap, AIROHA_PWM_REG_SIPO_FLASH_MODE_CFG,
				  AIROHA_PWM_SERIAL_GPIO_FLASH_MODE);
}

Because the SIPO bits of pc->initialized are never set on AN7589, this
condition is always true and every disable clears BIT(1) at offset 0x0030
in the shared GPIO syscon regmap, risking corruption of unrelated register
state.

Guarding this clear on pc->soc->npwm > AIROHA_PWM_NUM_GPIO would avoid
touching that register on AN7589.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204193857.3801624-1-john@phrozen.org?part=3

      reply	other threads:[~2026-12-04 19:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 19:38 [PATCH v2 0/3] pwm: airoha: add AN7589 support John Crispin
2026-12-04 19:38 ` [PATCH v2 1/3] dt-bindings: mfd: airoha: add #pwm-cells to AN7589 gpio-sysctl John Crispin
2026-12-04 19:45   ` sashiko-bot
2026-12-04 19:38 ` [PATCH v2 2/3] mfd: add Airoha GPIO system controller driver John Crispin
2026-12-04 19:50   ` sashiko-bot
2026-12-04 19:38 ` [PATCH v2 3/3] pwm: airoha: add support for AN7589 John Crispin
2026-12-04 19:55   ` sashiko-bot [this message]

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-250574@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=john@phrozen.org \
    --cc=lee@kernel.org \
    --cc=mfd@lists.linux.dev \
    --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