From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C90F2606A324 for ; Thu, 19 Nov 2026 13:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=w39/kk2F; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=jXgxK+eA DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=bV4UJVZ9NL/7DCp8HEJshTGUvYsQkJNidhWUdfBTaSM=; b=w39/kk2FKn+2fu i7nvSzd1HEGt32+Vp+33g28RVZG/4ELzfbe+QSn0vtUXkEyodhkF6kJRPTCINFvjtszKOHK8hO7xO pyde4ZiQG+xi6WYHIDgTPryEy+t/ENrui+S1OvPiDdPZo/ZBTqDXTUYlfvJRY5tZpexIkmXJllh5P iSOh8tyJhUWtuzN9MJ0iCxSMcV5IHz3ZuBWdP7OUdnVRAdD7m5qMr0GSY/AI12xPaX+FjlurZHMpS ZiiHP8ia47kOfQHs49pYaOTwsQb6xTiuxV4VBR6GSPooHZWt+xxZkOEoqeTTw5Pg31LhVxuOpwYza 9uIkFMQUYnupu/RWRS/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xU2PP-0000000C6Ix-1yix; Thu, 19 Nov 2026 13:42:40 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xU2PI-0000000C6EV-3bvW for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2026 13:42:34 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-490d59c3edaso691981f8f.1 for ; Thu, 19 Nov 2026 05:42:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795095751; x=1795700551; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bV4UJVZ9NL/7DCp8HEJshTGUvYsQkJNidhWUdfBTaSM=; b=jXgxK+eASXrP+dpam7YQMEX6Zwud2AckJcMVdVQWUhW845o5tKRG216lNvf8GtzXuR wENcDSLSiE/XJ6X0Vyo1+cRaPo+gF6tD9PQL4nCxQx0wxwjz1ObIK/LMeXgR+TsZjL/J YteSl/X+JCMNS8+bEPlfRcbZB+SIuVLY4yOuyRxmQQ+NP15oNqjFzyZwHY450vBOWcIo /WOfYaxOLAtIOs33/uX/QFIMDtsPZrBF0JWUTK8TVRWs0EXNmUC77rpXgsABtGSozubd c5eDeJfAia1NTe7FYVxwGSBetf4fUoOlUBgXz+WHexHbJ6sdUV/A1P9VbLyDlfk6FA0Q duEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795095751; x=1795700551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=bV4UJVZ9NL/7DCp8HEJshTGUvYsQkJNidhWUd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gkZfJ3twIqjUn9W26jK7B2TeQHHKKXfiQ9Kuh2ZNUlwyRfk81N7 pD7rF2tVA9zmmmzi6c7VBDHEx/vmeXifVWqJL5+TsBcxtLOu45yAYsHbFJhapsPusBdmzJB9ESB 5iyrr1ByEnd5nMpmg2oKT/P64GC/udo2y7o= X-Received: by 2002:a5d:64c4:0:b0:4a8:647c:f962 with SMTP id ffacd0b85a97d-4aa573ee4c2mr3035038f8f.23.1795095750641; Thu, 19 Nov 2026 05:42:30 -0800 (PST) Received: from deb05.proceq.com ([213.160.61.66]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a656095e98sm9437971f8f.42.2026.11.19.05.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2026 05:42:29 -0800 (PST) From: Mehmet Fide To: Andi Shyti , Oleksij Rempel Cc: Pengutronix Kernel Team , Frank Li , Sascha Hauer , Fabio Estevam , Stefan Eichenberger , Yao Yuan , Wolfram Sang , 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 Message-ID: <20261119134225.265242-3-mehmet.fide@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261119134225.265242-1-mehmet.fide@gmail.com> References: <20261119134225.265242-1-mehmet.fide@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261119_054233_038375_2F98DDC5 X-CRM114-Status: GOOD ( 15.79 ) X-Spam-Score: -1.1 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_GMAIL_RCVD, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Mehmet Fide 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 --- 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