linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: at91-sama5d2_adc: fix DMA conversion crash
@ 2020-09-16  7:08 Eugen Hristev
  2020-09-17 17:28 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Eugen Hristev @ 2020-09-16  7:08 UTC (permalink / raw)
  To: jic23, alexandru.ardelean
  Cc: linux-iio, linux-arm-kernel, linux-kernel, Eugen Hristev

After the move of the postenable code to preenable, the DMA start was
done before the DMA init, which is not correct.
The DMA is initialized in set_watermark. Because of this, we need to call
the DMA start functions in set_watermark, after the DMA init, instead of
preenable hook, when the DMA is not properly setup yet.

Fixes: f3c034f61775 ("iio: at91-sama5d2_adc: adjust iio_triggered_buffer_{predisable,postenable} positions")
Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---

Hi,

This crash is in the kernel since 5.8-rc1

Please have a look at discussion here:
https://lore.kernel.org/linux-iio/CA+U=DsqRUtjjoe5nevP_wNxTgr27+O2V1h9w7d3QijBQ+5f3XA@mail.gmail.com/T/#t

Thanks !

 drivers/iio/adc/at91-sama5d2_adc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index de9583d6cddd..b5196797dcb8 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -884,7 +884,7 @@ static bool at91_adc_current_chan_is_touch(struct iio_dev *indio_dev)
 			       AT91_SAMA5D2_MAX_CHAN_IDX + 1);
 }
 
-static int at91_adc_buffer_preenable(struct iio_dev *indio_dev)
+static int at91_adc_buffer_prepare(struct iio_dev *indio_dev)
 {
 	int ret;
 	u8 bit;
@@ -901,7 +901,7 @@ static int at91_adc_buffer_preenable(struct iio_dev *indio_dev)
 	/* we continue with the triggered buffer */
 	ret = at91_adc_dma_start(indio_dev);
 	if (ret) {
-		dev_err(&indio_dev->dev, "buffer postenable failed\n");
+		dev_err(&indio_dev->dev, "buffer prepare failed\n");
 		return ret;
 	}
 
@@ -989,7 +989,6 @@ static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev)
 }
 
 static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {
-	.preenable = &at91_adc_buffer_preenable,
 	.postdisable = &at91_adc_buffer_postdisable,
 };
 
@@ -1586,7 +1585,11 @@ static int at91_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
 	else if (val > 1)
 		at91_adc_dma_init(to_platform_device(&indio_dev->dev));
 
-	return 0;
+	/*
+	 * We can start the DMA only after setting the watermark and
+	 * having the DMA initialization completed
+	 */
+	return at91_adc_buffer_prepare(indio_dev);
 }
 
 static int at91_adc_update_scan_mode(struct iio_dev *indio_dev,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: adc: at91-sama5d2_adc: fix DMA conversion crash
  2020-09-16  7:08 [PATCH] iio: adc: at91-sama5d2_adc: fix DMA conversion crash Eugen Hristev
@ 2020-09-17 17:28 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2020-09-17 17:28 UTC (permalink / raw)
  To: Eugen Hristev
  Cc: alexandru.ardelean, linux-iio, linux-arm-kernel, linux-kernel

On Wed, 16 Sep 2020 10:08:21 +0300
Eugen Hristev <eugen.hristev@microchip.com> wrote:

> After the move of the postenable code to preenable, the DMA start was
> done before the DMA init, which is not correct.
> The DMA is initialized in set_watermark. Because of this, we need to call
> the DMA start functions in set_watermark, after the DMA init, instead of
> preenable hook, when the DMA is not properly setup yet.
> 
> Fixes: f3c034f61775 ("iio: at91-sama5d2_adc: adjust iio_triggered_buffer_{predisable,postenable} positions")
> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>

Basic approach looks fine, but if we were to get an error from  the
buffer_prepare() function, should we be looking to disable dma if we
enabled it earlier in the set_watermark callback?

> ---
> 
> Hi,
> 
> This crash is in the kernel since 5.8-rc1
> 
> Please have a look at discussion here:
> https://lore.kernel.org/linux-iio/CA+U=DsqRUtjjoe5nevP_wNxTgr27+O2V1h9w7d3QijBQ+5f3XA@mail.gmail.com/T/#t
> 
> Thanks !
> 
>  drivers/iio/adc/at91-sama5d2_adc.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
> index de9583d6cddd..b5196797dcb8 100644
> --- a/drivers/iio/adc/at91-sama5d2_adc.c
> +++ b/drivers/iio/adc/at91-sama5d2_adc.c
> @@ -884,7 +884,7 @@ static bool at91_adc_current_chan_is_touch(struct iio_dev *indio_dev)
>  			       AT91_SAMA5D2_MAX_CHAN_IDX + 1);
>  }
>  
> -static int at91_adc_buffer_preenable(struct iio_dev *indio_dev)
> +static int at91_adc_buffer_prepare(struct iio_dev *indio_dev)
>  {
>  	int ret;
>  	u8 bit;
> @@ -901,7 +901,7 @@ static int at91_adc_buffer_preenable(struct iio_dev *indio_dev)
>  	/* we continue with the triggered buffer */
>  	ret = at91_adc_dma_start(indio_dev);
>  	if (ret) {
> -		dev_err(&indio_dev->dev, "buffer postenable failed\n");
> +		dev_err(&indio_dev->dev, "buffer prepare failed\n");
>  		return ret;
>  	}
>  
> @@ -989,7 +989,6 @@ static int at91_adc_buffer_postdisable(struct iio_dev *indio_dev)
>  }
>  
>  static const struct iio_buffer_setup_ops at91_buffer_setup_ops = {
> -	.preenable = &at91_adc_buffer_preenable,
>  	.postdisable = &at91_adc_buffer_postdisable,
>  };
>  
> @@ -1586,7 +1585,11 @@ static int at91_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
>  	else if (val > 1)
>  		at91_adc_dma_init(to_platform_device(&indio_dev->dev));
>  
> -	return 0;
> +	/*
> +	 * We can start the DMA only after setting the watermark and
> +	 * having the DMA initialization completed
> +	 */

Looks superficially to me like we may need to unwind some stuff if this fails.

> +	return at91_adc_buffer_prepare(indio_dev);
>  }
>  
>  static int at91_adc_update_scan_mode(struct iio_dev *indio_dev,


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-17 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16  7:08 [PATCH] iio: adc: at91-sama5d2_adc: fix DMA conversion crash Eugen Hristev
2020-09-17 17:28 ` Jonathan Cameron

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).