From: Mehmet Fide <mehmet.fide@gmail.com>
To: Andi Shyti <andi.shyti@kernel.org>,
Oleksij Rempel <o.rempel@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>,
Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Stefan Eichenberger <eichest@gmail.com>,
Yao Yuan <yao.yuan@freescale.com>, Wolfram Sang <wsa@kernel.org>,
linux-i2c@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
mehmet.fide@screeningeagle.com
Subject: [PATCH v2 2/3] i2c: imx: unmap the DMA buffer when a transfer is terminated
Date: Thu, 19 Nov 2026 14:42:24 +0100 [thread overview]
Message-ID: <20261119134225.265242-3-mehmet.fide@gmail.com> (raw)
In-Reply-To: <20261119134225.265242-1-mehmet.fide@gmail.com>
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The buffer of a DMA transfer is unmapped in the DMA completion callback
only. When the wait for the completion times out the transfer is
terminated, the callback does not run and the mapping is never released.
Unmap the buffer where the transfer is waited for, after the transfer
has completed or has been terminated.
Fixes: ce1a78840ff7 ("i2c: imx: add DMA support for freescale i2c driver")
Cc: stable@vger.kernel.org
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
drivers/i2c/busses/i2c-imx.c | 41 ++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f20727ffb5ce..fbfabceb29ac 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -469,11 +469,26 @@ static void i2c_imx_dma_callback(void *arg)
struct imx_i2c_struct *i2c_imx = (struct imx_i2c_struct *)arg;
struct imx_i2c_dma *dma = i2c_imx->dma;
- dma_unmap_single(dma->chan_using->device->dev, dma->dma_buf,
- dma->dma_len, dma->dma_data_dir);
complete(&dma->cmd_complete);
}
+static int i2c_imx_dma_wait(struct imx_i2c_struct *i2c_imx)
+{
+ struct imx_i2c_dma *dma = i2c_imx->dma;
+ int result = 0;
+
+ if (!wait_for_completion_timeout(&dma->cmd_complete,
+ msecs_to_jiffies(DMA_TIMEOUT)))
+ result = -ETIMEDOUT;
+
+ if (result)
+ dmaengine_terminate_sync(dma->chan_using);
+ dma_unmap_single(dma->chan_using->device->dev, dma->dma_buf,
+ dma->dma_len, dma->dma_data_dir);
+
+ return result;
+}
+
static int i2c_imx_dma_xfer(struct imx_i2c_struct *i2c_imx,
struct i2c_msg *msgs)
{
@@ -1192,7 +1207,6 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
struct i2c_msg *msgs)
{
int result;
- unsigned long time_left;
unsigned int temp = 0;
unsigned long orig_jiffies = jiffies;
struct imx_i2c_dma *dma = i2c_imx->dma;
@@ -1217,13 +1231,9 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx,
* The first byte must be transmitted by the CPU.
*/
imx_i2c_write_reg(i2c_imx_addr_byte(msgs), i2c_imx, IMX_I2C_I2DR);
- time_left = wait_for_completion_timeout(
- &i2c_imx->dma->cmd_complete,
- msecs_to_jiffies(DMA_TIMEOUT));
- if (time_left == 0) {
- dmaengine_terminate_sync(dma->chan_using);
- return -ETIMEDOUT;
- }
+ result = i2c_imx_dma_wait(i2c_imx);
+ if (result)
+ return result;
/* Waiting for transfer complete. */
while (1) {
@@ -1298,7 +1308,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
struct i2c_msg *msgs, bool is_lastmsg)
{
int result;
- unsigned long time_left;
unsigned int temp;
unsigned long orig_jiffies = jiffies;
struct imx_i2c_dma *dma = i2c_imx->dma;
@@ -1321,13 +1330,9 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
if (result)
return result;
- time_left = wait_for_completion_timeout(
- &i2c_imx->dma->cmd_complete,
- msecs_to_jiffies(DMA_TIMEOUT));
- if (time_left == 0) {
- dmaengine_terminate_sync(dma->chan_using);
- return -ETIMEDOUT;
- }
+ result = i2c_imx_dma_wait(i2c_imx);
+ if (result)
+ return result;
/* waiting for transfer complete. */
while (1) {
--
2.56.0
next prev parent reply other threads:[~2026-11-19 13:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 13:42 [PATCH v2 0/3] i2c: imx: fixes for a DMA write that is not acknowledged Mehmet Fide
2026-11-19 13:42 ` [PATCH v2 1/3] i2c: imx: do not carry the interrupt status over to the next transfer Mehmet Fide
2026-11-19 13:42 ` Mehmet Fide [this message]
2026-11-19 13:42 ` [PATCH v2 3/3] i2c: imx: return -ENXIO at once when a DMA write is not acknowledged Mehmet Fide
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=20261119134225.265242-3-mehmet.fide@gmail.com \
--to=mehmet.fide@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=andi.shyti@kernel.org \
--cc=eichest@gmail.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mehmet.fide@screeningeagle.com \
--cc=o.rempel@pengutronix.de \
--cc=s.hauer@pengutronix.de \
--cc=stable@vger.kernel.org \
--cc=wsa@kernel.org \
--cc=yao.yuan@freescale.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
all inboxes | Powered by JetHome®