dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, dri-devel@lists.freedesktop.org
Cc: media-ci@linuxtv.org, wsa+renesas@sang-engineering.com
Subject: Re: [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer()
Date: Thu, 03 Dec 2026 19:34:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-248521@kernel.org> (raw)
In-Reply-To: <20261203183214.1939736-4-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] i2c: sh_mobile: data race on dma_direction in
  sh_mobile_i2c_dma_callback()
--

commit c6b6af1c3ce9c1df00cdd2b1dc80f991c809d4d9
Author: Lee Jones <lee@kernel.org>

i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer()

This commit terminates and synchronizes any active DMA channel in
sh_mobile_xfer() before freeing the bounce buffer with
i2c_put_dma_safe_msg_buf().  It also selects the DMA channel from
pd->msg->flags, re-checks pd->dma_direction after dmaengine_terminate_sync(),
and reorders sh_mobile_i2c_dma_callback().

> diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
> index 0d10742a8ec0c..d7aa710767c75 100644
> --- a/drivers/i2c/busses/i2c-sh_mobile.c
> +++ b/drivers/i2c/busses/i2c-sh_mobile.c

[ ... ]

> @@ -462,11 +467,10 @@ static void sh_mobile_i2c_dma_callback(void *data)
>  {
>  	struct sh_mobile_i2c_data *pd = data;
>  
> -	sh_mobile_i2c_cleanup_dma(pd, false);
>  	pd->pos = pd->msg->len;
>  	pd->stop_after_dma = true;
> -
>  	iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
> +	sh_mobile_i2c_cleanup_dma(pd, false);
>  }

[Severity: Low]
Does moving sh_mobile_i2c_cleanup_dma() after iic_set_clr() introduce a data
race on pd->dma_direction?

Clearing ICIC_TDMAE and ICIC_RDMAE unmasks the I2C hardware interrupt before
dma_unmap_single() and the store to pd->dma_direction complete:

CPU0 (DMAC threaded IRQ)          CPU1 (<hardirq>)
sh_mobile_i2c_dma_callback()
  iic_set_clr(pd, ICIC, 0, ...)
  sh_mobile_i2c_cleanup_dma()     sh_mobile_i2c_isr()
    dma_unmap_single(...)
    pd->dma_direction = DMA_NONE    if (pd->dma_direction == ...)
                                    <-- data race

sh_mobile_i2c_isr() reads pd->dma_direction unconditionally without locking
or READ_ONCE(), triggering a KCSAN data race on every normal DMA completion.
It can also wake sh_mobile_xfer() before dma_unmap_single() finishes, forcing
dmaengine_terminate_sync() to wait on the callback.

Calling sh_mobile_i2c_cleanup_dma(pd, false) after setting pd->pos and
pd->stop_after_dma, but before iic_set_clr(), avoids both the data race and
the premature wakeup.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203183214.1939736-1-lee@kernel.org?part=3

      reply	other threads:[~2026-12-03 19:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 18:31 [PATCH 00/10] i2c: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
2026-12-03 18:31 ` [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer() Lee Jones
2026-12-03 19:34   ` 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-248521@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lee@kernel.org \
    --cc=media-ci@linuxtv.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox