All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 3/8] iio: adc: stm32-adc: add support for stm32mp23 and stm32mp25
Date: Fri, 11 Sep 2026 16:26:02 +0000	[thread overview]
Message-ID: <20260911162602.D323F1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911-adc-stm32mp25-v1-v1-3-cef26eecdef2@foss.st.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Missing bounds check on the `st,adc-trigger-sel` device tree property allows an out-of-bounds array read when indexing `adc->cfg->trigs`.
- [Medium] Missing ADC stop (`ADSTP`) on calibration timeout error path leaves ADC in a locked state.

Pre-existing issues:
- [High] Configuring an unsupported internal channel does not abort setup, leading to errant read-modify-write operations on register offset 0 (ISR), which silently clears unrelated pending interrupts.
--

commit 07a141434d979402aadc3f3eaff7d932ee702232
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

iio: adc: stm32-adc: add support for stm32mp23 and stm32mp25

This commit adds support for the STM32MP23 and STM32MP25 SoCs to the
stm32-adc driver. It introduces support for diversity in IRQs, clocks,
internal voltage channels, and trigger lists by utilizing a dedicated
compatible string and configuration data.

> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
[ ... ]
> @@ -1503,6 +1503,163 @@ static void stm32h7_adc_unprepare(struct iio_dev *indio_dev)
[ ... ]
> +static int stm32mp25_adc_prepare(struct iio_dev *indio_dev)
> +{
> +	struct stm32_adc *adc = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = stm32h7_adc_exit_pwr_down(indio_dev);
> +	if (ret)
> +		return ret;
> +
> +	/* Must enable the ADC before running software-assisted calibration */
> +	ret = stm32h7_adc_enable(indio_dev);
> +	if (ret)
> +		goto pwr_dwn;
> +
> +	/* Always run offset calibration */
> +	ret = stm32mp25_adc_calib(indio_dev);
> +	if (ret)
> +		goto adc_dis;
> +
> +	stm32_adc_int_ch_enable(indio_dev);
> +
> +	stm32_adc_writel(adc, adc->cfg->regs->difsel.reg, adc->difsel);
> +
> +	if (adc->cfg->has_presel)
> +		stm32_adc_writel(adc, STM32H7_ADC_PCSEL, adc->pcsel);
> +
> +	return 0;
> +
> +adc_dis:
> +	stm32h7_adc_disable(indio_dev);

[Severity: Medium]
If calibration times out, does this error path leave the ADC in a locked
state?

If stm32mp25_adc_calib() times out waiting for ADSTART to clear, it returns
an error that jumps to adc_dis. The error path directly calls
stm32h7_adc_disable(), which tries to disable the ADC by setting ADDIS.

However, the hardware specification generally prohibits setting ADDIS while
ADSTART=1. Should the driver first abort the conversion using an
stm32h7_adc_stop_conv() call to set ADSTP and wait for ADSTART to clear
before disabling the hardware?

[ ... ]
> @@ -2641,6 +2641,11 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n
>  					dev_warn(&indio_dev->dev,
>  						 "%s channel not available\n", ch_name);
>  				break;
> +			case STM32_ADC_INT_CH_VDDGPU:
> +				if (!adc->cfg->regs->or_vddgpu.reg)
> +					dev_warn(&indio_dev->dev,
> +						 "%s channel not available\n", ch_name);
> +				break;
>  			}
>  
>  			if (stm32_adc_ic[i].idx != STM32_ADC_INT_CH_VREFINT) {
>  				adc->int_ch[i] = chan;
>  				break;
>  			}

[Severity: High]
This is a pre-existing issue, but does this warning branch fail to abort
channel registration?

If an unsupported internal channel like vddgpu is requested, the driver
prints a warning but falls through and assigns it a valid int_ch below.

This causes a problem later during setup:

stm32_adc_int_ch_enable() {
    ...
    case STM32_ADC_INT_CH_VDDGPU:
        stm32_adc_set_bits(adc, adc->cfg->regs->or_vddgpu.reg,
                           adc->cfg->regs->or_vddgpu.mask);
    ...
}

Because the register offset is uninitialized (0), this performs a
read-modify-write on offset 0, which corresponds to the ISR register. Since
the ISR has read-clear-write-1 semantics, this will silently clear all
currently pending unrelated interrupts.

[ ... ]
> @@ -2914,6 +2914,18 @@ static int stm32_adc_probe(struct platform_device *pdev)
>  	if (ret < 0)
>  		return ret;
>  
> +	if (device_property_present(&pdev->dev, "st,adc-trigger-sel")) {
> +		ret = device_property_read_u32(dev, "st,adc-trigger-sel", &trig_id);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	adc->trigs = adc->cfg->trigs[trig_id];

[Severity: High]
Could an invalid st,adc-trigger-sel value lead to an out-of-bounds read
here?

The st,adc-trigger-sel property is read directly into trig_id and
immediately used to index the adc->cfg->trigs array, which has a fixed
size of 2. 

If a malformed Device Tree provides a larger value, this skips bounds
validation and might cause a memory safety issue by dereferencing
invalid pointers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911-adc-stm32mp25-v1-v1-0-cef26eecdef2@foss.st.com?part=3

  parent reply	other threads:[~2026-09-11 16:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 15:51 [PATCH 0/8] iio: adc: stm32: add support for stm32mp23 and stm32mp25 Fabrice Gasnier
2026-09-11 15:51 ` [PATCH 1/8] dt-bindings: iio: adc: stm32-adc: " Fabrice Gasnier
2026-09-11 16:02   ` sashiko-bot
2026-09-11 18:08   ` Marek Vasut
2026-09-13  3:08   ` Jonathan Cameron
2026-09-11 15:51 ` [PATCH 2/8] iio: adc: stm32-adc: manage characterization voltage diversity Fabrice Gasnier
2026-09-11 16:10   ` Andy Shevchenko
2026-09-11 16:15   ` sashiko-bot
2026-09-11 15:51 ` [PATCH 3/8] iio: adc: stm32-adc: add support for stm32mp23 and stm32mp25 Fabrice Gasnier
2026-09-11 16:22   ` Andy Shevchenko
2026-09-11 16:26   ` sashiko-bot [this message]
2026-09-13  3:25   ` Jonathan Cameron
2026-09-11 15:51 ` [PATCH 4/8] arm64: dts: st: add vrefint calibration on stm32mp23 Fabrice Gasnier
2026-09-11 18:10   ` Marek Vasut
2026-09-11 15:51 ` [PATCH 5/8] arm64: dts: st: add vrefint calibration on stm32mp25 Fabrice Gasnier
2026-09-11 15:51 ` [PATCH 6/8] arm64: dts: st: add ADC nodes on stm32mp231 Fabrice Gasnier
2026-09-11 15:51 ` [PATCH 7/8] arm64: dts: st: add ADC nodes on stm32mp251 Fabrice Gasnier
2026-09-11 15:51 ` [PATCH 8/8] arm64: dts: st: add ADC support on stm32mp257f-ev1 board Fabrice Gasnier

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=20260911162602.D323F1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.