All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cosmin Tanislav" <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	wsa+renesas@sang-engineering.com
Subject: Re: [PATCH 4/9] iio: adc: rzt2h: claim direct mode on single reads
Date: Fri, 28 Aug 2026 15:15:08 +0000	[thread overview]
Message-ID: <20260828151508.598DB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828145943.2077589-5-cosmin-gabriel.tanislav.xa@renesas.com>

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

Pre-existing issues:
- [High] Unsafe 1-jiffy hardware timeout causes spurious failures.
- [High] Late interrupt triggers spurious completion for subsequent reads on timeout.
--

commit 804ca0ac39c62632fae66702cb8c967efd8b7dee
Author: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>

iio: adc: rzt2h: claim direct mode on single reads
    
Claim direct mode around the single read to prevent it from conflicting
with an ongoing buffered read.

> diff --git a/drivers/iio/adc/rzt2h_adc.c b/drivers/iio/adc/rzt2h_adc.c
> index 995308a419f12..95bcebdc02cb3 100644
> --- a/drivers/iio/adc/rzt2h_adc.c
> +++ b/drivers/iio/adc/rzt2h_adc.c
> @@ -158,8 +158,13 @@ static int rzt2h_adc_read_raw(struct iio_dev *indio_dev,
>  	struct rzt2h_adc *adc = iio_priv(indio_dev);
>  
>  	switch (mask) {
> -	case IIO_CHAN_INFO_RAW:
> +	case IIO_CHAN_INFO_RAW: {
> +		IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> +		if (IIO_DEV_ACQUIRE_FAILED(claim))
> +			return -EBUSY;
> +
>  		return rzt2h_adc_read_single(adc, chan->channel, val);

[Severity: High]
This isn't a bug introduced by this patch, but this is a pre-existing issue
in rzt2h_adc_read_single(). Can the 1-jiffy timeout expire instantaneously
and cause spurious failures?

Looking at rzt2h_adc_read_single():

	ret = wait_for_completion_timeout(&adc->completion, usecs_to_jiffies(1));
	if (!ret) {
		ret = -ETIMEDOUT;
		goto disable;
	}

A 1-jiffy timeout can expire almost instantaneously if the next timer tick
occurs immediately after the call. Even though the conversion takes ~0.32us,
could it be outraced by the timer tick, causing the driver to incorrectly assume
a hardware failure and abort the read?

[Severity: High]
This is also a pre-existing issue, but does a timeout in rzt2h_adc_read_single()
leave a pending interrupt that could corrupt subsequent reads?

If a timeout occurs, the cleanup path calls rzt2h_adc_stop() to disable device
interrupts, but it does not synchronize with the IRQ controller. A pending or
concurrently running ISR will unconditionally signal completion:

static irqreturn_t rzt2h_adc_isr(int irq, void *private)
{
	struct rzt2h_adc *adc = private;

	complete(&adc->completion);

	return IRQ_HANDLED;
}

If this late ISR executes immediately after a subsequent read calls
reinit_completion(), could the new read falsely complete instantly and return
stale or garbage data from the ADC before the hardware actually finishes?

> +	}
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 1800;
>  		*val2 = 12;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260828145943.2077589-1-cosmin-gabriel.tanislav.xa@renesas.com?part=4

  reply	other threads:[~2026-08-28 15:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 14:59 [PATCH 0/9] iio: adc: rzt2h: add DMA buffer support Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 1/9] iio: adc: rzt2h: remove unused struct rzt2h_adc::max_channels Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 2/9] iio: adc: rzt2h: store IRQ in private state Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 3/9] iio: adc: rzt2h: store the physical address " Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 4/9] iio: adc: rzt2h: claim direct mode on single reads Cosmin Tanislav
2026-08-28 15:15   ` sashiko-bot [this message]
2026-08-28 14:59 ` [PATCH 5/9] iio: adc: rzt2h: implement DMA buffer support Cosmin Tanislav
2026-08-28 15:13   ` sashiko-bot
2026-08-29  1:20   ` Jonathan Cameron
2026-08-29  1:24     ` Jonathan Cameron
2026-09-03  7:49     ` Cosmin-Gabriel Tanislav
2026-09-04  3:11       ` Jonathan Cameron
2026-08-28 14:59 ` [PATCH 6/9] iio: adc: rzt2h: expose sampling frequency Cosmin Tanislav
2026-08-28 15:14   ` sashiko-bot
2026-08-28 14:59 ` [PATCH 7/9] dt-bindings: iio: adc: renesas,r9a09g077-adc: document DMA support Cosmin Tanislav
2026-08-28 15:14   ` sashiko-bot
2026-08-28 16:21   ` Conor Dooley
2026-08-28 17:17     ` Geert Uytterhoeven
2026-08-31 15:16       ` Conor Dooley
2026-08-28 14:59 ` [PATCH 8/9] arm64: dts: renesas: r9a09g077: Wire up DMA support for ADC Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 9/9] arm64: dts: renesas: r9a09g087: " Cosmin Tanislav

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=20260828151508.598DB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=cosmin-gabriel.tanislav.xa@renesas.com \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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.