linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [stable 4.19+][PATCH 05/20] media: stm32-dcmi: fix DMA corruption when stopping streaming
Date: Fri, 15 Nov 2019 15:33:41 -0700	[thread overview]
Message-ID: <20191115223356.27675-5-mathieu.poirier@linaro.org> (raw)
In-Reply-To: <20191115223356.27675-1-mathieu.poirier@linaro.org>

From: Hugues Fruchet <hugues.fruchet@st.com>

commit b3ce6f6ff3c260ee53b0f2236e5fd950d46957da upstream

Avoid call of dmaengine_terminate_all() between
dmaengine_prep_slave_single() and dmaengine_submit() by locking
the whole DMA submission sequence.

Signed-off-by: Hugues Fruchet <hugues.fruchet@st.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Cc: stable <stable@vger.kernel.org> # 4.19+
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index 1d9c028e52cb..d86944109cbf 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -164,6 +164,9 @@ struct stm32_dcmi {
 	int				errors_count;
 	int				overrun_count;
 	int				buffers_count;
+
+	/* Ensure DMA operations atomicity */
+	struct mutex			dma_lock;
 };
 
 static inline struct stm32_dcmi *notifier_to_dcmi(struct v4l2_async_notifier *n)
@@ -314,6 +317,13 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi,
 		return ret;
 	}
 
+	/*
+	 * Avoid call of dmaengine_terminate_all() between
+	 * dmaengine_prep_slave_single() and dmaengine_submit()
+	 * by locking the whole DMA submission sequence
+	 */
+	mutex_lock(&dcmi->dma_lock);
+
 	/* Prepare a DMA transaction */
 	desc = dmaengine_prep_slave_single(dcmi->dma_chan, buf->paddr,
 					   buf->size,
@@ -322,6 +332,7 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi,
 	if (!desc) {
 		dev_err(dcmi->dev, "%s: DMA dmaengine_prep_slave_single failed for buffer phy=%pad size=%zu\n",
 			__func__, &buf->paddr, buf->size);
+		mutex_unlock(&dcmi->dma_lock);
 		return -EINVAL;
 	}
 
@@ -333,9 +344,12 @@ static int dcmi_start_dma(struct stm32_dcmi *dcmi,
 	dcmi->dma_cookie = dmaengine_submit(desc);
 	if (dma_submit_error(dcmi->dma_cookie)) {
 		dev_err(dcmi->dev, "%s: DMA submission failed\n", __func__);
+		mutex_unlock(&dcmi->dma_lock);
 		return -ENXIO;
 	}
 
+	mutex_unlock(&dcmi->dma_lock);
+
 	dma_async_issue_pending(dcmi->dma_chan);
 
 	return 0;
@@ -717,7 +731,9 @@ static void dcmi_stop_streaming(struct vb2_queue *vq)
 	spin_unlock_irq(&dcmi->irqlock);
 
 	/* Stop all pending DMA operations */
+	mutex_lock(&dcmi->dma_lock);
 	dmaengine_terminate_all(dcmi->dma_chan);
+	mutex_unlock(&dcmi->dma_lock);
 
 	pm_runtime_put(dcmi->dev);
 
@@ -1719,6 +1735,7 @@ static int dcmi_probe(struct platform_device *pdev)
 
 	spin_lock_init(&dcmi->irqlock);
 	mutex_init(&dcmi->lock);
+	mutex_init(&dcmi->dma_lock);
 	init_completion(&dcmi->complete);
 	INIT_LIST_HEAD(&dcmi->buffers);
 
-- 
2.17.1


  parent reply	other threads:[~2019-11-15 22:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 22:33 [stable 4.19+][PATCH 01/20] i2c: stm32f7: fix first byte to send in slave mode Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 02/20] ARM: dts: stm32: relax qspi pins slew-rate for stm32mp157 Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 03/20] mailbox: stm32_ipcc: add spinlock to fix channels concurrent access Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 04/20] crypto: stm31/hash - Fix hmac issue more than 256 bytes Mathieu Poirier
2019-11-15 22:33 ` Mathieu Poirier [this message]
2019-11-15 22:33 ` [stable 4.19+][PATCH 06/20] media: stm32-dcmi: fix check of pm_runtime_get_sync return value Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 07/20] hwrng: stm32 - fix unbalanced pm_runtime_enable Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 08/20] remoteproc: fix rproc_da_to_va in case of unallocated carveout Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 09/20] clk: stm32mp1: fix HSI divider flag Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 10/20] clk: stm32mp1: fix mcu divider table Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 11/20] clk: stm32mp1: add CLK_SET_RATE_NO_REPARENT to Kernel clocks Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 12/20] clk: stm32mp1: parent clocks update Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 13/20] mailbox: mailbox-test: fix null pointer if no mmio Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 14/20] pinctrl: stm32: fix memory leak issue Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 15/20] ASoC: stm32: i2s: fix dma configuration Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 16/20] ASoC: stm32: i2s: fix 16 bit format support Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 17/20] ASoC: stm32: i2s: fix IRQ clearing Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 18/20] ASoC: stm32: sai: add missing put_device() Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 19/20] media: ov5640: fix framerate update Mathieu Poirier
2019-11-15 22:33 ` [stable 4.19+][PATCH 20/20] dmaengine: stm32-dma: check whether length is aligned on FIFO threshold Mathieu Poirier
2019-11-21 20:35 ` [stable 4.19+][PATCH 01/20] i2c: stm32f7: fix first byte to send in slave mode Greg KH
2019-11-22 16:27   ` Mathieu Poirier

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=20191115223356.27675-5-mathieu.poirier@linaro.org \
    --to=mathieu.poirier@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.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;
as well as URLs for NNTP newsgroup(s).