DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aniket Randive" <aniket.randive@oss.qualcomm.com>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH v1 3/3] i2c: qcom-geni: Add bus recovery support for GPI DMA mode
Date: Wed, 26 Aug 2026 10:05:00 +0000	[thread overview]
Message-ID: <20260826100500.9D9C21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260826-i2c_bus_recovery-v1-3-203f0ec76f84@oss.qualcomm.com>

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

Pre-existing issues:
- [Critical] Double free and invalid DMA unmap in geni_i2c_gpi_xfer() due to uninitialized rx_buf across loop iterations.
--

commit 1ca4e6273080dc8f5231d9130b61334c26638357
Author: Aniket Randive <aniket.randive@oss.qualcomm.com>

i2c: qcom-geni: Add bus recovery support for GPI DMA mode

This commit adds bus recovery support for GPI DMA mode in the QCOM GENI I2C
driver. It implements I2C_BUS_CLEAR and I2C_STOP_ON_BUS opcodes via the
GPI TX DMA channel and updates the recovery trigger logic.

> diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
> index 9fa1a8ac400c3..85cb1367958c6 100644
> --- a/drivers/i2c/busses/i2c-qcom-geni.c
> +++ b/drivers/i2c/busses/i2c-qcom-geni.c

[ ... ]

> @@ -1066,14 +1136,18 @@ static int geni_i2c_xfer(struct i2c_adapter *adap,
>  	else
>  		ret = geni_i2c_fifo_xfer(gi2c, msgs, num);

[Severity: Critical]
This is a pre-existing issue, but I noticed a potential double-free and
invalid DMA unmap in geni_i2c_gpi_xfer() during multi-message transfers.

Looking at geni_i2c_gpi_xfer() which is called just above this context,
the rx_buf pointer is initialized outside the message processing loop:

drivers/i2c/busses/i2c-qcom-geni.c:geni_i2c_gpi_xfer() {
    void *tx_buf = NULL, *rx_buf = NULL;
    ...
    for (i = 0; i < num; i++) {
        ...
        if (msgs[i].flags & I2C_M_RD) {
            ret =  geni_i2c_gpi(gi2c, msgs, &config,
                                &rx_addr, &rx_buf, I2C_READ, gi2c->rx_c);
        ...
        if (!gi2c->is_tx_multi_desc_xfer)
            geni_i2c_gpi_unmap(gi2c, &msgs[i], tx_buf, tx_addr, rx_buf, rx_addr);
}

If a multi-message transfer contains a read message followed by a write
message, rx_buf is allocated and set during the read message. During the
subsequent write message, the I2C_M_RD block is skipped, meaning rx_buf
is never reset to NULL.

The stale rx_buf pointer is then passed again to geni_i2c_gpi_unmap() at
the end of the write iteration:

drivers/i2c/busses/i2c-qcom-geni.c:geni_i2c_gpi_unmap() {
    ...
    if (rx_buf) {
        dma_unmap_single(gi2c->se.dev->parent, rx_addr, msg->len, DMA_FROM_DEVICE);
        i2c_put_dma_safe_msg_buf(rx_buf, msg, !gi2c->err);
    }
}

Could this lead to a double-free of the bounce buffer and an invalid DMA
unmap since rx_buf retains its value from the previous read iteration?

> -	if (!gi2c->gpi_mode &&
> -	    (ret == -EPROTO || ret == -ETIMEDOUT || ret == -EAGAIN)) {
> +	if (ret == -EPROTO || ret == -ETIMEDOUT || ret == -EAGAIN ||
> +	    (gi2c->gpi_mode && ret == -EIO)) {
>  		/*
>  		 * Only attempt recovery if SDA is stuck low. -EPROTO and
>  		 * -ETIMEDOUT indicate bus errors where the target may be

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260826-i2c_bus_recovery-v1-0-203f0ec76f84@oss.qualcomm.com?part=3

  reply	other threads:[~2026-08-26 10:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26  9:51 [PATCH 0/3] i2c: qcom-geni: Add I2C bus recovery support Aniket Randive
2026-08-26  9:51 ` [PATCH v1 1/3] dmaengine: qcom: gpi: Add I2C bus recovery opcode support Aniket Randive
2026-08-26  9:51 ` [PATCH v1 2/3] i2c: qcom-geni: Add bus recovery support for FIFO mode Aniket Randive
2026-08-26 10:03   ` sashiko-bot
2026-09-03 16:17   ` Jyothi Kumar Seerapu
2026-08-26  9:51 ` [PATCH v1 3/3] i2c: qcom-geni: Add bus recovery support for GPI DMA mode Aniket Randive
2026-08-26 10:05   ` sashiko-bot [this message]
2026-09-03 16:14   ` Jyothi Kumar Seerapu

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=20260826100500.9D9C21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=aniket.randive@oss.qualcomm.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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