Skip to content

Commit 1a1190b

Browse files
Upsylonbaregregkh
authored andcommitted
i2c: stm32f7: unmap DMA mapped buffer
commit 6aae87f upstream. Before each I2C transfer using DMA, the I2C buffer is DMA'pped to make sure the memory buffer is DMA'able. This is handle in the function `stm32_i2c_prep_dma_xfer()`. If the transfer fails for any reason the I2C buffer must be unmap. Use the dma_callback to factorize the code and fix this issue. Note that the `stm32f7_i2c_dma_callback()` is now called in case of DMA transfer success and error and that the `complete()` on the dma_complete completion structure is done inconditionnally in case of transfer success or error as well as the `dmaengine_terminate_async()`. This is allowed as a `complete()` in case transfer error has no effect as well as a `dmaengine_terminate_async()` on a transfer success. Also fix the unneeded cast and remove not more needed variables. Fixes: 7ecc8cf ("i2c: i2c-stm32f7: Add DMA support") Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com> Cc: <stable@vger.kernel.org> # v4.18+ Acked-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20250704-i2c-upstream-v4-2-84a095a2c728@foss.st.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 79b6352 commit 1a1190b

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

drivers/i2c/busses/i2c-stm32f7.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,11 @@ static void stm32f7_i2c_disable_dma_req(struct stm32f7_i2c_dev *i2c_dev)
739739

740740
static void stm32f7_i2c_dma_callback(void *arg)
741741
{
742-
struct stm32f7_i2c_dev *i2c_dev = (struct stm32f7_i2c_dev *)arg;
742+
struct stm32f7_i2c_dev *i2c_dev = arg;
743743
struct stm32_i2c_dma *dma = i2c_dev->dma;
744744

745745
stm32f7_i2c_disable_dma_req(i2c_dev);
746+
dmaengine_terminate_async(dma->chan_using);
746747
dma_unmap_single(i2c_dev->dev, dma->dma_buf, dma->dma_len,
747748
dma->dma_data_dir);
748749
complete(&dma->dma_complete);
@@ -1510,7 +1511,6 @@ static irqreturn_t stm32f7_i2c_handle_isr_errs(struct stm32f7_i2c_dev *i2c_dev,
15101511
u16 addr = f7_msg->addr;
15111512
void __iomem *base = i2c_dev->base;
15121513
struct device *dev = i2c_dev->dev;
1513-
struct stm32_i2c_dma *dma = i2c_dev->dma;
15141514

15151515
/* Bus error */
15161516
if (status & STM32F7_I2C_ISR_BERR) {
@@ -1551,10 +1551,8 @@ static irqreturn_t stm32f7_i2c_handle_isr_errs(struct stm32f7_i2c_dev *i2c_dev,
15511551
}
15521552

15531553
/* Disable dma */
1554-
if (i2c_dev->use_dma) {
1555-
stm32f7_i2c_disable_dma_req(i2c_dev);
1556-
dmaengine_terminate_async(dma->chan_using);
1557-
}
1554+
if (i2c_dev->use_dma)
1555+
stm32f7_i2c_dma_callback(i2c_dev);
15581556

15591557
i2c_dev->master_mode = false;
15601558
complete(&i2c_dev->complete);
@@ -1600,7 +1598,6 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
16001598
{
16011599
struct stm32f7_i2c_dev *i2c_dev = data;
16021600
struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
1603-
struct stm32_i2c_dma *dma = i2c_dev->dma;
16041601
void __iomem *base = i2c_dev->base;
16051602
u32 status, mask;
16061603
int ret;
@@ -1619,10 +1616,8 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
16191616
dev_dbg(i2c_dev->dev, "<%s>: Receive NACK (addr %x)\n",
16201617
__func__, f7_msg->addr);
16211618
writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR);
1622-
if (i2c_dev->use_dma) {
1623-
stm32f7_i2c_disable_dma_req(i2c_dev);
1624-
dmaengine_terminate_async(dma->chan_using);
1625-
}
1619+
if (i2c_dev->use_dma)
1620+
stm32f7_i2c_dma_callback(i2c_dev);
16261621
f7_msg->result = -ENXIO;
16271622
}
16281623

@@ -1640,8 +1635,7 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
16401635
ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ);
16411636
if (!ret) {
16421637
dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__);
1643-
stm32f7_i2c_disable_dma_req(i2c_dev);
1644-
dmaengine_terminate_async(dma->chan_using);
1638+
stm32f7_i2c_dma_callback(i2c_dev);
16451639
f7_msg->result = -ETIMEDOUT;
16461640
}
16471641
}

0 commit comments

Comments
 (0)