diff mbox series

[21/25] ASoC: dmaengine: Convert to generic PCM copy ops

Message ID 20230814115523.15279-22-tiwai@suse.de
State Superseded
Headers show
Series ALSA: Generic PCM copy ops using iov_iter | expand

Commit Message

Takashi Iwai Aug. 14, 2023, 11:55 a.m. UTC
This patch converts the ASoC dmaenging driver code to use the new
unified PCM copy callback.  It's a straightforward conversion from
*_user() to *_iter() variants.

The process callback is still using the direct pointer as of now, but
it'll be converted in the next patch.

Note that copy_from/to_iter() returns the copied bytes, hence the
error condition is inverted from copy_from/to_user().

Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-generic-dmaengine-pcm.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Andy Shevchenko Aug. 15, 2023, 2 p.m. UTC | #1
On Mon, Aug 14, 2023 at 01:55:19PM +0200, Takashi Iwai wrote:
> This patch converts the ASoC dmaenging driver code to use the new
> unified PCM copy callback.  It's a straightforward conversion from
> *_user() to *_iter() variants.
> 
> The process callback is still using the direct pointer as of now, but
> it'll be converted in the next patch.
> 
> Note that copy_from/to_iter() returns the copied bytes, hence the
> error condition is inverted from copy_from/to_user().

...

>  	if (is_playback)
> -		if (copy_from_user(dma_ptr, buf, bytes))
> +		if (!copy_from_iter(dma_ptr, bytes, buf))

!= bytes ?

>  			return -EFAULT;

Can be compressed to a single conditional:

	if (is_playback && copy_from_iter(dma_ptr, bytes, buf) != bytes)

...

>  	if (!is_playback)
> -		if (copy_to_user(buf, dma_ptr, bytes))
> +		if (!copy_to_iter(dma_ptr, bytes, buf))
>  			return -EFAULT;

As per above.
Takashi Iwai Aug. 15, 2023, 2:55 p.m. UTC | #2
On Tue, 15 Aug 2023 16:00:05 +0200,
Andy Shevchenko wrote:
> 
> Can be compressed to a single conditional:
> 
> 	if (is_playback && copy_from_iter(dma_ptr, bytes, buf) != bytes)

I prefer keeping the changes minimalistic in this kind of conversion
unless it becomes too ugly.  Then it's more clearer what's actually
changed.


thanks,

Takashi
Andy Shevchenko Aug. 15, 2023, 3:45 p.m. UTC | #3
On Tue, Aug 15, 2023 at 04:55:24PM +0200, Takashi Iwai wrote:
> On Tue, 15 Aug 2023 16:00:05 +0200,
> Andy Shevchenko wrote:
> > 
> > Can be compressed to a single conditional:
> > 
> > 	if (is_playback && copy_from_iter(dma_ptr, bytes, buf) != bytes)
> 
> I prefer keeping the changes minimalistic in this kind of conversion
> unless it becomes too ugly.  Then it's more clearer what's actually
> changed.

Fine by me!
diff mbox series

Patch

diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 3b99f619e37e..1a4f000fddb9 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -287,10 +287,10 @@  static snd_pcm_uframes_t dmaengine_pcm_pointer(
 		return snd_dmaengine_pcm_pointer(substream);
 }
 
-static int dmaengine_copy_user(struct snd_soc_component *component,
-			       struct snd_pcm_substream *substream,
-			       int channel, unsigned long hwoff,
-			       void __user *buf, unsigned long bytes)
+static int dmaengine_copy(struct snd_soc_component *component,
+			  struct snd_pcm_substream *substream,
+			  int channel, unsigned long hwoff,
+			  struct iov_iter *buf, unsigned long bytes)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct dmaengine_pcm *pcm = soc_component_to_pcm(component);
@@ -300,19 +300,20 @@  static int dmaengine_copy_user(struct snd_soc_component *component,
 	bool is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
 	void *dma_ptr = runtime->dma_area + hwoff +
 			channel * (runtime->dma_bytes / runtime->channels);
+	void *ptr = (void __force *)iter_iov_addr(buf);
 
 	if (is_playback)
-		if (copy_from_user(dma_ptr, buf, bytes))
+		if (!copy_from_iter(dma_ptr, bytes, buf))
 			return -EFAULT;
 
 	if (process) {
-		int ret = process(substream, channel, hwoff, (__force void *)buf, bytes);
+		int ret = process(substream, channel, hwoff, ptr, bytes);
 		if (ret < 0)
 			return ret;
 	}
 
 	if (!is_playback)
-		if (copy_to_user(buf, dma_ptr, bytes))
+		if (!copy_to_iter(dma_ptr, bytes, buf))
 			return -EFAULT;
 
 	return 0;
@@ -337,7 +338,7 @@  static const struct snd_soc_component_driver dmaengine_pcm_component_process = {
 	.hw_params	= dmaengine_pcm_hw_params,
 	.trigger	= dmaengine_pcm_trigger,
 	.pointer	= dmaengine_pcm_pointer,
-	.copy_user	= dmaengine_copy_user,
+	.copy		= dmaengine_copy,
 	.pcm_construct	= dmaengine_pcm_new,
 };