From: Frank Li <Frank.Li@nxp.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Dong Aisheng <aisheng.dong@nxp.com>,
Andi Shyti <andi.shyti@kernel.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>
Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
linux-i2c@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
Frank Li <Frank.Li@nxp.com>
Subject: [PATCH 3/3] i2c: lpi2c: Use auto cleanup for dma_map_single()
Date: Fri, 10 Oct 2025 14:50:26 -0400 [thread overview]
Message-ID: <20251010-dmamap_cleanup-v1-3-ec5bc14e82c4@nxp.com> (raw)
In-Reply-To: <20251010-dmamap_cleanup-v1-0-ec5bc14e82c4@nxp.com>
Use auto cleanup for dma_map_single() to simple code.
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Demostrate to how to use auto cleanup for dma map functiongs. It will
simple more if need map multi buffers at a functions.
---
drivers/i2c/busses/i2c-imx-lpi2c.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index 03b5a7e8c361abe1d75fb4d31f9614bbc6387d93..2c89d441ab1b3e607b8a2b0a6589e5909fa39ef4 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -727,9 +727,11 @@ static int lpi2c_dma_rx_cmd_submit(struct lpi2c_imx_struct *lpi2c_imx)
struct dma_chan *txchan = dma->chan_tx;
dma_cookie_t cookie;
- dma->dma_tx_addr = dma_map_single(txchan->device->dev,
- dma->rx_cmd_buf, dma->rx_cmd_buf_len,
- DMA_TO_DEVICE);
+ CLASS(dma_map_single, dma_addr)(txchan->device->dev,
+ dma->rx_cmd_buf, dma->rx_cmd_buf_len,
+ DMA_TO_DEVICE);
+ dma->dma_tx_addr = dma_addr.ret;
+
if (dma_mapping_error(txchan->device->dev, dma->dma_tx_addr)) {
dev_err(&lpi2c_imx->adapter.dev, "DMA map failed, use pio\n");
return -EINVAL;
@@ -749,18 +751,15 @@ static int lpi2c_dma_rx_cmd_submit(struct lpi2c_imx_struct *lpi2c_imx)
goto submit_err_exit;
}
+ retain_and_empty(dma_addr);
dma_async_issue_pending(txchan);
return 0;
desc_prepare_err_exit:
- dma_unmap_single(txchan->device->dev, dma->dma_tx_addr,
- dma->rx_cmd_buf_len, DMA_TO_DEVICE);
return -EINVAL;
submit_err_exit:
- dma_unmap_single(txchan->device->dev, dma->dma_tx_addr,
- dma->rx_cmd_buf_len, DMA_TO_DEVICE);
dmaengine_desc_free(rx_cmd_desc);
return -EINVAL;
}
--
2.34.1
next prev parent reply other threads:[~2025-10-10 18:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20251010185046eucas1p26868b540b74a96e36943066216525bed@eucas1p2.samsung.com>
2025-10-10 18:50 ` [PATCH 0/3] dma_mapping: Add auto cleanup support Frank Li
2025-10-10 18:50 ` [PATCH 1/3] cleanup: Add DEFINE_GUARD_ARGS_CLASS macro for resource alloc/free functions with multiple arguments Frank Li
2025-10-10 18:50 ` [PATCH 2/3] dma-mapping: Add auto cleanup support dma_map_single() Frank Li
2025-10-10 18:50 ` Frank Li [this message]
2025-10-14 5:54 ` [PATCH 0/3] dma_mapping: Add auto cleanup support Marek Szyprowski
2025-10-19 12:03 ` Leon Romanovsky
2025-10-20 15:56 ` Frank Li
2025-11-06 17:27 ` Frank Li
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=20251010-dmamap_cleanup-v1-3-ec5bc14e82c4@nxp.com \
--to=frank.li@nxp.com \
--cc=aisheng.dong@nxp.com \
--cc=andi.shyti@kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=iommu@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=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@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
all inboxes | Powered by JetHome®