public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter
@ 2023-08-14 11:54 Takashi Iwai
  2023-08-14 11:54 ` [PATCH 01/25] iov_iter: Export import_ubuf() Takashi Iwai
                   ` (24 more replies)
  0 siblings, 25 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:54 UTC (permalink / raw)
  To: alsa-devel
  Cc: linux-kernel, Takashi Iwai, Alexander Viro, Andy Shevchenko,
	Andrey Utkin, Anton Sviridenko, Arnaud Pouliquen, Banajit Goswami,
	Bluecherry Maintainers, Claudiu Beznea, Ismael Luceno,
	Lars-Peter Clausen, Mark Brown, Mauro Carvalho Chehab,
	Oleksandr Andrushchenko, Olivier Moysan, Srinivas Kandagatla,
	linux-media, xen-devel

Hi,

this is a revised patch set for cleaning up the PCM copy ops using
iov_iter to deal with kernel / user-space pointers consistently.

The previous patch set was based on sockptr_t:
  https://lore.kernel.org/r/20230731154718.31048-1-tiwai@suse.de
But this approach was NAK'ed as iov_iter is a preferred way for
achieving the purpose:
  https://lore.kernel.org/r/87edkce118.wl-tiwai@suse.de

The patch set starts with the missing export of import_ubuf()
function, followed by the new copy_ops using iov_iter, extensions of
some helpers and replacements of the existing code.  It resulted in a
good amount of code reduction.


Takashi

===

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Andrey Utkin <andrey_utkin@fastmail.com>
Cc: Anton Sviridenko <anton@corp.bluecherry.net>
Cc: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Cc: Banajit Goswami <bgoswami@quicinc.com>
Cc: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Ismael Luceno <ismael@iodev.co.uk>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Mark Brown <broonie@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Cc: Olivier Moysan <olivier.moysan@foss.st.com>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: linux-media@vger.kernel.org
Cc: xen-devel@lists.xenproject.org

===

Takashi Iwai (25):
  iov_iter: Export import_ubuf()
  ALSA: pcm: Add copy ops with iov_iter
  ALSA: core: Add memory copy helpers between iov_iter and iomem
  ALSA: dummy: Convert to generic PCM copy ops
  ALSA: gus: Convert to generic PCM copy ops
  ALSA: emu8000: Convert to generic PCM copy ops
  ALSA: es1938: Convert to generic PCM copy ops
  ALSA: korg1212: Convert to generic PCM copy ops
  ALSA: nm256: Convert to generic PCM copy ops
  ALSA: rme32: Convert to generic PCM copy ops
  ALSA: rme96: Convert to generic PCM copy ops
  ALSA: hdsp: Convert to generic PCM copy ops
  ALSA: rme9652: Convert to generic PCM copy ops
  ALSA: sh: Convert to generic PCM copy ops
  ALSA: xen: Convert to generic PCM copy ops
  ALSA: pcmtest: Update comment about PCM copy ops
  media: solo6x10: Convert to generic PCM copy ops
  ASoC: component: Add generic PCM copy ops
  ASoC: mediatek: Convert to generic PCM copy ops
  ASoC: qcom: Convert to generic PCM copy ops
  ASoC: dmaengine: Convert to generic PCM copy ops
  ASoC: dmaengine: Use iov_iter for process callback, too
  ALSA: doc: Update description for the new PCM copy ops
  ASoC: pcm: Drop obsoleted PCM copy_user ops
  ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops

 .../kernel-api/writing-an-alsa-driver.rst     | 58 ++++-------
 drivers/media/pci/solo6x10/solo6x10-g723.c    | 38 +-------
 include/sound/dmaengine_pcm.h                 |  2 +-
 include/sound/pcm.h                           | 13 ++-
 include/sound/soc-component.h                 | 14 +--
 lib/iov_iter.c                                |  1 +
 sound/core/memory.c                           | 56 +++++++++--
 sound/core/pcm_lib.c                          | 95 ++++++++++---------
 sound/core/pcm_native.c                       |  2 +-
 sound/drivers/dummy.c                         | 12 +--
 sound/drivers/pcmtest.c                       |  2 +-
 sound/isa/gus/gus_pcm.c                       | 23 +----
 sound/isa/sb/emu8000_pcm.c                    | 74 ++++-----------
 sound/pci/es1938.c                            | 30 +-----
 sound/pci/korg1212/korg1212.c                 | 50 +++-------
 sound/pci/nm256/nm256.c                       | 42 ++------
 sound/pci/rme32.c                             | 50 +++-------
 sound/pci/rme96.c                             | 42 ++------
 sound/pci/rme9652/hdsp.c                      | 42 ++------
 sound/pci/rme9652/rme9652.c                   | 46 ++-------
 sound/sh/sh_dac_audio.c                       | 25 +----
 sound/soc/atmel/mchp-pdmc.c                   |  2 +-
 sound/soc/mediatek/common/mtk-btcvsd.c        | 23 ++---
 sound/soc/qcom/lpass-platform.c               | 13 +--
 sound/soc/soc-component.c                     | 10 +-
 sound/soc/soc-generic-dmaengine-pcm.c         | 18 ++--
 sound/soc/soc-pcm.c                           |  4 +-
 sound/soc/stm/stm32_sai_sub.c                 |  2 +-
 sound/xen/xen_snd_front_alsa.c                | 55 ++---------
 29 files changed, 263 insertions(+), 581 deletions(-)

-- 
2.35.3


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

* [PATCH 01/25] iov_iter: Export import_ubuf()
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
@ 2023-08-14 11:54 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 02/25] ALSA: pcm: Add copy ops with iov_iter Takashi Iwai
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:54 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai, Alexander Viro

Export import_ubuf() to be used in sound subsystem for generic memory
handling as Linus suggested.  It's used for constructing an iov_iter
of a single segment user-space copy for PCM data.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/r/CAHk-=wh-mUL6mp4chAc6E_UjwpPLyCPRCJK+iB4ZMD2BqjwGHA@mail.gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 lib/iov_iter.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index e4dc809d1075..3743bbcbbb89 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1544,6 +1544,7 @@ int import_ubuf(int rw, void __user *buf, size_t len, struct iov_iter *i)
 	iov_iter_ubuf(i, rw, buf, len);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(import_ubuf);
 
 /**
  * iov_iter_restore() - Restore a &struct iov_iter to the same state as when
-- 
2.35.3


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

* [PATCH 02/25] ALSA: pcm: Add copy ops with iov_iter
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
  2023-08-14 11:54 ` [PATCH 01/25] iov_iter: Export import_ubuf() Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem Takashi Iwai
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

iov_iter is a universal interface to copy the data chunk from/to
user-space and kernel in a unified manner.  This API can fit for ALSA
PCM copy ops, too; we had to split to copy_user and copy_kernel in the
past, and those can be unified to a single ops with iov_iter.

This patch adds a new PCM copy ops that passes iov_iter for copying
both kernel and user-space in the same way.  This patch touches only
the ALSA PCM core part, and the actual users will be replaced in the
following patches.

The expansion of iov_iter is done in the PCM core right before calling
each copy callback.  It's a bit suboptimal, but I took this now as
it's the most straightforward replacement.  The more conversion to
iov_iter in the caller side is a TODO for future.

As of now, the old copy_user and copy_kernel ops are still kept.
Once after all users are converted, we'll drop the old copy_user and
copy_kernel ops, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/pcm.h     |   3 ++
 sound/core/pcm_lib.c    | 111 ++++++++++++++++++++++++----------------
 sound/core/pcm_native.c |   2 +-
 3 files changed, 71 insertions(+), 45 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 19f564606ac4..ff4a0c1c93a2 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/pm_qos.h>
 #include <linux/refcount.h>
+#include <linux/uio.h>
 
 #define snd_pcm_substream_chip(substream) ((substream)->private_data)
 #define snd_pcm_chip(pcm) ((pcm)->private_data)
@@ -68,6 +69,8 @@ struct snd_pcm_ops {
 			struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
 	int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
 			    unsigned long pos, unsigned long bytes);
+	int (*copy)(struct snd_pcm_substream *substream, int channel,
+		    unsigned long pos, struct iov_iter *iter, unsigned long bytes);
 	int (*copy_user)(struct snd_pcm_substream *substream, int channel,
 			 unsigned long pos, void __user *buf,
 			 unsigned long bytes);
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 9c121a921b04..3303914c58ea 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1973,10 +1973,11 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
 	
 typedef int (*pcm_transfer_f)(struct snd_pcm_substream *substream,
 			      int channel, unsigned long hwoff,
-			      void *buf, unsigned long bytes);
+			      struct iov_iter *iter, unsigned long bytes);
 
 typedef int (*pcm_copy_f)(struct snd_pcm_substream *, snd_pcm_uframes_t, void *,
-			  snd_pcm_uframes_t, snd_pcm_uframes_t, pcm_transfer_f);
+			  snd_pcm_uframes_t, snd_pcm_uframes_t, pcm_transfer_f,
+			  bool);
 
 /* calculate the target DMA-buffer position to be written/read */
 static void *get_dma_ptr(struct snd_pcm_runtime *runtime,
@@ -1986,32 +1987,24 @@ static void *get_dma_ptr(struct snd_pcm_runtime *runtime,
 		channel * (runtime->dma_bytes / runtime->channels);
 }
 
-/* default copy_user ops for write; used for both interleaved and non- modes */
+/* default copy ops for write; used for both interleaved and non- modes */
 static int default_write_copy(struct snd_pcm_substream *substream,
 			      int channel, unsigned long hwoff,
-			      void *buf, unsigned long bytes)
+			      struct iov_iter *iter, unsigned long bytes)
 {
-	if (copy_from_user(get_dma_ptr(substream->runtime, channel, hwoff),
-			   (void __user *)buf, bytes))
+	if (!copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff),
+			    bytes, iter))
 		return -EFAULT;
 	return 0;
 }
 
-/* default copy_kernel ops for write */
-static int default_write_copy_kernel(struct snd_pcm_substream *substream,
-				     int channel, unsigned long hwoff,
-				     void *buf, unsigned long bytes)
-{
-	memcpy(get_dma_ptr(substream->runtime, channel, hwoff), buf, bytes);
-	return 0;
-}
-
 /* fill silence instead of copy data; called as a transfer helper
  * from __snd_pcm_lib_write() or directly from noninterleaved_copy() when
  * a NULL buffer is passed
  */
 static int fill_silence(struct snd_pcm_substream *substream, int channel,
-			unsigned long hwoff, void *buf, unsigned long bytes)
+			unsigned long hwoff, struct iov_iter *iter,
+			unsigned long bytes)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 
@@ -2027,25 +2020,54 @@ static int fill_silence(struct snd_pcm_substream *substream, int channel,
 	return 0;
 }
 
-/* default copy_user ops for read; used for both interleaved and non- modes */
+/* default copy ops for read; used for both interleaved and non- modes */
 static int default_read_copy(struct snd_pcm_substream *substream,
 			     int channel, unsigned long hwoff,
-			     void *buf, unsigned long bytes)
+			     struct iov_iter *iter, unsigned long bytes)
 {
-	if (copy_to_user((void __user *)buf,
-			 get_dma_ptr(substream->runtime, channel, hwoff),
-			 bytes))
+	if (!copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff),
+			  bytes, iter))
 		return -EFAULT;
 	return 0;
 }
 
-/* default copy_kernel ops for read */
-static int default_read_copy_kernel(struct snd_pcm_substream *substream,
-				    int channel, unsigned long hwoff,
-				    void *buf, unsigned long bytes)
+/* a wrapper for calling old copy_kernel or copy_user ops */
+static int call_old_copy(struct snd_pcm_substream *substream,
+			 int channel, unsigned long hwoff,
+			 struct iov_iter *iter, unsigned long bytes)
 {
-	memcpy(buf, get_dma_ptr(substream->runtime, channel, hwoff), bytes);
-	return 0;
+	if (iov_iter_is_kvec(iter))
+		return substream->ops->copy_kernel(substream, channel, hwoff,
+						   iter_iov_addr(iter), bytes);
+	else
+		return substream->ops->copy_user(substream, channel, hwoff,
+						 iter_iov_addr(iter), bytes);
+}
+
+/* call transfer with the filled iov_iter */
+static int do_transfer(struct snd_pcm_substream *substream, int c,
+		       unsigned long hwoff, void *data, unsigned long bytes,
+		       pcm_transfer_f transfer, bool in_kernel)
+{
+	struct iov_iter iter;
+	int err, type;
+
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		type = ITER_SOURCE;
+	else
+		type = ITER_DEST;
+
+	if (in_kernel) {
+		struct kvec kvec = { data, bytes };
+
+		iov_iter_kvec(&iter, type, &kvec, 1, bytes);
+		return transfer(substream, c, hwoff, &iter, bytes);
+	}
+
+	err = import_ubuf(type, (__force void __user *)data, bytes, &iter);
+	if (err)
+		return err;
+	return transfer(substream, c, hwoff, &iter, bytes);
 }
 
 /* call transfer function with the converted pointers and sizes;
@@ -2055,7 +2077,8 @@ static int interleaved_copy(struct snd_pcm_substream *substream,
 			    snd_pcm_uframes_t hwoff, void *data,
 			    snd_pcm_uframes_t off,
 			    snd_pcm_uframes_t frames,
-			    pcm_transfer_f transfer)
+			    pcm_transfer_f transfer,
+			    bool in_kernel)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 
@@ -2063,7 +2086,9 @@ static int interleaved_copy(struct snd_pcm_substream *substream,
 	hwoff = frames_to_bytes(runtime, hwoff);
 	off = frames_to_bytes(runtime, off);
 	frames = frames_to_bytes(runtime, frames);
-	return transfer(substream, 0, hwoff, data + off, frames);
+
+	return do_transfer(substream, 0, hwoff, data + off, frames, transfer,
+			   in_kernel);
 }
 
 /* call transfer function with the converted pointers and sizes for each
@@ -2073,7 +2098,8 @@ static int noninterleaved_copy(struct snd_pcm_substream *substream,
 			       snd_pcm_uframes_t hwoff, void *data,
 			       snd_pcm_uframes_t off,
 			       snd_pcm_uframes_t frames,
-			       pcm_transfer_f transfer)
+			       pcm_transfer_f transfer,
+			       bool in_kernel)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	int channels = runtime->channels;
@@ -2091,8 +2117,8 @@ static int noninterleaved_copy(struct snd_pcm_substream *substream,
 		if (!data || !*bufs)
 			err = fill_silence(substream, c, hwoff, NULL, frames);
 		else
-			err = transfer(substream, c, hwoff, *bufs + off,
-				       frames);
+			err = do_transfer(substream, c, hwoff, *bufs + off,
+					  frames, transfer, in_kernel);
 		if (err < 0)
 			return err;
 	}
@@ -2108,10 +2134,10 @@ static int fill_silence_frames(struct snd_pcm_substream *substream,
 	if (substream->runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED ||
 	    substream->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED)
 		return interleaved_copy(substream, off, NULL, 0, frames,
-					fill_silence);
+					fill_silence, true);
 	else
 		return noninterleaved_copy(substream, off, NULL, 0, frames,
-					   fill_silence);
+					   fill_silence, true);
 }
 
 /* sanity-check for read/write methods */
@@ -2121,7 +2147,7 @@ static int pcm_sanity_check(struct snd_pcm_substream *substream)
 	if (PCM_RUNTIME_CHECK(substream))
 		return -ENXIO;
 	runtime = substream->runtime;
-	if (snd_BUG_ON(!substream->ops->copy_user && !runtime->dma_area))
+	if (snd_BUG_ON(!substream->ops->copy && !substream->ops->copy_user && !runtime->dma_area))
 		return -EINVAL;
 	if (runtime->state == SNDRV_PCM_STATE_OPEN)
 		return -EBADFD;
@@ -2226,15 +2252,12 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 			transfer = fill_silence;
 		else
 			return -EINVAL;
-	} else if (in_kernel) {
-		if (substream->ops->copy_kernel)
-			transfer = substream->ops->copy_kernel;
-		else
-			transfer = is_playback ?
-				default_write_copy_kernel : default_read_copy_kernel;
 	} else {
-		if (substream->ops->copy_user)
-			transfer = (pcm_transfer_f)substream->ops->copy_user;
+		if (substream->ops->copy)
+			transfer = substream->ops->copy;
+		else if ((in_kernel && substream->ops->copy_kernel) ||
+			 (!in_kernel && substream->ops->copy_user))
+			transfer = call_old_copy;
 		else
 			transfer = is_playback ?
 				default_write_copy : default_read_copy;
@@ -2307,7 +2330,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 		if (!is_playback)
 			snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU);
 		err = writer(substream, appl_ofs, data, offset, frames,
-			     transfer);
+			     transfer, in_kernel);
 		if (is_playback)
 			snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
 		snd_pcm_stream_lock_irq(substream);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 95fc56e403b1..34efd4d198d6 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -809,7 +809,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
 		runtime->boundary *= 2;
 
 	/* clear the buffer for avoiding possible kernel info leaks */
-	if (runtime->dma_area && !substream->ops->copy_user) {
+	if (runtime->dma_area && !substream->ops->copy && !substream->ops->copy_user) {
 		size_t size = runtime->dma_bytes;
 
 		if (runtime->info & SNDRV_PCM_INFO_MMAP)
-- 
2.35.3


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

* [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
  2023-08-14 11:54 ` [PATCH 01/25] iov_iter: Export import_ubuf() Takashi Iwai
  2023-08-14 11:55 ` [PATCH 02/25] ALSA: pcm: Add copy ops with iov_iter Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-15 13:51   ` Andy Shevchenko
  2023-08-14 11:55 ` [PATCH 04/25] ALSA: dummy: Convert to generic PCM copy ops Takashi Iwai
                   ` (21 subsequent siblings)
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

Add two more helpers for copying memory between iov_iter and iomem,
which will be used by the new PCM copy ops in a few drivers.
The existing helpers became wrappers of those now.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/pcm.h |  5 ++++
 sound/core/memory.c | 56 ++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index ff4a0c1c93a2..f75beead79e3 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -1559,6 +1559,11 @@ static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
 #define pcm_dbg(pcm, fmt, args...) \
 	dev_dbg((pcm)->card->dev, fmt, ##args)
 
+/* helpers for copying between iov_iter and iomem */
+int copy_to_iter_fromio(struct iov_iter *itert, const void __iomem *src,
+			size_t count);
+int copy_from_iter_toio(void __iomem *dst, struct iov_iter *iter, size_t count);
+
 struct snd_pcm_status64 {
 	snd_pcm_state_t state;		/* stream state */
 	u8 rsvd[4];
diff --git a/sound/core/memory.c b/sound/core/memory.c
index 5d894dc32f7d..e5b54cd73ed6 100644
--- a/sound/core/memory.c
+++ b/sound/core/memory.c
@@ -9,6 +9,7 @@
 #include <linux/io.h>
 #include <linux/uaccess.h>
 #include <sound/core.h>
+#include <sound/pcm.h>
 
 /**
  * copy_to_user_fromio - copy data from mmio-space to user-space
@@ -21,9 +22,30 @@
  * Return: Zero if successful, or non-zero on failure.
  */
 int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
+{
+	struct iov_iter iter;
+
+	if (import_ubuf(ITER_DEST, dst, count, &iter))
+		return -EFAULT;
+	return copy_to_iter_fromio(&iter, (const void __iomem *)src, count);
+}
+EXPORT_SYMBOL(copy_to_user_fromio);
+
+/**
+ * copy_to_iter_fromio - copy data from mmio-space to iov_iter
+ * @dst: the destination iov_iter
+ * @src: the source pointer on mmio
+ * @count: the data size to copy in bytes
+ *
+ * Copies the data from mmio-space to iov_iter.
+ *
+ * Return: Zero if successful, or non-zero on failure.
+ */
+int copy_to_iter_fromio(struct iov_iter *dst, const void __iomem *src,
+			size_t count)
 {
 #if defined(__i386__) || defined(CONFIG_SPARC32)
-	return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
+	return !copy_to_iter((const void __force *)src, count, dst) ? -EFAULT : 0;
 #else
 	char buf[256];
 	while (count) {
@@ -31,16 +53,15 @@ int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size
 		if (c > sizeof(buf))
 			c = sizeof(buf);
 		memcpy_fromio(buf, (void __iomem *)src, c);
-		if (copy_to_user(dst, buf, c))
+		if (!copy_to_iter(buf, c, dst))
 			return -EFAULT;
 		count -= c;
-		dst += c;
 		src += c;
 	}
 	return 0;
 #endif
 }
-EXPORT_SYMBOL(copy_to_user_fromio);
+EXPORT_SYMBOL(copy_to_iter_fromio);
 
 /**
  * copy_from_user_toio - copy data from user-space to mmio-space
@@ -53,23 +74,42 @@ EXPORT_SYMBOL(copy_to_user_fromio);
  * Return: Zero if successful, or non-zero on failure.
  */
 int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
+{
+	struct iov_iter iter;
+
+	if (import_ubuf(ITER_SOURCE, (void __user *)src, count, &iter))
+		return -EFAULT;
+	return copy_from_iter_toio((void __iomem *)dst, &iter, count);
+}
+EXPORT_SYMBOL(copy_from_user_toio);
+
+/**
+ * copy_from_iter_toio - copy data from iov_iter to mmio-space
+ * @dst: the destination pointer on mmio-space
+ * @src: the source iov_iter
+ * @count: the data size to copy in bytes
+ *
+ * Copies the data from iov_iter to mmio-space.
+ *
+ * Return: Zero if successful, or non-zero on failure.
+ */
+int copy_from_iter_toio(void __iomem *dst, struct iov_iter *src, size_t count)
 {
 #if defined(__i386__) || defined(CONFIG_SPARC32)
-	return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0;
+	return !copy_from_iter((void __force *)dst, count, src) ? -EFAULT : 0;
 #else
 	char buf[256];
 	while (count) {
 		size_t c = count;
 		if (c > sizeof(buf))
 			c = sizeof(buf);
-		if (copy_from_user(buf, src, c))
+		if (!copy_from_iter(buf, c, src))
 			return -EFAULT;
 		memcpy_toio(dst, buf, c);
 		count -= c;
 		dst += c;
-		src += c;
 	}
 	return 0;
 #endif
 }
-EXPORT_SYMBOL(copy_from_user_toio);
+EXPORT_SYMBOL(copy_from_iter_toio);
-- 
2.35.3


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

* [PATCH 04/25] ALSA: dummy: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (2 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-15 13:52   ` Andy Shevchenko
  2023-08-14 11:55 ` [PATCH 05/25] ALSA: gus: " Takashi Iwai
                   ` (20 subsequent siblings)
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the dummy driver code to use the new unified PCM
copy callback.  As dummy driver doesn't do anything in the callback,
it's just a simple replacement.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/drivers/dummy.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 9c17b49a2ae1..4317677ba24a 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -626,14 +626,7 @@ static int alloc_fake_buffer(void)
 
 static int dummy_pcm_copy(struct snd_pcm_substream *substream,
 			  int channel, unsigned long pos,
-			  void __user *dst, unsigned long bytes)
-{
-	return 0; /* do nothing */
-}
-
-static int dummy_pcm_copy_kernel(struct snd_pcm_substream *substream,
-				 int channel, unsigned long pos,
-				 void *dst, unsigned long bytes)
+			  struct iov_iter *iter, unsigned long bytes)
 {
 	return 0; /* do nothing */
 }
@@ -667,8 +660,7 @@ static const struct snd_pcm_ops dummy_pcm_ops_no_buf = {
 	.prepare =	dummy_pcm_prepare,
 	.trigger =	dummy_pcm_trigger,
 	.pointer =	dummy_pcm_pointer,
-	.copy_user =	dummy_pcm_copy,
-	.copy_kernel =	dummy_pcm_copy_kernel,
+	.copy =		dummy_pcm_copy,
 	.fill_silence =	dummy_pcm_silence,
 	.page =		dummy_pcm_page,
 };
-- 
2.35.3


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

* [PATCH 05/25] ALSA: gus: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (3 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 04/25] ALSA: dummy: Convert to generic PCM copy ops Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 06/25] ALSA: emu8000: " Takashi Iwai
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the GUS driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/isa/gus/gus_pcm.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index 388db5fb65bd..f67b53612d5f 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -369,7 +369,7 @@ static int playback_copy_ack(struct snd_pcm_substream *substream,
 
 static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream,
 				     int voice, unsigned long pos,
-				     void __user *src, unsigned long count)
+				     struct iov_iter *src, unsigned long count)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct gus_pcm_private *pcmp = runtime->private_data;
@@ -379,27 +379,11 @@ static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream,
 	bpos = get_bpos(pcmp, voice, pos, len);
 	if (bpos < 0)
 		return pos;
-	if (copy_from_user(runtime->dma_area + bpos, src, len))
+	if (!copy_from_iter(runtime->dma_area + bpos, len, src))
 		return -EFAULT;
 	return playback_copy_ack(substream, bpos, len);
 }
 
-static int snd_gf1_pcm_playback_copy_kernel(struct snd_pcm_substream *substream,
-					    int voice, unsigned long pos,
-					    void *src, unsigned long count)
-{
-	struct snd_pcm_runtime *runtime = substream->runtime;
-	struct gus_pcm_private *pcmp = runtime->private_data;
-	unsigned int len = count;
-	int bpos;
-
-	bpos = get_bpos(pcmp, voice, pos, len);
-	if (bpos < 0)
-		return pos;
-	memcpy(runtime->dma_area + bpos, src, len);
-	return playback_copy_ack(substream, bpos, len);
-}
-
 static int snd_gf1_pcm_playback_silence(struct snd_pcm_substream *substream,
 					int voice, unsigned long pos,
 					unsigned long count)
@@ -830,8 +814,7 @@ static const struct snd_pcm_ops snd_gf1_pcm_playback_ops = {
 	.prepare =	snd_gf1_pcm_playback_prepare,
 	.trigger =	snd_gf1_pcm_playback_trigger,
 	.pointer =	snd_gf1_pcm_playback_pointer,
-	.copy_user =	snd_gf1_pcm_playback_copy,
-	.copy_kernel =	snd_gf1_pcm_playback_copy_kernel,
+	.copy =		snd_gf1_pcm_playback_copy,
 	.fill_silence =	snd_gf1_pcm_playback_silence,
 };
 
-- 
2.35.3


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

* [PATCH 06/25] ALSA: emu8000: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (4 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 05/25] ALSA: gus: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 07/25] ALSA: es1938: " Takashi Iwai
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the SB Emu8000 driver code to use the new unified
PCM copy callback.  The conversion is a bit complicated because of
many open code in emu8000_pcm.c.  GET_VAL() and LOOP_WRITE() macros
were rewritten / simplified with copy_from_iter().  As
copy_from_iter() updates the internal offset value, we can drop the
corresponding part, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/isa/sb/emu8000_pcm.c | 74 +++++++++-----------------------------
 1 file changed, 16 insertions(+), 58 deletions(-)

diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index c8afc4347c54..9e59d0b2a3fe 100644
--- a/sound/isa/sb/emu8000_pcm.c
+++ b/sound/isa/sb/emu8000_pcm.c
@@ -409,39 +409,25 @@ do { \
 		return -EAGAIN;\
 } while (0)
 
-enum {
-	COPY_USER, COPY_KERNEL, FILL_SILENCE,
-};
-
-#define GET_VAL(sval, buf, mode)					\
+#define GET_VAL(sval, iter)						\
 	do {								\
-		switch (mode) {						\
-		case FILL_SILENCE:					\
+		if (!iter)						\
 			sval = 0;					\
-			break;						\
-		case COPY_KERNEL:					\
-			sval = *buf++;					\
-			break;						\
-		default:						\
-			if (get_user(sval, (unsigned short __user *)buf)) \
-				return -EFAULT;				\
-			buf++;						\
-			break;						\
-		}							\
+		else if (!copy_from_iter(&sval, 2, iter))		\
+			return -EFAULT;					\
 	} while (0)
 
 #ifdef USE_NONINTERLEAVE
 
-#define LOOP_WRITE(rec, offset, _buf, count, mode)		\
+#define LOOP_WRITE(rec, offset, iter, count)			\
 	do {							\
 		struct snd_emu8000 *emu = (rec)->emu;		\
-		unsigned short *buf = (__force unsigned short *)(_buf); \
 		snd_emu8000_write_wait(emu, 1);			\
 		EMU8000_SMALW_WRITE(emu, offset);		\
 		while (count > 0) {				\
 			unsigned short sval;			\
 			CHECK_SCHEDULER();			\
-			GET_VAL(sval, buf, mode);		\
+			GET_VAL(sval, iter);			\
 			EMU8000_SMLD_WRITE(emu, sval);		\
 			count--;				\
 		}						\
@@ -450,27 +436,14 @@ enum {
 /* copy one channel block */
 static int emu8k_pcm_copy(struct snd_pcm_substream *subs,
 			  int voice, unsigned long pos,
-			  void __user *src, unsigned long count)
+			  struct iov_iter *src, unsigned long count)
 {
 	struct snd_emu8k_pcm *rec = subs->runtime->private_data;
 
 	/* convert to word unit */
 	pos = (pos << 1) + rec->loop_start[voice];
 	count <<= 1;
-	LOOP_WRITE(rec, pos, src, count, COPY_USER);
-	return 0;
-}
-
-static int emu8k_pcm_copy_kernel(struct snd_pcm_substream *subs,
-				 int voice, unsigned long pos,
-				 void *src, unsigned long count)
-{
-	struct snd_emu8k_pcm *rec = subs->runtime->private_data;
-
-	/* convert to word unit */
-	pos = (pos << 1) + rec->loop_start[voice];
-	count <<= 1;
-	LOOP_WRITE(rec, pos, src, count, COPY_KERNEL);
+	LOOP_WRITE(rec, pos, src, count);
 	return 0;
 }
 
@@ -483,16 +456,15 @@ static int emu8k_pcm_silence(struct snd_pcm_substream *subs,
 	/* convert to word unit */
 	pos = (pos << 1) + rec->loop_start[voice];
 	count <<= 1;
-	LOOP_WRITE(rec, pos, NULL, count, FILL_SILENCE);
+	LOOP_WRITE(rec, pos, USER_SOCKPTR(NULL), count);
 	return 0;
 }
 
 #else /* interleave */
 
-#define LOOP_WRITE(rec, pos, _buf, count, mode)				\
+#define LOOP_WRITE(rec, pos, iter, count)				\
 	do {								\
 		struct snd_emu8000 *emu = rec->emu;			\
-		unsigned short *buf = (__force unsigned short *)(_buf);	\
 		snd_emu8000_write_wait(emu, 1);				\
 		EMU8000_SMALW_WRITE(emu, pos + rec->loop_start[0]);	\
 		if (rec->voices > 1)					\
@@ -500,11 +472,11 @@ static int emu8k_pcm_silence(struct snd_pcm_substream *subs,
 		while (count > 0) {					\
 			unsigned short sval;				\
 			CHECK_SCHEDULER();				\
-			GET_VAL(sval, buf, mode);			\
+			GET_VAL(sval, iter);				\
 			EMU8000_SMLD_WRITE(emu, sval);			\
 			if (rec->voices > 1) {				\
 				CHECK_SCHEDULER();			\
-				GET_VAL(sval, buf, mode);		\
+				GET_VAL(sval, iter);			\
 				EMU8000_SMRD_WRITE(emu, sval);		\
 			}						\
 			count--;					\
@@ -518,27 +490,14 @@ static int emu8k_pcm_silence(struct snd_pcm_substream *subs,
  */
 static int emu8k_pcm_copy(struct snd_pcm_substream *subs,
 			  int voice, unsigned long pos,
-			  void __user *src, unsigned long count)
+			  struct iov_iter *src, unsigned long count)
 {
 	struct snd_emu8k_pcm *rec = subs->runtime->private_data;
 
 	/* convert to frames */
 	pos = bytes_to_frames(subs->runtime, pos);
 	count = bytes_to_frames(subs->runtime, count);
-	LOOP_WRITE(rec, pos, src, count, COPY_USER);
-	return 0;
-}
-
-static int emu8k_pcm_copy_kernel(struct snd_pcm_substream *subs,
-				 int voice, unsigned long pos,
-				 void *src, unsigned long count)
-{
-	struct snd_emu8k_pcm *rec = subs->runtime->private_data;
-
-	/* convert to frames */
-	pos = bytes_to_frames(subs->runtime, pos);
-	count = bytes_to_frames(subs->runtime, count);
-	LOOP_WRITE(rec, pos, src, count, COPY_KERNEL);
+	LOOP_WRITE(rec, pos, src, count);
 	return 0;
 }
 
@@ -550,7 +509,7 @@ static int emu8k_pcm_silence(struct snd_pcm_substream *subs,
 	/* convert to frames */
 	pos = bytes_to_frames(subs->runtime, pos);
 	count = bytes_to_frames(subs->runtime, count);
-	LOOP_WRITE(rec, pos, NULL, count, FILL_SILENCE);
+	LOOP_WRITE(rec, pos, NULL, count);
 	return 0;
 }
 #endif
@@ -666,8 +625,7 @@ static const struct snd_pcm_ops emu8k_pcm_ops = {
 	.prepare =	emu8k_pcm_prepare,
 	.trigger =	emu8k_pcm_trigger,
 	.pointer =	emu8k_pcm_pointer,
-	.copy_user =	emu8k_pcm_copy,
-	.copy_kernel =	emu8k_pcm_copy_kernel,
+	.copy =		emu8k_pcm_copy,
 	.fill_silence =	emu8k_pcm_silence,
 };
 
-- 
2.35.3


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

* [PATCH 07/25] ALSA: es1938: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (5 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 06/25] ALSA: emu8000: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 08/25] ALSA: korg1212: " Takashi Iwai
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the es1938 driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants in most parts.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/es1938.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)

diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index e34ec6f89e7e..9e28e9fecd2a 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -824,7 +824,7 @@ static snd_pcm_uframes_t snd_es1938_playback_pointer(struct snd_pcm_substream *s
 
 static int snd_es1938_capture_copy(struct snd_pcm_substream *substream,
 				   int channel, unsigned long pos,
-				   void __user *dst, unsigned long count)
+				   struct iov_iter *dst, unsigned long count)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct es1938 *chip = snd_pcm_substream_chip(substream);
@@ -832,36 +832,17 @@ static int snd_es1938_capture_copy(struct snd_pcm_substream *substream,
 	if (snd_BUG_ON(pos + count > chip->dma1_size))
 		return -EINVAL;
 	if (pos + count < chip->dma1_size) {
-		if (copy_to_user(dst, runtime->dma_area + pos + 1, count))
+		if (!copy_to_iter(runtime->dma_area + pos + 1, count, dst))
 			return -EFAULT;
 	} else {
-		if (copy_to_user(dst, runtime->dma_area + pos + 1, count - 1))
+		if (!copy_to_iter(runtime->dma_area + pos + 1, count - 1, dst))
 			return -EFAULT;
-		if (put_user(runtime->dma_area[0],
-			     ((unsigned char __user *)dst) + count - 1))
+		if (!copy_to_iter(runtime->dma_area, 1, dst))
 			return -EFAULT;
 	}
 	return 0;
 }
 
-static int snd_es1938_capture_copy_kernel(struct snd_pcm_substream *substream,
-					  int channel, unsigned long pos,
-					  void *dst, unsigned long count)
-{
-	struct snd_pcm_runtime *runtime = substream->runtime;
-	struct es1938 *chip = snd_pcm_substream_chip(substream);
-
-	if (snd_BUG_ON(pos + count > chip->dma1_size))
-		return -EINVAL;
-	if (pos + count < chip->dma1_size) {
-		memcpy(dst, runtime->dma_area + pos + 1, count);
-	} else {
-		memcpy(dst, runtime->dma_area + pos + 1, count - 1);
-		runtime->dma_area[0] = *((unsigned char *)dst + count - 1);
-	}
-	return 0;
-}
-
 /* ----------------------------------------------------------------------
  * Audio1 Capture (ADC)
  * ----------------------------------------------------------------------*/
@@ -987,8 +968,7 @@ static const struct snd_pcm_ops snd_es1938_capture_ops = {
 	.prepare =	snd_es1938_capture_prepare,
 	.trigger =	snd_es1938_capture_trigger,
 	.pointer =	snd_es1938_capture_pointer,
-	.copy_user =	snd_es1938_capture_copy,
-	.copy_kernel =	snd_es1938_capture_copy_kernel,
+	.copy =		snd_es1938_capture_copy,
 };
 
 static int snd_es1938_new_pcm(struct es1938 *chip, int device)
-- 
2.35.3


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

* [PATCH 08/25] ALSA: korg1212: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (6 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 07/25] ALSA: es1938: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-15 13:55   ` Andy Shevchenko
  2023-08-14 11:55 ` [PATCH 09/25] ALSA: nm256: " Takashi Iwai
                   ` (16 subsequent siblings)
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the korg1212 driver code to use the new unified
PCM copy callback.  The open-coded conditional memory copies are
replaced with simpler copy_from/to_iter() calls.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/korg1212/korg1212.c | 50 +++++++++--------------------------
 1 file changed, 12 insertions(+), 38 deletions(-)

diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 33b4f95d65b3..bfbff6dee273 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -1285,8 +1285,7 @@ static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int coun
 }
 
 static int snd_korg1212_copy_to(struct snd_pcm_substream *substream,
-				void __user *dst, int pos, int count,
-				bool in_kernel)
+				struct iov_iter *dst, int pos, int count)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
         struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
@@ -1306,24 +1305,20 @@ static int snd_korg1212_copy_to(struct snd_pcm_substream *substream,
 #if K1212_DEBUG_LEVEL > 0
 		if ( (void *) src < (void *) korg1212->recordDataBufsPtr ||
 		     (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) {
-			printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i);
+			printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst->kvec.iov_base, i);
 			return -EFAULT;
 		}
 #endif
-		if (in_kernel)
-			memcpy((__force void *)dst, src, size);
-		else if (copy_to_user(dst, src, size))
+		if (!copy_to_iter(src, size, dst))
 			return -EFAULT;
 		src++;
-		dst += size;
 	}
 
 	return 0;
 }
 
 static int snd_korg1212_copy_from(struct snd_pcm_substream *substream,
-				  void __user *src, int pos, int count,
-				  bool in_kernel)
+				  struct iov_iter *src, int pos, int count)
 {
         struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
@@ -1345,16 +1340,13 @@ static int snd_korg1212_copy_from(struct snd_pcm_substream *substream,
 #if K1212_DEBUG_LEVEL > 0
 		if ( (void *) dst < (void *) korg1212->playDataBufsPtr ||
 		     (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) {
-			printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i);
+			printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src->kvec.iov_base, dst, i);
 			return -EFAULT;
 		}
 #endif
-		if (in_kernel)
-			memcpy(dst, (__force void *)src, size);
-		else if (copy_from_user(dst, src, size))
+		if (!copy_from_iter(dst, size, src))
 			return -EFAULT;
 		dst++;
-		src += size;
 	}
 
 	return 0;
@@ -1642,17 +1634,9 @@ static snd_pcm_uframes_t snd_korg1212_capture_pointer(struct snd_pcm_substream *
 
 static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream,
 				      int channel, unsigned long pos,
-				      void __user *src, unsigned long count)
+				      struct iov_iter *src, unsigned long count)
 {
-	return snd_korg1212_copy_from(substream, src, pos, count, false);
-}
-
-static int snd_korg1212_playback_copy_kernel(struct snd_pcm_substream *substream,
-				      int channel, unsigned long pos,
-				      void *src, unsigned long count)
-{
-	return snd_korg1212_copy_from(substream, (void __user *)src,
-				      pos, count, true);
+	return snd_korg1212_copy_from(substream, src, pos, count);
 }
 
 static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream,
@@ -1670,17 +1654,9 @@ static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream,
 
 static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream,
 				     int channel, unsigned long pos,
-				     void __user *dst, unsigned long count)
+				     struct iov_iter *dst, unsigned long count)
 {
-	return snd_korg1212_copy_to(substream, dst, pos, count, false);
-}
-
-static int snd_korg1212_capture_copy_kernel(struct snd_pcm_substream *substream,
-				     int channel, unsigned long pos,
-				     void *dst, unsigned long count)
-{
-	return snd_korg1212_copy_to(substream, (void __user *)dst,
-				    pos, count, true);
+	return snd_korg1212_copy_to(substream, dst, pos, count);
 }
 
 static const struct snd_pcm_ops snd_korg1212_playback_ops = {
@@ -1691,8 +1667,7 @@ static const struct snd_pcm_ops snd_korg1212_playback_ops = {
         .prepare =	snd_korg1212_prepare,
         .trigger =	snd_korg1212_trigger,
         .pointer =	snd_korg1212_playback_pointer,
-	.copy_user =	snd_korg1212_playback_copy,
-	.copy_kernel =	snd_korg1212_playback_copy_kernel,
+	.copy =		snd_korg1212_playback_copy,
 	.fill_silence =	snd_korg1212_playback_silence,
 };
 
@@ -1704,8 +1679,7 @@ static const struct snd_pcm_ops snd_korg1212_capture_ops = {
 	.prepare =	snd_korg1212_prepare,
 	.trigger =	snd_korg1212_trigger,
 	.pointer =	snd_korg1212_capture_pointer,
-	.copy_user =	snd_korg1212_capture_copy,
-	.copy_kernel =	snd_korg1212_capture_copy_kernel,
+	.copy =		snd_korg1212_capture_copy,
 };
 
 /*
-- 
2.35.3


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

* [PATCH 09/25] ALSA: nm256: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (7 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 08/25] ALSA: korg1212: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 10/25] ALSA: rme32: " Takashi Iwai
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the nm256 driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/nm256/nm256.c | 42 ++++++-----------------------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index f99a1e96e923..34f90829e656 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -691,26 +691,12 @@ snd_nm256_playback_silence(struct snd_pcm_substream *substream,
 static int
 snd_nm256_playback_copy(struct snd_pcm_substream *substream,
 			int channel, unsigned long pos,
-			void __user *src, unsigned long count)
+			struct iov_iter *src, unsigned long count)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct nm256_stream *s = runtime->private_data;
 
-	if (copy_from_user_toio(s->bufptr + pos, src, count))
-		return -EFAULT;
-	return 0;
-}
-
-static int
-snd_nm256_playback_copy_kernel(struct snd_pcm_substream *substream,
-			       int channel, unsigned long pos,
-			       void *src, unsigned long count)
-{
-	struct snd_pcm_runtime *runtime = substream->runtime;
-	struct nm256_stream *s = runtime->private_data;
-
-	memcpy_toio(s->bufptr + pos, src, count);
-	return 0;
+	return copy_from_iter_toio(s->bufptr + pos, src, count);
 }
 
 /*
@@ -719,26 +705,12 @@ snd_nm256_playback_copy_kernel(struct snd_pcm_substream *substream,
 static int
 snd_nm256_capture_copy(struct snd_pcm_substream *substream,
 		       int channel, unsigned long pos,
-		       void __user *dst, unsigned long count)
+		       struct iov_iter *dst, unsigned long count)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct nm256_stream *s = runtime->private_data;
 
-	if (copy_to_user_fromio(dst, s->bufptr + pos, count))
-		return -EFAULT;
-	return 0;
-}
-
-static int
-snd_nm256_capture_copy_kernel(struct snd_pcm_substream *substream,
-			      int channel, unsigned long pos,
-			      void *dst, unsigned long count)
-{
-	struct snd_pcm_runtime *runtime = substream->runtime;
-	struct nm256_stream *s = runtime->private_data;
-
-	memcpy_fromio(dst, s->bufptr + pos, count);
-	return 0;
+	return copy_to_iter_fromio(dst, s->bufptr + pos, count);
 }
 
 #endif /* !__i386__ */
@@ -909,8 +881,7 @@ static const struct snd_pcm_ops snd_nm256_playback_ops = {
 	.trigger =	snd_nm256_playback_trigger,
 	.pointer =	snd_nm256_playback_pointer,
 #ifndef __i386__
-	.copy_user =	snd_nm256_playback_copy,
-	.copy_kernel =	snd_nm256_playback_copy_kernel,
+	.copy =		snd_nm256_playback_copy,
 	.fill_silence =	snd_nm256_playback_silence,
 #endif
 	.mmap =		snd_pcm_lib_mmap_iomem,
@@ -924,8 +895,7 @@ static const struct snd_pcm_ops snd_nm256_capture_ops = {
 	.trigger =	snd_nm256_capture_trigger,
 	.pointer =	snd_nm256_capture_pointer,
 #ifndef __i386__
-	.copy_user =	snd_nm256_capture_copy,
-	.copy_kernel =	snd_nm256_capture_copy_kernel,
+	.copy =		snd_nm256_capture_copy,
 #endif
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
-- 
2.35.3


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

* [PATCH 10/25] ALSA: rme32: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (8 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 09/25] ALSA: nm256: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 11/25] ALSA: rme96: " Takashi Iwai
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the rme32 driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/rme32.c | 50 +++++++++++------------------------------------
 1 file changed, 11 insertions(+), 39 deletions(-)

diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index 9c0ac025e143..02144bbee6d5 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -252,48 +252,24 @@ static int snd_rme32_playback_silence(struct snd_pcm_substream *substream,
 /* copy callback for halfduplex mode */
 static int snd_rme32_playback_copy(struct snd_pcm_substream *substream,
 				   int channel, unsigned long pos,
-				   void __user *src, unsigned long count)
+				   struct iov_iter *src, unsigned long count)
 {
 	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
 
-	if (copy_from_user_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos,
-				src, count))
-		return -EFAULT;
-	return 0;
-}
-
-static int snd_rme32_playback_copy_kernel(struct snd_pcm_substream *substream,
-					  int channel, unsigned long pos,
-					  void *src, unsigned long count)
-{
-	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
-
-	memcpy_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos, src, count);
-	return 0;
+	return copy_from_iter_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos,
+				   src, count);
 }
 
 /* copy callback for halfduplex mode */
 static int snd_rme32_capture_copy(struct snd_pcm_substream *substream,
 				  int channel, unsigned long pos,
-				  void __user *dst, unsigned long count)
+				  struct iov_iter *dst, unsigned long count)
 {
 	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
 
-	if (copy_to_user_fromio(dst,
-			    rme32->iobase + RME32_IO_DATA_BUFFER + pos,
-			    count))
-		return -EFAULT;
-	return 0;
-}
-
-static int snd_rme32_capture_copy_kernel(struct snd_pcm_substream *substream,
-					 int channel, unsigned long pos,
-					 void *dst, unsigned long count)
-{
-	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
-
-	memcpy_fromio(dst, rme32->iobase + RME32_IO_DATA_BUFFER + pos, count);
-	return 0;
+	return copy_to_iter_fromio(dst,
+				   rme32->iobase + RME32_IO_DATA_BUFFER + pos,
+				   count);
 }
 
 /*
@@ -1194,8 +1170,7 @@ static const struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
 	.prepare =	snd_rme32_playback_prepare,
 	.trigger =	snd_rme32_pcm_trigger,
 	.pointer =	snd_rme32_playback_pointer,
-	.copy_user =	snd_rme32_playback_copy,
-	.copy_kernel =	snd_rme32_playback_copy_kernel,
+	.copy =		snd_rme32_playback_copy,
 	.fill_silence =	snd_rme32_playback_silence,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
@@ -1207,8 +1182,7 @@ static const struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
 	.prepare =	snd_rme32_capture_prepare,
 	.trigger =	snd_rme32_pcm_trigger,
 	.pointer =	snd_rme32_capture_pointer,
-	.copy_user =	snd_rme32_capture_copy,
-	.copy_kernel =	snd_rme32_capture_copy_kernel,
+	.copy =		snd_rme32_capture_copy,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
 
@@ -1219,8 +1193,7 @@ static const struct snd_pcm_ops snd_rme32_playback_adat_ops = {
 	.prepare =	snd_rme32_playback_prepare,
 	.trigger =	snd_rme32_pcm_trigger,
 	.pointer =	snd_rme32_playback_pointer,
-	.copy_user =	snd_rme32_playback_copy,
-	.copy_kernel =	snd_rme32_playback_copy_kernel,
+	.copy =		snd_rme32_playback_copy,
 	.fill_silence =	snd_rme32_playback_silence,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
@@ -1232,8 +1205,7 @@ static const struct snd_pcm_ops snd_rme32_capture_adat_ops = {
 	.prepare =	snd_rme32_capture_prepare,
 	.trigger =	snd_rme32_pcm_trigger,
 	.pointer =	snd_rme32_capture_pointer,
-	.copy_user =	snd_rme32_capture_copy,
-	.copy_kernel =	snd_rme32_capture_copy_kernel,
+	.copy =		snd_rme32_capture_copy,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
 
-- 
2.35.3


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

* [PATCH 11/25] ALSA: rme96: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (9 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 10/25] ALSA: rme32: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 12/25] ALSA: hdsp: " Takashi Iwai
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the rme96 driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/rme96.c | 42 ++++++++----------------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index bccb7e0d3d11..6b5ffb18197b 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -320,48 +320,26 @@ snd_rme96_playback_silence(struct snd_pcm_substream *substream,
 static int
 snd_rme96_playback_copy(struct snd_pcm_substream *substream,
 			int channel, unsigned long pos,
-			void __user *src, unsigned long count)
+			struct iov_iter *src, unsigned long count)
 {
 	struct rme96 *rme96 = snd_pcm_substream_chip(substream);
 
-	return copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
+	return copy_from_iter_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
 				   src, count);
 }
 
-static int
-snd_rme96_playback_copy_kernel(struct snd_pcm_substream *substream,
-			       int channel, unsigned long pos,
-			       void *src, unsigned long count)
-{
-	struct rme96 *rme96 = snd_pcm_substream_chip(substream);
-
-	memcpy_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src, count);
-	return 0;
-}
-
 static int
 snd_rme96_capture_copy(struct snd_pcm_substream *substream,
 		       int channel, unsigned long pos,
-		       void __user *dst, unsigned long count)
+		       struct iov_iter *dst, unsigned long count)
 {
 	struct rme96 *rme96 = snd_pcm_substream_chip(substream);
 
-	return copy_to_user_fromio(dst,
+	return copy_to_iter_fromio(dst,
 				   rme96->iobase + RME96_IO_REC_BUFFER + pos,
 				   count);
 }
 
-static int
-snd_rme96_capture_copy_kernel(struct snd_pcm_substream *substream,
-			      int channel, unsigned long pos,
-			      void *dst, unsigned long count)
-{
-	struct rme96 *rme96 = snd_pcm_substream_chip(substream);
-
-	memcpy_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos, count);
-	return 0;
-}
-
 /*
  * Digital output capabilities (S/PDIF)
  */
@@ -1518,8 +1496,7 @@ static const struct snd_pcm_ops snd_rme96_playback_spdif_ops = {
 	.prepare =	snd_rme96_playback_prepare,
 	.trigger =	snd_rme96_playback_trigger,
 	.pointer =	snd_rme96_playback_pointer,
-	.copy_user =	snd_rme96_playback_copy,
-	.copy_kernel =	snd_rme96_playback_copy_kernel,
+	.copy =		snd_rme96_playback_copy,
 	.fill_silence =	snd_rme96_playback_silence,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
@@ -1531,8 +1508,7 @@ static const struct snd_pcm_ops snd_rme96_capture_spdif_ops = {
 	.prepare =	snd_rme96_capture_prepare,
 	.trigger =	snd_rme96_capture_trigger,
 	.pointer =	snd_rme96_capture_pointer,
-	.copy_user =	snd_rme96_capture_copy,
-	.copy_kernel =	snd_rme96_capture_copy_kernel,
+	.copy =		snd_rme96_capture_copy,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
 
@@ -1543,8 +1519,7 @@ static const struct snd_pcm_ops snd_rme96_playback_adat_ops = {
 	.prepare =	snd_rme96_playback_prepare,
 	.trigger =	snd_rme96_playback_trigger,
 	.pointer =	snd_rme96_playback_pointer,
-	.copy_user =	snd_rme96_playback_copy,
-	.copy_kernel =	snd_rme96_playback_copy_kernel,
+	.copy =		snd_rme96_playback_copy,
 	.fill_silence =	snd_rme96_playback_silence,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
@@ -1556,8 +1531,7 @@ static const struct snd_pcm_ops snd_rme96_capture_adat_ops = {
 	.prepare =	snd_rme96_capture_prepare,
 	.trigger =	snd_rme96_capture_trigger,
 	.pointer =	snd_rme96_capture_pointer,
-	.copy_user =	snd_rme96_capture_copy,
-	.copy_kernel =	snd_rme96_capture_copy_kernel,
+	.copy =		snd_rme96_capture_copy,
 	.mmap =		snd_pcm_lib_mmap_iomem,
 };
 
-- 
2.35.3


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

* [PATCH 12/25] ALSA: hdsp: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (10 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 11/25] ALSA: rme96: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 13/25] ALSA: rme9652: " Takashi Iwai
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the hdsp driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/rme9652/hdsp.c | 42 ++++++----------------------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 65add92c88aa..960cc75608cb 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -3961,7 +3961,7 @@ static signed char *hdsp_channel_buffer_location(struct hdsp *hdsp,
 
 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream,
 				  int channel, unsigned long pos,
-				  void __user *src, unsigned long count)
+				  struct iov_iter *src, unsigned long count)
 {
 	struct hdsp *hdsp = snd_pcm_substream_chip(substream);
 	signed char *channel_buf;
@@ -3972,28 +3972,14 @@ static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream,
 	channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
 	if (snd_BUG_ON(!channel_buf))
 		return -EIO;
-	if (copy_from_user(channel_buf + pos, src, count))
+	if (!copy_from_iter(channel_buf + pos, count, src))
 		return -EFAULT;
 	return 0;
 }
 
-static int snd_hdsp_playback_copy_kernel(struct snd_pcm_substream *substream,
-					 int channel, unsigned long pos,
-					 void *src, unsigned long count)
-{
-	struct hdsp *hdsp = snd_pcm_substream_chip(substream);
-	signed char *channel_buf;
-
-	channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
-	if (snd_BUG_ON(!channel_buf))
-		return -EIO;
-	memcpy(channel_buf + pos, src, count);
-	return 0;
-}
-
 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream,
 				 int channel, unsigned long pos,
-				 void __user *dst, unsigned long count)
+				 struct iov_iter *dst, unsigned long count)
 {
 	struct hdsp *hdsp = snd_pcm_substream_chip(substream);
 	signed char *channel_buf;
@@ -4004,25 +3990,11 @@ static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream,
 	channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
 	if (snd_BUG_ON(!channel_buf))
 		return -EIO;
-	if (copy_to_user(dst, channel_buf + pos, count))
+	if (!copy_to_iter(channel_buf + pos, count, dst))
 		return -EFAULT;
 	return 0;
 }
 
-static int snd_hdsp_capture_copy_kernel(struct snd_pcm_substream *substream,
-					int channel, unsigned long pos,
-					void *dst, unsigned long count)
-{
-	struct hdsp *hdsp = snd_pcm_substream_chip(substream);
-	signed char *channel_buf;
-
-	channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
-	if (snd_BUG_ON(!channel_buf))
-		return -EIO;
-	memcpy(dst, channel_buf + pos, count);
-	return 0;
-}
-
 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream,
 			       int channel, unsigned long pos,
 			       unsigned long count)
@@ -4950,8 +4922,7 @@ static const struct snd_pcm_ops snd_hdsp_playback_ops = {
 	.prepare =	snd_hdsp_prepare,
 	.trigger =	snd_hdsp_trigger,
 	.pointer =	snd_hdsp_hw_pointer,
-	.copy_user =	snd_hdsp_playback_copy,
-	.copy_kernel =	snd_hdsp_playback_copy_kernel,
+	.copy =		snd_hdsp_playback_copy,
 	.fill_silence =	snd_hdsp_hw_silence,
 };
 
@@ -4963,8 +4934,7 @@ static const struct snd_pcm_ops snd_hdsp_capture_ops = {
 	.prepare =	snd_hdsp_prepare,
 	.trigger =	snd_hdsp_trigger,
 	.pointer =	snd_hdsp_hw_pointer,
-	.copy_user =	snd_hdsp_capture_copy,
-	.copy_kernel =	snd_hdsp_capture_copy_kernel,
+	.copy =		snd_hdsp_capture_copy,
 };
 
 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
-- 
2.35.3


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

* [PATCH 13/25] ALSA: rme9652: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (11 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 12/25] ALSA: hdsp: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 14/25] ALSA: sh: " Takashi Iwai
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the rme9652 driver code to use the new unified PCM
copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

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

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/rme9652/rme9652.c | 46 +++++--------------------------------
 1 file changed, 6 insertions(+), 40 deletions(-)

diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index e7c320afefe8..fb01d9c4247b 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -1844,7 +1844,7 @@ static signed char *rme9652_channel_buffer_location(struct snd_rme9652 *rme9652,
 
 static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream,
 				     int channel, unsigned long pos,
-				     void __user *src, unsigned long count)
+				     struct iov_iter *src, unsigned long count)
 {
 	struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
 	signed char *channel_buf;
@@ -1857,30 +1857,14 @@ static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream,
 						       channel);
 	if (snd_BUG_ON(!channel_buf))
 		return -EIO;
-	if (copy_from_user(channel_buf + pos, src, count))
+	if (!copy_from_iter(channel_buf + pos, count, src))
 		return -EFAULT;
 	return 0;
 }
 
-static int snd_rme9652_playback_copy_kernel(struct snd_pcm_substream *substream,
-					    int channel, unsigned long pos,
-					    void *src, unsigned long count)
-{
-	struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
-	signed char *channel_buf;
-
-	channel_buf = rme9652_channel_buffer_location(rme9652,
-						      substream->pstr->stream,
-						      channel);
-	if (snd_BUG_ON(!channel_buf))
-		return -EIO;
-	memcpy(channel_buf + pos, src, count);
-	return 0;
-}
-
 static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream,
 				    int channel, unsigned long pos,
-				    void __user *dst, unsigned long count)
+				    struct iov_iter *dst, unsigned long count)
 {
 	struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
 	signed char *channel_buf;
@@ -1893,27 +1877,11 @@ static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream,
 						       channel);
 	if (snd_BUG_ON(!channel_buf))
 		return -EIO;
-	if (copy_to_user(dst, channel_buf + pos, count))
+	if (!copy_to_iter(channel_buf + pos, count, dst))
 		return -EFAULT;
 	return 0;
 }
 
-static int snd_rme9652_capture_copy_kernel(struct snd_pcm_substream *substream,
-					   int channel, unsigned long pos,
-					   void *dst, unsigned long count)
-{
-	struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
-	signed char *channel_buf;
-
-	channel_buf = rme9652_channel_buffer_location(rme9652,
-						      substream->pstr->stream,
-						      channel);
-	if (snd_BUG_ON(!channel_buf))
-		return -EIO;
-	memcpy(dst, channel_buf + pos, count);
-	return 0;
-}
-
 static int snd_rme9652_hw_silence(struct snd_pcm_substream *substream,
 				  int channel, unsigned long pos,
 				  unsigned long count)
@@ -2370,8 +2338,7 @@ static const struct snd_pcm_ops snd_rme9652_playback_ops = {
 	.prepare =	snd_rme9652_prepare,
 	.trigger =	snd_rme9652_trigger,
 	.pointer =	snd_rme9652_hw_pointer,
-	.copy_user =	snd_rme9652_playback_copy,
-	.copy_kernel =	snd_rme9652_playback_copy_kernel,
+	.copy =		snd_rme9652_playback_copy,
 	.fill_silence =	snd_rme9652_hw_silence,
 };
 
@@ -2383,8 +2350,7 @@ static const struct snd_pcm_ops snd_rme9652_capture_ops = {
 	.prepare =	snd_rme9652_prepare,
 	.trigger =	snd_rme9652_trigger,
 	.pointer =	snd_rme9652_hw_pointer,
-	.copy_user =	snd_rme9652_capture_copy,
-	.copy_kernel =	snd_rme9652_capture_copy_kernel,
+	.copy =		snd_rme9652_capture_copy,
 };
 
 static int snd_rme9652_create_pcm(struct snd_card *card,
-- 
2.35.3


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

* [PATCH 14/25] ALSA: sh: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (12 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 13/25] ALSA: rme9652: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 15/25] ALSA: xen: " Takashi Iwai
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

This patch converts the sh_dac_audio driver code to use the new
unified PCM copy callback.  It's a straightforward conversion from
*_user() to *_iter() variants.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/sh/sh_dac_audio.c | 25 +++----------------------
 1 file changed, 3 insertions(+), 22 deletions(-)

diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c
index 8cf571955c9d..95ba3abd4e47 100644
--- a/sound/sh/sh_dac_audio.c
+++ b/sound/sh/sh_dac_audio.c
@@ -158,12 +158,12 @@ static int snd_sh_dac_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 
 static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream,
 			       int channel, unsigned long pos,
-			       void __user *src, unsigned long count)
+			       struct iov_iter *src, unsigned long count)
 {
 	/* channel is not used (interleaved data) */
 	struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
 
-	if (copy_from_user_toio(chip->data_buffer + pos, src, count))
+	if (copy_from_iter_toio(chip->data_buffer + pos, src, count))
 		return -EFAULT;
 	chip->buffer_end = chip->data_buffer + pos + count;
 
@@ -175,24 +175,6 @@ static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-static int snd_sh_dac_pcm_copy_kernel(struct snd_pcm_substream *substream,
-				      int channel, unsigned long pos,
-				      void *src, unsigned long count)
-{
-	/* channel is not used (interleaved data) */
-	struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
-
-	memcpy_toio(chip->data_buffer + pos, src, count);
-	chip->buffer_end = chip->data_buffer + pos + count;
-
-	if (chip->empty) {
-		chip->empty = 0;
-		dac_audio_start_timer(chip);
-	}
-
-	return 0;
-}
-
 static int snd_sh_dac_pcm_silence(struct snd_pcm_substream *substream,
 				  int channel, unsigned long pos,
 				  unsigned long count)
@@ -227,8 +209,7 @@ static const struct snd_pcm_ops snd_sh_dac_pcm_ops = {
 	.prepare	= snd_sh_dac_pcm_prepare,
 	.trigger	= snd_sh_dac_pcm_trigger,
 	.pointer	= snd_sh_dac_pcm_pointer,
-	.copy_user	= snd_sh_dac_pcm_copy,
-	.copy_kernel	= snd_sh_dac_pcm_copy_kernel,
+	.copy		= snd_sh_dac_pcm_copy,
 	.fill_silence	= snd_sh_dac_pcm_silence,
 	.mmap		= snd_pcm_lib_mmap_iomem,
 };
-- 
2.35.3


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

* [PATCH 15/25] ALSA: xen: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (13 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 14/25] ALSA: sh: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 16/25] ALSA: pcmtest: Update comment about " Takashi Iwai
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai, Oleksandr Andrushchenko, xen-devel

This patch converts the xen frontend driver code to use the new
unified PCM copy callback.  It's a straightforward conversion from
*_user() to *_iter() variants.

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

Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Cc: xen-devel@lists.xenproject.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/xen/xen_snd_front_alsa.c | 55 +++++++---------------------------
 1 file changed, 10 insertions(+), 45 deletions(-)

diff --git a/sound/xen/xen_snd_front_alsa.c b/sound/xen/xen_snd_front_alsa.c
index db917453a473..363351bff264 100644
--- a/sound/xen/xen_snd_front_alsa.c
+++ b/sound/xen/xen_snd_front_alsa.c
@@ -602,38 +602,24 @@ static snd_pcm_uframes_t alsa_pointer(struct snd_pcm_substream *substream)
 	return (snd_pcm_uframes_t)atomic_read(&stream->hw_ptr);
 }
 
-static int alsa_pb_copy_user(struct snd_pcm_substream *substream,
-			     int channel, unsigned long pos, void __user *src,
-			     unsigned long count)
+static int alsa_pb_copy(struct snd_pcm_substream *substream,
+			int channel, unsigned long pos, struct iov_iter *src,
+			unsigned long count)
 {
 	struct xen_snd_front_pcm_stream_info *stream = stream_get(substream);
 
 	if (unlikely(pos + count > stream->buffer_sz))
 		return -EINVAL;
 
-	if (copy_from_user(stream->buffer + pos, src, count))
+	if (!copy_from_iter(stream->buffer + pos, count, src))
 		return -EFAULT;
 
 	return xen_snd_front_stream_write(&stream->evt_pair->req, pos, count);
 }
 
-static int alsa_pb_copy_kernel(struct snd_pcm_substream *substream,
-			       int channel, unsigned long pos, void *src,
-			       unsigned long count)
-{
-	struct xen_snd_front_pcm_stream_info *stream = stream_get(substream);
-
-	if (unlikely(pos + count > stream->buffer_sz))
-		return -EINVAL;
-
-	memcpy(stream->buffer + pos, src, count);
-
-	return xen_snd_front_stream_write(&stream->evt_pair->req, pos, count);
-}
-
-static int alsa_cap_copy_user(struct snd_pcm_substream *substream,
-			      int channel, unsigned long pos, void __user *dst,
-			      unsigned long count)
+static int alsa_cap_copy(struct snd_pcm_substream *substream,
+			 int channel, unsigned long pos, struct iov_iter *dst,
+			 unsigned long count)
 {
 	struct xen_snd_front_pcm_stream_info *stream = stream_get(substream);
 	int ret;
@@ -645,29 +631,10 @@ static int alsa_cap_copy_user(struct snd_pcm_substream *substream,
 	if (ret < 0)
 		return ret;
 
-	return copy_to_user(dst, stream->buffer + pos, count) ?
+	return !copy_to_iter(stream->buffer + pos, count, dst) ?
 		-EFAULT : 0;
 }
 
-static int alsa_cap_copy_kernel(struct snd_pcm_substream *substream,
-				int channel, unsigned long pos, void *dst,
-				unsigned long count)
-{
-	struct xen_snd_front_pcm_stream_info *stream = stream_get(substream);
-	int ret;
-
-	if (unlikely(pos + count > stream->buffer_sz))
-		return -EINVAL;
-
-	ret = xen_snd_front_stream_read(&stream->evt_pair->req, pos, count);
-	if (ret < 0)
-		return ret;
-
-	memcpy(dst, stream->buffer + pos, count);
-
-	return 0;
-}
-
 static int alsa_pb_fill_silence(struct snd_pcm_substream *substream,
 				int channel, unsigned long pos,
 				unsigned long count)
@@ -697,8 +664,7 @@ static const struct snd_pcm_ops snd_drv_alsa_playback_ops = {
 	.prepare	= alsa_prepare,
 	.trigger	= alsa_trigger,
 	.pointer	= alsa_pointer,
-	.copy_user	= alsa_pb_copy_user,
-	.copy_kernel	= alsa_pb_copy_kernel,
+	.copy		= alsa_pb_copy,
 	.fill_silence	= alsa_pb_fill_silence,
 };
 
@@ -710,8 +676,7 @@ static const struct snd_pcm_ops snd_drv_alsa_capture_ops = {
 	.prepare	= alsa_prepare,
 	.trigger	= alsa_trigger,
 	.pointer	= alsa_pointer,
-	.copy_user	= alsa_cap_copy_user,
-	.copy_kernel	= alsa_cap_copy_kernel,
+	.copy		= alsa_cap_copy,
 };
 
 static int new_pcm_instance(struct xen_snd_front_card_info *card_info,
-- 
2.35.3


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

* [PATCH 16/25] ALSA: pcmtest: Update comment about PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (14 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 15/25] ALSA: xen: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 17/25] media: solo6x10: Convert to generic " Takashi Iwai
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

Just an update of a comment mentioning the old PCM callbacks to
correct to the new PCM copy ops.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/drivers/pcmtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c
index 291e7fe47893..d205e10a0605 100644
--- a/sound/drivers/pcmtest.c
+++ b/sound/drivers/pcmtest.c
@@ -225,7 +225,7 @@ static void check_buf_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runti
 
 /*
  * Fill buffer in the non-interleaved mode. The order of samples is C0, ..., C0, C1, ..., C1, C2...
- * The channel buffers lay in the DMA buffer continuously (see default copy_user and copy_kernel
+ * The channel buffers lay in the DMA buffer continuously (see default copy
  * handlers in the pcm_lib.c file).
  *
  * Here we increment the DMA buffer position every time we write a byte to any channel 'buffer'.
-- 
2.35.3


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

* [PATCH 17/25] media: solo6x10: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (15 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 16/25] ALSA: pcmtest: Update comment about " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 12:15   ` Ismael Luceno
  2023-08-14 11:55 ` [PATCH 18/25] ASoC: component: Add " Takashi Iwai
                   ` (7 subsequent siblings)
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel
  Cc: linux-kernel, Takashi Iwai, Bluecherry Maintainers,
	Anton Sviridenko, Andrey Utkin, Ismael Luceno,
	Mauro Carvalho Chehab, linux-media

This patch converts the solo6x10 driver code to use the new unified
PCM copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.  As copy_to_iter() updates the internal offest at
each write, we can drop the dst counter update in the loop, too.

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

Cc: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
Cc: Anton Sviridenko <anton@corp.bluecherry.net>
Cc: Andrey Utkin <andrey_utkin@fastmail.com>
Cc: Ismael Luceno <ismael@iodev.co.uk>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/media/pci/solo6x10/solo6x10-g723.c | 38 +++-------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
index 6cebad665565..aceacb822cab 100644
--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
@@ -204,9 +204,9 @@ static snd_pcm_uframes_t snd_solo_pcm_pointer(struct snd_pcm_substream *ss)
 	return idx * G723_FRAMES_PER_PAGE;
 }
 
-static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
-				  unsigned long pos, void __user *dst,
-				  unsigned long count)
+static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel,
+			     unsigned long pos, struct iov_iter *dst,
+			     unsigned long count)
 {
 	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
 	struct solo_dev *solo_dev = solo_pcm->solo_dev;
@@ -223,35 +223,8 @@ static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
 		if (err)
 			return err;
 
-		if (copy_to_user(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES))
+		if (!copy_to_iter(solo_pcm->g723_buf, G723_PERIOD_BYTES, dst))
 			return -EFAULT;
-		dst += G723_PERIOD_BYTES;
-	}
-
-	return 0;
-}
-
-static int snd_solo_pcm_copy_kernel(struct snd_pcm_substream *ss, int channel,
-				    unsigned long pos, void *dst,
-				    unsigned long count)
-{
-	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
-	struct solo_dev *solo_dev = solo_pcm->solo_dev;
-	int err, i;
-
-	for (i = 0; i < (count / G723_FRAMES_PER_PAGE); i++) {
-		int page = (pos / G723_FRAMES_PER_PAGE) + i;
-
-		err = solo_p2m_dma_t(solo_dev, 0, solo_pcm->g723_dma,
-				     SOLO_G723_EXT_ADDR(solo_dev) +
-				     (page * G723_PERIOD_BLOCK) +
-				     (ss->number * G723_PERIOD_BYTES),
-				     G723_PERIOD_BYTES, 0, 0);
-		if (err)
-			return err;
-
-		memcpy(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES);
-		dst += G723_PERIOD_BYTES;
 	}
 
 	return 0;
@@ -263,8 +236,7 @@ static const struct snd_pcm_ops snd_solo_pcm_ops = {
 	.prepare = snd_solo_pcm_prepare,
 	.trigger = snd_solo_pcm_trigger,
 	.pointer = snd_solo_pcm_pointer,
-	.copy_user = snd_solo_pcm_copy_user,
-	.copy_kernel = snd_solo_pcm_copy_kernel,
+	.copy = snd_solo_pcm_copy,
 };
 
 static int snd_solo_capture_volume_info(struct snd_kcontrol *kcontrol,
-- 
2.35.3


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

* [PATCH 18/25] ASoC: component: Add generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (16 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 17/25] media: solo6x10: Convert to generic " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 12:59   ` Mark Brown
  2023-08-15 13:56   ` Andy Shevchenko
  2023-08-14 11:55 ` [PATCH 19/25] ASoC: mediatek: Convert to " Takashi Iwai
                   ` (6 subsequent siblings)
  24 siblings, 2 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai, Mark Brown

For following the ALSA PCM core change, a new PCM copy ops is added
toe ASoC component framework: snd_soc_component_driver receives the
copy ops, and snd_soc_pcm_component_copy() helper is provided.

This also fixes a long-standing potential bug where the ASoC driver
covers only copy_user PCM callback and misses the copy from kernel
pointers (such as OSS PCM layer), too.

As of this patch, the old copy_user is still kept, but it'll be
dropped later after all drivers are converted.

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/soc-component.h |  7 +++++++
 sound/soc/soc-component.c     | 20 ++++++++++++++++++++
 sound/soc/soc-pcm.c           |  4 +++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index 87f248a06271..8040f001f2fb 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -141,6 +141,10 @@ struct snd_soc_component_driver {
 			 struct snd_pcm_substream *substream, int channel,
 			 unsigned long pos, void __user *buf,
 			 unsigned long bytes);
+	int (*copy)(struct snd_soc_component *component,
+		    struct snd_pcm_substream *substream, int channel,
+		    unsigned long pos, struct iov_iter *buf,
+		    unsigned long bytes);
 	struct page *(*page)(struct snd_soc_component *component,
 			     struct snd_pcm_substream *substream,
 			     unsigned long offset);
@@ -512,6 +516,9 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
 				    int channel, unsigned long pos,
 				    void __user *buf, unsigned long bytes);
+int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
+			       int channel, unsigned long pos,
+			       struct iov_iter *buf, unsigned long bytes);
 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
 					unsigned long offset);
 int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 4356cc320fea..ccab47f22122 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -1052,6 +1052,26 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
 	return 0;
 }
 
+int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
+			       int channel, unsigned long pos,
+			       struct iov_iter *buf, unsigned long bytes)
+{
+	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+	struct snd_soc_component *component;
+	int i;
+
+	/* FIXME. it returns 1st copy now */
+	for_each_rtd_components(rtd, i, component)
+		if (component->driver->copy)
+			return soc_component_ret(
+				component,
+				component->driver->copy(
+					component, substream, channel,
+					pos, buf, bytes));
+
+	return -EINVAL;
+}
+
 int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
 				    int channel, unsigned long pos,
 				    void __user *buf, unsigned long bytes)
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 8896227e4fb7..71403da28d37 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2973,7 +2973,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 			rtd->ops.ioctl		= snd_soc_pcm_component_ioctl;
 		if (drv->sync_stop)
 			rtd->ops.sync_stop	= snd_soc_pcm_component_sync_stop;
-		if (drv->copy_user)
+		if (drv->copy)
+			rtd->ops.copy		= snd_soc_pcm_component_copy;
+		else if (drv->copy_user)
 			rtd->ops.copy_user	= snd_soc_pcm_component_copy_user;
 		if (drv->page)
 			rtd->ops.page		= snd_soc_pcm_component_page;
-- 
2.35.3


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

* [PATCH 19/25] ASoC: mediatek: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (17 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 18/25] ASoC: component: Add " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 13:00   ` Mark Brown
  2023-08-15 13:58   ` Andy Shevchenko
  2023-08-14 11:55 ` [PATCH 20/25] ASoC: qcom: " Takashi Iwai
                   ` (5 subsequent siblings)
  24 siblings, 2 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai, Mark Brown

This patch converts the mediatek BT SCO driver code to use the new
unified PCM copy callback.  It's a straightforward conversion from
*_user() to *_iter() variants.  As copy_form/to_iter() updates the
internal offset at each read/write, we can drop the cur_*_idx counter
in the loop, too.

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

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/mediatek/common/mtk-btcvsd.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c
index 1ba0633e542f..64150f3cec0e 100644
--- a/sound/soc/mediatek/common/mtk-btcvsd.c
+++ b/sound/soc/mediatek/common/mtk-btcvsd.c
@@ -696,11 +696,10 @@ static int wait_for_bt_irq(struct mtk_btcvsd_snd *bt,
 }
 
 static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt,
-				   char __user *buf,
+				   struct iov_iter *buf,
 				   size_t count)
 {
 	ssize_t read_size = 0, read_count = 0, cur_read_idx, cont;
-	unsigned int cur_buf_ofs = 0;
 	unsigned long avail;
 	unsigned long flags;
 	unsigned int packet_size = bt->rx->packet_size;
@@ -743,9 +742,8 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt,
 		if (read_size > cont)
 			read_size = cont;
 
-		if (copy_to_user(buf + cur_buf_ofs,
-				 bt->rx_packet_buf + cur_read_idx,
-				 read_size)) {
+		if (!copy_to_iter(bt->rx_packet_buf + cur_read_idx,
+				  read_size, buf)) {
 			dev_warn(bt->dev, "%s(), copy_to_user fail\n",
 				 __func__);
 			return -EFAULT;
@@ -756,7 +754,6 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt,
 		spin_unlock_irqrestore(&bt->rx_lock, flags);
 
 		read_count += read_size;
-		cur_buf_ofs += read_size;
 		count -= read_size;
 	}
 
@@ -777,11 +774,10 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt,
 }
 
 static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt,
-				    char __user *buf,
+				    struct iov_iter *buf,
 				    size_t count)
 {
 	int written_size = count, avail, cur_write_idx, write_size, cont;
-	unsigned int cur_buf_ofs = 0;
 	unsigned long flags;
 	unsigned int packet_size = bt->tx->packet_size;
 
@@ -835,10 +831,8 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt,
 		if (write_size > cont)
 			write_size = cont;
 
-		if (copy_from_user(bt->tx_packet_buf +
-				   cur_write_idx,
-				   buf + cur_buf_ofs,
-				   write_size)) {
+		if (!copy_from_iter(bt->tx_packet_buf + cur_write_idx,
+				    write_size, buf)) {
 			dev_warn(bt->dev, "%s(), copy_from_user fail\n",
 				 __func__);
 			return -EFAULT;
@@ -847,7 +841,6 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt,
 		spin_lock_irqsave(&bt->tx_lock, flags);
 		bt->tx->packet_w += write_size / packet_size;
 		spin_unlock_irqrestore(&bt->tx_lock, flags);
-		cur_buf_ofs += write_size;
 		count -= write_size;
 	}
 
@@ -1033,7 +1026,7 @@ static snd_pcm_uframes_t mtk_pcm_btcvsd_pointer(
 static int mtk_pcm_btcvsd_copy(struct snd_soc_component *component,
 			       struct snd_pcm_substream *substream,
 			       int channel, unsigned long pos,
-			       void __user *buf, unsigned long count)
+			       struct iov_iter *buf, unsigned long count)
 {
 	struct mtk_btcvsd_snd *bt = snd_soc_component_get_drvdata(component);
 
@@ -1274,7 +1267,7 @@ static const struct snd_soc_component_driver mtk_btcvsd_snd_platform = {
 	.prepare	= mtk_pcm_btcvsd_prepare,
 	.trigger	= mtk_pcm_btcvsd_trigger,
 	.pointer	= mtk_pcm_btcvsd_pointer,
-	.copy_user	= mtk_pcm_btcvsd_copy,
+	.copy		= mtk_pcm_btcvsd_copy,
 };
 
 static int mtk_btcvsd_snd_probe(struct platform_device *pdev)
-- 
2.35.3


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

* [PATCH 20/25] ASoC: qcom: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (18 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 19/25] ASoC: mediatek: Convert to " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 13:06   ` Mark Brown
  2023-08-14 11:55 ` [PATCH 21/25] ASoC: dmaengine: " Takashi Iwai
                   ` (4 subsequent siblings)
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel
  Cc: linux-kernel, Takashi Iwai, Srinivas Kandagatla, Banajit Goswami,
	Mark Brown

This patch converts the qcom lpass driver code to use the new unified
PCM copy callback.  It's a straightforward conversion from *_user() to
*_iter() variants.

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

Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Banajit Goswami <bgoswami@quicinc.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/qcom/lpass-platform.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index ef5cb40b2d9b..4ab6ac085b84 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -1219,7 +1219,8 @@ static int lpass_platform_pcmops_resume(struct snd_soc_component *component)
 
 static int lpass_platform_copy(struct snd_soc_component *component,
 			       struct snd_pcm_substream *substream, int channel,
-			       unsigned long pos, void __user *buf, unsigned long bytes)
+			       unsigned long pos, struct iov_iter *buf,
+			       unsigned long bytes)
 {
 	struct snd_pcm_runtime *rt = substream->runtime;
 	unsigned int dai_id = component->id;
@@ -1230,16 +1231,16 @@ static int lpass_platform_copy(struct snd_soc_component *component,
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		if (is_cdc_dma_port(dai_id)) {
-			ret = copy_from_user_toio(dma_buf, buf, bytes);
+			ret = copy_from_iter_toio(dma_buf, buf, bytes);
 		} else {
-			if (copy_from_user((void __force *)dma_buf, buf, bytes))
+			if (!copy_from_iter((void __force *)dma_buf, bytes, buf))
 				ret = -EFAULT;
 		}
 	} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
 		if (is_cdc_dma_port(dai_id)) {
-			ret = copy_to_user_fromio(buf, dma_buf, bytes);
+			ret = copy_to_iter_fromio(buf, dma_buf, bytes);
 		} else {
-			if (copy_to_user(buf, (void __force *)dma_buf, bytes))
+			if (!copy_to_iter((void __force *)dma_buf, bytes, buf))
 				ret = -EFAULT;
 		}
 	}
@@ -1260,7 +1261,7 @@ static const struct snd_soc_component_driver lpass_component_driver = {
 	.pcm_construct	= lpass_platform_pcm_new,
 	.suspend		= lpass_platform_pcmops_suspend,
 	.resume			= lpass_platform_pcmops_resume,
-	.copy_user		= lpass_platform_copy,
+	.copy		= lpass_platform_copy,
 
 };
 
-- 
2.35.3


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

* [PATCH 21/25] ASoC: dmaengine: Convert to generic PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (19 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 20/25] ASoC: qcom: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 13:18   ` Mark Brown
  2023-08-15 14:00   ` Andy Shevchenko
  2023-08-14 11:55 ` [PATCH 22/25] ASoC: dmaengine: Use iov_iter for process callback, too Takashi Iwai
                   ` (3 subsequent siblings)
  24 siblings, 2 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai, Lars-Peter Clausen, Mark Brown

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

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,
 };
 
-- 
2.35.3


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

* [PATCH 22/25] ASoC: dmaengine: Use iov_iter for process callback, too
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (20 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 21/25] ASoC: dmaengine: " Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 13:19   ` Mark Brown
  2023-08-14 11:55 ` [PATCH 23/25] ALSA: doc: Update description for the new PCM copy ops Takashi Iwai
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel
  Cc: linux-kernel, Takashi Iwai, Lars-Peter Clausen, Claudiu Beznea,
	Mark Brown, Olivier Moysan, Arnaud Pouliquen

Along with the conversion to PCM copy ops, use the iov_iter for the
pointer to be passed to the dmaengine process callback, too.  It
avoids the direct reference of iter_iov_addr(), and it can potentially
help for the drivers to access memory properly (although both atmel
and stm drivers don't use the given buffer address at all for now).

Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Claudiu Beznea <claudiu.beznea@microchip.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Olivier Moysan <olivier.moysan@foss.st.com>
Cc: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/dmaengine_pcm.h         | 2 +-
 sound/soc/atmel/mchp-pdmc.c           | 2 +-
 sound/soc/soc-generic-dmaengine-pcm.c | 5 ++---
 sound/soc/stm/stm32_sai_sub.c         | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h
index 2df54cf02cb3..c9a8bce9a785 100644
--- a/include/sound/dmaengine_pcm.h
+++ b/include/sound/dmaengine_pcm.h
@@ -142,7 +142,7 @@ struct snd_dmaengine_pcm_config {
 			struct snd_pcm_substream *substream);
 	int (*process)(struct snd_pcm_substream *substream,
 		       int channel, unsigned long hwoff,
-		       void *buf, unsigned long bytes);
+		       struct iov_iter *buf, unsigned long bytes);
 	dma_filter_fn compat_filter_fn;
 	struct device *dma_dev;
 	const char *chan_names[SNDRV_PCM_STREAM_LAST + 1];
diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c
index c79c73e6791e..b3afcf25b4a9 100644
--- a/sound/soc/atmel/mchp-pdmc.c
+++ b/sound/soc/atmel/mchp-pdmc.c
@@ -962,7 +962,7 @@ static int mchp_pdmc_dt_init(struct mchp_pdmc *dd)
 /* used to clean the channel index found on RHR's MSB */
 static int mchp_pdmc_process(struct snd_pcm_substream *substream,
 			     int channel, unsigned long hwoff,
-			     void *buf, unsigned long bytes)
+			     struct iov_iter *buf, unsigned long bytes)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	u8 *dma_ptr = runtime->dma_area + hwoff +
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index 1a4f000fddb9..6dee033ab9b9 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -296,18 +296,17 @@ static int dmaengine_copy(struct snd_soc_component *component,
 	struct dmaengine_pcm *pcm = soc_component_to_pcm(component);
 	int (*process)(struct snd_pcm_substream *substream,
 		       int channel, unsigned long hwoff,
-		       void *buf, unsigned long bytes) = pcm->config->process;
+		       struct iov_iter *buf, unsigned long bytes) = pcm->config->process;
 	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_iter(dma_ptr, bytes, buf))
 			return -EFAULT;
 
 	if (process) {
-		int ret = process(substream, channel, hwoff, ptr, bytes);
+		int ret = process(substream, channel, hwoff, buf, bytes);
 		if (ret < 0)
 			return ret;
 	}
diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c
index 271ec5b3378d..39f9b4654fa2 100644
--- a/sound/soc/stm/stm32_sai_sub.c
+++ b/sound/soc/stm/stm32_sai_sub.c
@@ -1233,7 +1233,7 @@ static const struct snd_soc_dai_ops stm32_sai_pcm_dai_ops = {
 
 static int stm32_sai_pcm_process_spdif(struct snd_pcm_substream *substream,
 				       int channel, unsigned long hwoff,
-				       void *buf, unsigned long bytes)
+				       struct iov_iter *buf, unsigned long bytes)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-- 
2.35.3


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

* [PATCH 23/25] ALSA: doc: Update description for the new PCM copy ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (21 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 22/25] ASoC: dmaengine: Use iov_iter for process callback, too Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 11:55 ` [PATCH 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops Takashi Iwai
  2023-08-14 11:55 ` [PATCH 25/25] ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops Takashi Iwai
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

Update the documentation about the PCM copy callbacks.
The update was kept minimalistic, just correcting the use of copy_user
ops with the single copy ops, and drop/update the text mentioning the
copy_kernel.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 .../kernel-api/writing-an-alsa-driver.rst     | 58 ++++++-------------
 1 file changed, 19 insertions(+), 39 deletions(-)

diff --git a/Documentation/sound/kernel-api/writing-an-alsa-driver.rst b/Documentation/sound/kernel-api/writing-an-alsa-driver.rst
index 4335c98b3d82..cd421856409e 100644
--- a/Documentation/sound/kernel-api/writing-an-alsa-driver.rst
+++ b/Documentation/sound/kernel-api/writing-an-alsa-driver.rst
@@ -2018,8 +2018,8 @@ sleeping poll threads, etc.
 
 This callback is also atomic by default.
 
-copy_user, copy_kernel and fill_silence ops
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+copy and fill_silence ops
+~~~~~~~~~~~~~~~~~~~~~~~~~
 
 These callbacks are not mandatory, and can be omitted in most cases.
 These callbacks are used when the hardware buffer cannot be in the
@@ -3444,8 +3444,8 @@ external hardware buffer in interrupts (or in tasklets, preferably).
 
 The first case works fine if the external hardware buffer is large
 enough. This method doesn't need any extra buffers and thus is more
-efficient. You need to define the ``copy_user`` and ``copy_kernel``
-callbacks for the data transfer, in addition to the ``fill_silence``
+efficient. You need to define the ``copy`` callback
+for the data transfer, in addition to the ``fill_silence``
 callback for playback. However, there is a drawback: it cannot be
 mmapped. The examples are GUS's GF1 PCM or emu8000's wavetable PCM.
 
@@ -3458,22 +3458,22 @@ Another case is when the chip uses a PCI memory-map region for the
 buffer instead of the host memory. In this case, mmap is available only
 on certain architectures like the Intel one. In non-mmap mode, the data
 cannot be transferred as in the normal way. Thus you need to define the
-``copy_user``, ``copy_kernel`` and ``fill_silence`` callbacks as well,
+``copy`` and ``fill_silence`` callbacks as well,
 as in the cases above. Examples are found in ``rme32.c`` and
 ``rme96.c``.
 
-The implementation of the ``copy_user``, ``copy_kernel`` and
+The implementation of the ``copy`` and
 ``silence`` callbacks depends upon whether the hardware supports
-interleaved or non-interleaved samples. The ``copy_user`` callback is
+interleaved or non-interleaved samples. The ``copy`` callback is
 defined like below, a bit differently depending on whether the direction
 is playback or capture::
 
-  static int playback_copy_user(struct snd_pcm_substream *substream,
+  static int playback_copy(struct snd_pcm_substream *substream,
                int channel, unsigned long pos,
-               void __user *src, unsigned long count);
-  static int capture_copy_user(struct snd_pcm_substream *substream,
+               struct iov_iter *src, unsigned long count);
+  static int capture_copy(struct snd_pcm_substream *substream,
                int channel, unsigned long pos,
-               void __user *dst, unsigned long count);
+               struct iov_iter *dst, unsigned long count);
 
 In the case of interleaved samples, the second argument (``channel``) is
 not used. The third argument (``pos``) specifies the position in bytes.
@@ -3490,18 +3490,17 @@ of data (``count``) at the specified pointer (``src``) to the specified
 offset (``pos``) in the hardware buffer. When coded like memcpy-like
 way, the copy would look like::
 
-  my_memcpy_from_user(my_buffer + pos, src, count);
+  my_memcpy_from_iter(my_buffer + pos, src, count);
 
 For the capture direction, you copy the given amount of data (``count``)
 at the specified offset (``pos``) in the hardware buffer to the
 specified pointer (``dst``)::
 
-  my_memcpy_to_user(dst, my_buffer + pos, count);
+  my_memcpy_to_iter(dst, my_buffer + pos, count);
 
-Here the functions are named ``from_user`` and ``to_user`` because
-it's the user-space buffer that is passed to these callbacks.  That
-is, the callback is supposed to copy data from/to the user-space
-directly to/from the hardware buffer.
+The given ``src`` or ``dst`` a struct iov_iter pointer containing the
+pointer and the size.  Use the existing helpers to copy or access the
+data as defined in ``linux/uio.h``.
 
 Careful readers might notice that these callbacks receive the
 arguments in bytes, not in frames like other callbacks.  It's because
@@ -3519,25 +3518,6 @@ the given user-space buffer, but only for the given channel. For
 details, please check ``isa/gus/gus_pcm.c`` or ``pci/rme9652/rme9652.c``
 as examples.
 
-The above callbacks are the copies from/to the user-space buffer.  There
-are some cases where we want to copy from/to the kernel-space buffer
-instead.  In such a case, the ``copy_kernel`` callback is called.  It'd
-look like::
-
-  static int playback_copy_kernel(struct snd_pcm_substream *substream,
-               int channel, unsigned long pos,
-               void *src, unsigned long count);
-  static int capture_copy_kernel(struct snd_pcm_substream *substream,
-               int channel, unsigned long pos,
-               void *dst, unsigned long count);
-
-As found easily, the only difference is that the buffer pointer is
-without a ``__user`` prefix; that is, a kernel-buffer pointer is passed
-in the fourth argument.  Correspondingly, the implementation would be
-a version without the user-copy, such as::
-
-  my_memcpy(my_buffer + pos, src, count);
-
 Usually for the playback, another callback ``fill_silence`` is
 defined.  It's implemented in a similar way as the copy callbacks
 above::
@@ -3545,10 +3525,10 @@ above::
   static int silence(struct snd_pcm_substream *substream, int channel,
                      unsigned long pos, unsigned long count);
 
-The meanings of arguments are the same as in the ``copy_user`` and
-``copy_kernel`` callbacks, although there is no buffer pointer
+The meanings of arguments are the same as in the ``copy`` callback,
+although there is no buffer pointer
 argument. In the case of interleaved samples, the channel argument has
-no meaning, as for the ``copy_*`` callbacks.
+no meaning, as for the ``copy`` callback.
 
 The role of the ``fill_silence`` callback is to set the given amount
 (``count``) of silence data at the specified offset (``pos``) in the
-- 
2.35.3


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

* [PATCH 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (22 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 23/25] ALSA: doc: Update description for the new PCM copy ops Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  2023-08-14 13:19   ` Mark Brown
  2023-08-14 11:55 ` [PATCH 25/25] ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops Takashi Iwai
  24 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai, Mark Brown

Now all ASoC users have been replaced to use the new PCM copy ops,
let's drop the obsoleted copy_user ops and its helper function.

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/soc-component.h |  7 -------
 sound/soc/soc-component.c     | 20 --------------------
 sound/soc/soc-pcm.c           |  2 --
 3 files changed, 29 deletions(-)

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index 8040f001f2fb..17bea3144551 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -137,10 +137,6 @@ struct snd_soc_component_driver {
 		struct timespec64 *audio_ts,
 		struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
 		struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
-	int (*copy_user)(struct snd_soc_component *component,
-			 struct snd_pcm_substream *substream, int channel,
-			 unsigned long pos, void __user *buf,
-			 unsigned long bytes);
 	int (*copy)(struct snd_soc_component *component,
 		    struct snd_pcm_substream *substream, int channel,
 		    unsigned long pos, struct iov_iter *buf,
@@ -513,9 +509,6 @@ int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
 int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
 				unsigned int cmd, void *arg);
 int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
-int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
-				    int channel, unsigned long pos,
-				    void __user *buf, unsigned long bytes);
 int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
 			       int channel, unsigned long pos,
 			       struct iov_iter *buf, unsigned long bytes);
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index ccab47f22122..d8fbbfc14dc2 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -1072,26 +1072,6 @@ int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
 	return -EINVAL;
 }
 
-int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
-				    int channel, unsigned long pos,
-				    void __user *buf, unsigned long bytes)
-{
-	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-	struct snd_soc_component *component;
-	int i;
-
-	/* FIXME. it returns 1st copy now */
-	for_each_rtd_components(rtd, i, component)
-		if (component->driver->copy_user)
-			return soc_component_ret(
-				component,
-				component->driver->copy_user(
-					component, substream, channel,
-					pos, buf, bytes));
-
-	return -EINVAL;
-}
-
 struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
 					unsigned long offset)
 {
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 71403da28d37..ae02d1d80c88 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2975,8 +2975,6 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 			rtd->ops.sync_stop	= snd_soc_pcm_component_sync_stop;
 		if (drv->copy)
 			rtd->ops.copy		= snd_soc_pcm_component_copy;
-		else if (drv->copy_user)
-			rtd->ops.copy_user	= snd_soc_pcm_component_copy_user;
 		if (drv->page)
 			rtd->ops.page		= snd_soc_pcm_component_page;
 		if (drv->mmap)
-- 
2.35.3


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

* [PATCH 25/25] ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops
  2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
                   ` (23 preceding siblings ...)
  2023-08-14 11:55 ` [PATCH 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops Takashi Iwai
@ 2023-08-14 11:55 ` Takashi Iwai
  24 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 11:55 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux-kernel, Takashi Iwai

Finally all users have been converted to the new PCM copy ops, let's
drop the obsoleted copy_kernel and copy_user ops completely.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/pcm.h     |  5 -----
 sound/core/pcm_lib.c    | 18 +-----------------
 sound/core/pcm_native.c |  2 +-
 3 files changed, 2 insertions(+), 23 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index f75beead79e3..958a0b284b5f 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -71,11 +71,6 @@ struct snd_pcm_ops {
 			    unsigned long pos, unsigned long bytes);
 	int (*copy)(struct snd_pcm_substream *substream, int channel,
 		    unsigned long pos, struct iov_iter *iter, unsigned long bytes);
-	int (*copy_user)(struct snd_pcm_substream *substream, int channel,
-			 unsigned long pos, void __user *buf,
-			 unsigned long bytes);
-	int (*copy_kernel)(struct snd_pcm_substream *substream, int channel,
-			   unsigned long pos, void *buf, unsigned long bytes);
 	struct page *(*page)(struct snd_pcm_substream *substream,
 			     unsigned long offset);
 	int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 3303914c58ea..4859fb1caec9 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -2031,19 +2031,6 @@ static int default_read_copy(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-/* a wrapper for calling old copy_kernel or copy_user ops */
-static int call_old_copy(struct snd_pcm_substream *substream,
-			 int channel, unsigned long hwoff,
-			 struct iov_iter *iter, unsigned long bytes)
-{
-	if (iov_iter_is_kvec(iter))
-		return substream->ops->copy_kernel(substream, channel, hwoff,
-						   iter_iov_addr(iter), bytes);
-	else
-		return substream->ops->copy_user(substream, channel, hwoff,
-						 iter_iov_addr(iter), bytes);
-}
-
 /* call transfer with the filled iov_iter */
 static int do_transfer(struct snd_pcm_substream *substream, int c,
 		       unsigned long hwoff, void *data, unsigned long bytes,
@@ -2147,7 +2134,7 @@ static int pcm_sanity_check(struct snd_pcm_substream *substream)
 	if (PCM_RUNTIME_CHECK(substream))
 		return -ENXIO;
 	runtime = substream->runtime;
-	if (snd_BUG_ON(!substream->ops->copy && !substream->ops->copy_user && !runtime->dma_area))
+	if (snd_BUG_ON(!substream->ops->copy && !runtime->dma_area))
 		return -EINVAL;
 	if (runtime->state == SNDRV_PCM_STATE_OPEN)
 		return -EBADFD;
@@ -2255,9 +2242,6 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
 	} else {
 		if (substream->ops->copy)
 			transfer = substream->ops->copy;
-		else if ((in_kernel && substream->ops->copy_kernel) ||
-			 (!in_kernel && substream->ops->copy_user))
-			transfer = call_old_copy;
 		else
 			transfer = is_playback ?
 				default_write_copy : default_read_copy;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 34efd4d198d6..bd9ddf412b46 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -809,7 +809,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
 		runtime->boundary *= 2;
 
 	/* clear the buffer for avoiding possible kernel info leaks */
-	if (runtime->dma_area && !substream->ops->copy && !substream->ops->copy_user) {
+	if (runtime->dma_area && !substream->ops->copy) {
 		size_t size = runtime->dma_bytes;
 
 		if (runtime->info & SNDRV_PCM_INFO_MMAP)
-- 
2.35.3


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

* Re: [PATCH 17/25] media: solo6x10: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 17/25] media: solo6x10: Convert to generic " Takashi Iwai
@ 2023-08-14 12:15   ` Ismael Luceno
  2023-08-14 12:17     ` Takashi Iwai
  0 siblings, 1 reply; 44+ messages in thread
From: Ismael Luceno @ 2023-08-14 12:15 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: alsa-devel, linux-kernel, Bluecherry Maintainers,
	Anton Sviridenko, Andrey Utkin, Mauro Carvalho Chehab,
	linux-media

On 14/Aug/2023 13:55, Takashi Iwai wrote:
> This patch converts the solo6x10 driver code to use the new unified
> PCM copy callback.  It's a straightforward conversion from *_user() to
> *_iter() variants.  As copy_to_iter() updates the internal offest at
> each write, we can drop the dst counter update in the loop, too.
> 
> Note that copy_from/to_iter() returns the copied bytes, hence the
> error condition is inverted from copy_from/to_user().
> 
> Cc: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
> Cc: Anton Sviridenko <anton@corp.bluecherry.net>
> Cc: Andrey Utkin <andrey_utkin@fastmail.com>
> Cc: Ismael Luceno <ismael@iodev.co.uk>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: linux-media@vger.kernel.org
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  drivers/media/pci/solo6x10/solo6x10-g723.c | 38 +++-------------------
>  1 file changed, 5 insertions(+), 33 deletions(-)
> 
> diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
> index 6cebad665565..aceacb822cab 100644
> --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
> +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
> @@ -204,9 +204,9 @@ static snd_pcm_uframes_t snd_solo_pcm_pointer(struct snd_pcm_substream *ss)
>  	return idx * G723_FRAMES_PER_PAGE;
>  }
>  
> -static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
> -				  unsigned long pos, void __user *dst,
> -				  unsigned long count)
> +static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel,
> +			     unsigned long pos, struct iov_iter *dst,
> +			     unsigned long count)
>  {
>  	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
>  	struct solo_dev *solo_dev = solo_pcm->solo_dev;
> @@ -223,35 +223,8 @@ static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
>  		if (err)
>  			return err;
>  
> -		if (copy_to_user(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES))
> +		if (!copy_to_iter(solo_pcm->g723_buf, G723_PERIOD_BYTES, dst))
>  			return -EFAULT;
> -		dst += G723_PERIOD_BYTES;
> -	}
> -
> -	return 0;
> -}
> -
> -static int snd_solo_pcm_copy_kernel(struct snd_pcm_substream *ss, int channel,
> -				    unsigned long pos, void *dst,
> -				    unsigned long count)
> -{
> -	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
> -	struct solo_dev *solo_dev = solo_pcm->solo_dev;
> -	int err, i;
> -
> -	for (i = 0; i < (count / G723_FRAMES_PER_PAGE); i++) {
> -		int page = (pos / G723_FRAMES_PER_PAGE) + i;
> -
> -		err = solo_p2m_dma_t(solo_dev, 0, solo_pcm->g723_dma,
> -				     SOLO_G723_EXT_ADDR(solo_dev) +
> -				     (page * G723_PERIOD_BLOCK) +
> -				     (ss->number * G723_PERIOD_BYTES),
> -				     G723_PERIOD_BYTES, 0, 0);
> -		if (err)
> -			return err;
> -
> -		memcpy(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES);
> -		dst += G723_PERIOD_BYTES;
>  	}
>  
>  	return 0;
> @@ -263,8 +236,7 @@ static const struct snd_pcm_ops snd_solo_pcm_ops = {
>  	.prepare = snd_solo_pcm_prepare,
>  	.trigger = snd_solo_pcm_trigger,
>  	.pointer = snd_solo_pcm_pointer,
> -	.copy_user = snd_solo_pcm_copy_user,
> -	.copy_kernel = snd_solo_pcm_copy_kernel,
> +	.copy = snd_solo_pcm_copy,
>  };
>  
>  static int snd_solo_capture_volume_info(struct snd_kcontrol *kcontrol,
> -- 
> 2.35.3
> 

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>

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

* Re: [PATCH 17/25] media: solo6x10: Convert to generic PCM copy ops
  2023-08-14 12:15   ` Ismael Luceno
@ 2023-08-14 12:17     ` Takashi Iwai
  2023-08-14 12:26       ` Ismael Luceno
  0 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-14 12:17 UTC (permalink / raw)
  To: Ismael Luceno
  Cc: alsa-devel, linux-kernel, Bluecherry Maintainers,
	Anton Sviridenko, Andrey Utkin, Mauro Carvalho Chehab,
	linux-media

On Mon, 14 Aug 2023 14:15:18 +0200,
Ismael Luceno wrote:
> 
> On 14/Aug/2023 13:55, Takashi Iwai wrote:
> > This patch converts the solo6x10 driver code to use the new unified
> > PCM copy callback.  It's a straightforward conversion from *_user() to
> > *_iter() variants.  As copy_to_iter() updates the internal offest at
> > each write, we can drop the dst counter update in the loop, too.
> > 
> > Note that copy_from/to_iter() returns the copied bytes, hence the
> > error condition is inverted from copy_from/to_user().
> > 
> > Cc: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
> > Cc: Anton Sviridenko <anton@corp.bluecherry.net>
> > Cc: Andrey Utkin <andrey_utkin@fastmail.com>
> > Cc: Ismael Luceno <ismael@iodev.co.uk>
> > Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> > Cc: linux-media@vger.kernel.org
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >  drivers/media/pci/solo6x10/solo6x10-g723.c | 38 +++-------------------
> >  1 file changed, 5 insertions(+), 33 deletions(-)
> > 
> > diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
> > index 6cebad665565..aceacb822cab 100644
> > --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
> > +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
> > @@ -204,9 +204,9 @@ static snd_pcm_uframes_t snd_solo_pcm_pointer(struct snd_pcm_substream *ss)
> >  	return idx * G723_FRAMES_PER_PAGE;
> >  }
> >  
> > -static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
> > -				  unsigned long pos, void __user *dst,
> > -				  unsigned long count)
> > +static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel,
> > +			     unsigned long pos, struct iov_iter *dst,
> > +			     unsigned long count)
> >  {
> >  	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
> >  	struct solo_dev *solo_dev = solo_pcm->solo_dev;
> > @@ -223,35 +223,8 @@ static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
> >  		if (err)
> >  			return err;
> >  
> > -		if (copy_to_user(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES))
> > +		if (!copy_to_iter(solo_pcm->g723_buf, G723_PERIOD_BYTES, dst))
> >  			return -EFAULT;
> > -		dst += G723_PERIOD_BYTES;
> > -	}
> > -
> > -	return 0;
> > -}
> > -
> > -static int snd_solo_pcm_copy_kernel(struct snd_pcm_substream *ss, int channel,
> > -				    unsigned long pos, void *dst,
> > -				    unsigned long count)
> > -{
> > -	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
> > -	struct solo_dev *solo_dev = solo_pcm->solo_dev;
> > -	int err, i;
> > -
> > -	for (i = 0; i < (count / G723_FRAMES_PER_PAGE); i++) {
> > -		int page = (pos / G723_FRAMES_PER_PAGE) + i;
> > -
> > -		err = solo_p2m_dma_t(solo_dev, 0, solo_pcm->g723_dma,
> > -				     SOLO_G723_EXT_ADDR(solo_dev) +
> > -				     (page * G723_PERIOD_BLOCK) +
> > -				     (ss->number * G723_PERIOD_BYTES),
> > -				     G723_PERIOD_BYTES, 0, 0);
> > -		if (err)
> > -			return err;
> > -
> > -		memcpy(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES);
> > -		dst += G723_PERIOD_BYTES;
> >  	}
> >  
> >  	return 0;
> > @@ -263,8 +236,7 @@ static const struct snd_pcm_ops snd_solo_pcm_ops = {
> >  	.prepare = snd_solo_pcm_prepare,
> >  	.trigger = snd_solo_pcm_trigger,
> >  	.pointer = snd_solo_pcm_pointer,
> > -	.copy_user = snd_solo_pcm_copy_user,
> > -	.copy_kernel = snd_solo_pcm_copy_kernel,
> > +	.copy = snd_solo_pcm_copy,
> >  };
> >  
> >  static int snd_solo_capture_volume_info(struct snd_kcontrol *kcontrol,
> > -- 
> > 2.35.3
> > 
> 
> Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>

You meant Reviewed-by or Acked-by?  Signed-off-by is a tag used when
you carry a patch.


thanks,

Takashi

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

* Re: [PATCH 17/25] media: solo6x10: Convert to generic PCM copy ops
  2023-08-14 12:17     ` Takashi Iwai
@ 2023-08-14 12:26       ` Ismael Luceno
  0 siblings, 0 replies; 44+ messages in thread
From: Ismael Luceno @ 2023-08-14 12:26 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: alsa-devel, linux-kernel, Andrey Utkin, Mauro Carvalho Chehab,
	linux-media

On 14/Aug/2023 14:17, Takashi Iwai wrote:
> On Mon, 14 Aug 2023 14:15:18 +0200,
> Ismael Luceno wrote:
> > 
> > On 14/Aug/2023 13:55, Takashi Iwai wrote:
> > > This patch converts the solo6x10 driver code to use the new unified
> > > PCM copy callback.  It's a straightforward conversion from *_user() to
> > > *_iter() variants.  As copy_to_iter() updates the internal offest at
> > > each write, we can drop the dst counter update in the loop, too.
> > > 
> > > Note that copy_from/to_iter() returns the copied bytes, hence the
> > > error condition is inverted from copy_from/to_user().
> > > 
> > > Cc: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
> > > Cc: Anton Sviridenko <anton@corp.bluecherry.net>
> > > Cc: Andrey Utkin <andrey_utkin@fastmail.com>
> > > Cc: Ismael Luceno <ismael@iodev.co.uk>
> > > Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> > > Cc: linux-media@vger.kernel.org
> > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > ---
> > >  drivers/media/pci/solo6x10/solo6x10-g723.c | 38 +++-------------------
> > >  1 file changed, 5 insertions(+), 33 deletions(-)
> > > 
> > > diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
> > > index 6cebad665565..aceacb822cab 100644
> > > --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
> > > +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
> > > @@ -204,9 +204,9 @@ static snd_pcm_uframes_t snd_solo_pcm_pointer(struct snd_pcm_substream *ss)
> > >  	return idx * G723_FRAMES_PER_PAGE;
> > >  }
> > >  
> > > -static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
> > > -				  unsigned long pos, void __user *dst,
> > > -				  unsigned long count)
> > > +static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel,
> > > +			     unsigned long pos, struct iov_iter *dst,
> > > +			     unsigned long count)
> > >  {
> > >  	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
> > >  	struct solo_dev *solo_dev = solo_pcm->solo_dev;
> > > @@ -223,35 +223,8 @@ static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channel,
> > >  		if (err)
> > >  			return err;
> > >  
> > > -		if (copy_to_user(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES))
> > > +		if (!copy_to_iter(solo_pcm->g723_buf, G723_PERIOD_BYTES, dst))
> > >  			return -EFAULT;
> > > -		dst += G723_PERIOD_BYTES;
> > > -	}
> > > -
> > > -	return 0;
> > > -}
> > > -
> > > -static int snd_solo_pcm_copy_kernel(struct snd_pcm_substream *ss, int channel,
> > > -				    unsigned long pos, void *dst,
> > > -				    unsigned long count)
> > > -{
> > > -	struct solo_snd_pcm *solo_pcm = snd_pcm_substream_chip(ss);
> > > -	struct solo_dev *solo_dev = solo_pcm->solo_dev;
> > > -	int err, i;
> > > -
> > > -	for (i = 0; i < (count / G723_FRAMES_PER_PAGE); i++) {
> > > -		int page = (pos / G723_FRAMES_PER_PAGE) + i;
> > > -
> > > -		err = solo_p2m_dma_t(solo_dev, 0, solo_pcm->g723_dma,
> > > -				     SOLO_G723_EXT_ADDR(solo_dev) +
> > > -				     (page * G723_PERIOD_BLOCK) +
> > > -				     (ss->number * G723_PERIOD_BYTES),
> > > -				     G723_PERIOD_BYTES, 0, 0);
> > > -		if (err)
> > > -			return err;
> > > -
> > > -		memcpy(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES);
> > > -		dst += G723_PERIOD_BYTES;
> > >  	}
> > >  
> > >  	return 0;
> > > @@ -263,8 +236,7 @@ static const struct snd_pcm_ops snd_solo_pcm_ops = {
> > >  	.prepare = snd_solo_pcm_prepare,
> > >  	.trigger = snd_solo_pcm_trigger,
> > >  	.pointer = snd_solo_pcm_pointer,
> > > -	.copy_user = snd_solo_pcm_copy_user,
> > > -	.copy_kernel = snd_solo_pcm_copy_kernel,
> > > +	.copy = snd_solo_pcm_copy,
> > >  };
> > >  
> > >  static int snd_solo_capture_volume_info(struct snd_kcontrol *kcontrol,
> > > -- 
> > > 2.35.3
> > > 
> > 
> > Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
> 
> You meant Reviewed-by or Acked-by?  Signed-off-by is a tag used when
> you carry a patch.
> 
> 
> thanks,
> 
> Takashi

Yes, sorry, I meant "Acked-by".

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

* Re: [PATCH 18/25] ASoC: component: Add generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 18/25] ASoC: component: Add " Takashi Iwai
@ 2023-08-14 12:59   ` Mark Brown
  2023-08-15 13:56   ` Andy Shevchenko
  1 sibling, 0 replies; 44+ messages in thread
From: Mark Brown @ 2023-08-14 12:59 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 313 bytes --]

On Mon, Aug 14, 2023 at 01:55:16PM +0200, Takashi Iwai wrote:
> For following the ALSA PCM core change, a new PCM copy ops is added
> toe ASoC component framework: snd_soc_component_driver receives the
> copy ops, and snd_soc_pcm_component_copy() helper is provided.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 19/25] ASoC: mediatek: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 19/25] ASoC: mediatek: Convert to " Takashi Iwai
@ 2023-08-14 13:00   ` Mark Brown
  2023-08-15 13:58   ` Andy Shevchenko
  1 sibling, 0 replies; 44+ messages in thread
From: Mark Brown @ 2023-08-14 13:00 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 407 bytes --]

On Mon, Aug 14, 2023 at 01:55:17PM +0200, Takashi Iwai wrote:
> This patch converts the mediatek BT SCO driver code to use the new
> unified PCM copy callback.  It's a straightforward conversion from
> *_user() to *_iter() variants.  As copy_form/to_iter() updates the
> internal offset at each read/write, we can drop the cur_*_idx counter
> in the loop, too.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 20/25] ASoC: qcom: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 20/25] ASoC: qcom: " Takashi Iwai
@ 2023-08-14 13:06   ` Mark Brown
  0 siblings, 0 replies; 44+ messages in thread
From: Mark Brown @ 2023-08-14 13:06 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: alsa-devel, linux-kernel, Srinivas Kandagatla, Banajit Goswami

[-- Attachment #1: Type: text/plain, Size: 410 bytes --]

On Mon, Aug 14, 2023 at 01:55:18PM +0200, Takashi Iwai wrote:
> This patch converts the qcom lpass driver code to use the new unified
> PCM copy callback.  It's a straightforward conversion from *_user() to
> *_iter() variants.
> 
> Note that copy_from/to_iter() returns the copied bytes, hence the
> error condition is inverted from copy_from/to_user().

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 21/25] ASoC: dmaengine: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 21/25] ASoC: dmaengine: " Takashi Iwai
@ 2023-08-14 13:18   ` Mark Brown
  2023-08-15 14:00   ` Andy Shevchenko
  1 sibling, 0 replies; 44+ messages in thread
From: Mark Brown @ 2023-08-14 13:18 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel, Lars-Peter Clausen

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

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.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 22/25] ASoC: dmaengine: Use iov_iter for process callback, too
  2023-08-14 11:55 ` [PATCH 22/25] ASoC: dmaengine: Use iov_iter for process callback, too Takashi Iwai
@ 2023-08-14 13:19   ` Mark Brown
  0 siblings, 0 replies; 44+ messages in thread
From: Mark Brown @ 2023-08-14 13:19 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: alsa-devel, linux-kernel, Lars-Peter Clausen, Claudiu Beznea,
	Olivier Moysan, Arnaud Pouliquen

[-- Attachment #1: Type: text/plain, Size: 458 bytes --]

On Mon, Aug 14, 2023 at 01:55:20PM +0200, Takashi Iwai wrote:
> Along with the conversion to PCM copy ops, use the iov_iter for the
> pointer to be passed to the dmaengine process callback, too.  It
> avoids the direct reference of iter_iov_addr(), and it can potentially
> help for the drivers to access memory properly (although both atmel
> and stm drivers don't use the given buffer address at all for now).

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops
  2023-08-14 11:55 ` [PATCH 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops Takashi Iwai
@ 2023-08-14 13:19   ` Mark Brown
  0 siblings, 0 replies; 44+ messages in thread
From: Mark Brown @ 2023-08-14 13:19 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 243 bytes --]

On Mon, Aug 14, 2023 at 01:55:22PM +0200, Takashi Iwai wrote:
> Now all ASoC users have been replaced to use the new PCM copy ops,
> let's drop the obsoleted copy_user ops and its helper function.

Reviewed-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem
  2023-08-14 11:55 ` [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem Takashi Iwai
@ 2023-08-15 13:51   ` Andy Shevchenko
  2023-08-15 13:54     ` Takashi Iwai
  0 siblings, 1 reply; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 13:51 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel

On Mon, Aug 14, 2023 at 01:55:01PM +0200, Takashi Iwai wrote:
> Add two more helpers for copying memory between iov_iter and iomem,
> which will be used by the new PCM copy ops in a few drivers.
> The existing helpers became wrappers of those now.
> 
> Note that copy_from/to_iter() returns the copied bytes, hence the
> error condition is inverted from copy_from/to_user().

...

> -	return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
> +	return !copy_to_iter((const void __force *)src, count, dst) ? -EFAULT : 0;

Inverted means, I believe, this

	return copy_to_iter((const void __force *)src, count, dst) == count ? 0 : -EFAULT;

as far as I understand the idea behind the copy_to_user() return value.

Ditto for other cases.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 04/25] ALSA: dummy: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 04/25] ALSA: dummy: Convert to generic PCM copy ops Takashi Iwai
@ 2023-08-15 13:52   ` Andy Shevchenko
  0 siblings, 0 replies; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 13:52 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel

On Mon, Aug 14, 2023 at 01:55:02PM +0200, Takashi Iwai wrote:
> This patch converts the dummy driver code to use the new unified PCM
> copy callback.  As dummy driver doesn't do anything in the callback,
> it's just a simple replacement.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem
  2023-08-15 13:51   ` Andy Shevchenko
@ 2023-08-15 13:54     ` Takashi Iwai
  0 siblings, 0 replies; 44+ messages in thread
From: Takashi Iwai @ 2023-08-15 13:54 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: alsa-devel, linux-kernel

On Tue, 15 Aug 2023 15:51:30 +0200,
Andy Shevchenko wrote:
> 
> On Mon, Aug 14, 2023 at 01:55:01PM +0200, Takashi Iwai wrote:
> > Add two more helpers for copying memory between iov_iter and iomem,
> > which will be used by the new PCM copy ops in a few drivers.
> > The existing helpers became wrappers of those now.
> > 
> > Note that copy_from/to_iter() returns the copied bytes, hence the
> > error condition is inverted from copy_from/to_user().
> 
> ...
> 
> > -	return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
> > +	return !copy_to_iter((const void __force *)src, count, dst) ? -EFAULT : 0;
> 
> Inverted means, I believe, this
> 
> 	return copy_to_iter((const void __force *)src, count, dst) == count ? 0 : -EFAULT;
> 
> as far as I understand the idea behind the copy_to_user() return value.
> 
> Ditto for other cases.

OK, this looks more correct.  I'll fix in v2.


thanks,

Takashi

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

* Re: [PATCH 08/25] ALSA: korg1212: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 08/25] ALSA: korg1212: " Takashi Iwai
@ 2023-08-15 13:55   ` Andy Shevchenko
  0 siblings, 0 replies; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 13:55 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel

On Mon, Aug 14, 2023 at 01:55:06PM +0200, Takashi Iwai wrote:
> This patch converts the korg1212 driver code to use the new unified
> PCM copy callback.  The open-coded conditional memory copies are
> replaced with simpler copy_from/to_iter() calls.
> 
> Note that copy_from/to_iter() returns the copied bytes, hence the
> error condition is inverted from copy_from/to_user().

...

> +		if (!copy_to_iter(src, size, dst))

	!= size ?


>  			return -EFAULT;

...

> +		if (!copy_from_iter(dst, size, src))
>  			return -EFAULT;

Ditto.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 18/25] ASoC: component: Add generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 18/25] ASoC: component: Add " Takashi Iwai
  2023-08-14 12:59   ` Mark Brown
@ 2023-08-15 13:56   ` Andy Shevchenko
  1 sibling, 0 replies; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 13:56 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel, Mark Brown

On Mon, Aug 14, 2023 at 01:55:16PM +0200, Takashi Iwai wrote:
> For following the ALSA PCM core change, a new PCM copy ops is added
> toe ASoC component framework: snd_soc_component_driver receives the
> copy ops, and snd_soc_pcm_component_copy() helper is provided.
> 
> This also fixes a long-standing potential bug where the ASoC driver
> covers only copy_user PCM callback and misses the copy from kernel
> pointers (such as OSS PCM layer), too.
> 
> As of this patch, the old copy_user is still kept, but it'll be
> dropped later after all drivers are converted.

...

> +	/* FIXME. it returns 1st copy now */
> +	for_each_rtd_components(rtd, i, component)
> +		if (component->driver->copy)
> +			return soc_component_ret(
> +				component,

This can be on the previous line.

> +				component->driver->copy(
> +					component, substream, channel,

Ditto for the component parameter.

> +					pos, buf, bytes));

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 19/25] ASoC: mediatek: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 19/25] ASoC: mediatek: Convert to " Takashi Iwai
  2023-08-14 13:00   ` Mark Brown
@ 2023-08-15 13:58   ` Andy Shevchenko
  1 sibling, 0 replies; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 13:58 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel, Mark Brown

On Mon, Aug 14, 2023 at 01:55:17PM +0200, Takashi Iwai wrote:
> This patch converts the mediatek BT SCO driver code to use the new
> unified PCM copy callback.  It's a straightforward conversion from
> *_user() to *_iter() variants.  As copy_form/to_iter() updates the
> internal offset at each read/write, we can drop the cur_*_idx counter
> in the loop, too.
> 
> Note that copy_from/to_iter() returns the copied bytes, hence the
> error condition is inverted from copy_from/to_user().

...

> +		if (!copy_to_iter(bt->rx_packet_buf + cur_read_idx,

!= read_size ?

> +				  read_size, buf)) {
>  			dev_warn(bt->dev, "%s(), copy_to_user fail\n",

Forgot to fix the message.

>  				 __func__);
>  			return -EFAULT;

...

> +		if (!copy_from_iter(bt->tx_packet_buf + cur_write_idx,
> +				    write_size, buf)) {
>  			dev_warn(bt->dev, "%s(), copy_from_user fail\n",
>  				 __func__);
>  			return -EFAULT;

As per above.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 21/25] ASoC: dmaengine: Convert to generic PCM copy ops
  2023-08-14 11:55 ` [PATCH 21/25] ASoC: dmaengine: " Takashi Iwai
  2023-08-14 13:18   ` Mark Brown
@ 2023-08-15 14:00   ` Andy Shevchenko
  2023-08-15 14:55     ` Takashi Iwai
  1 sibling, 1 reply; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 14:00 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel, Lars-Peter Clausen, Mark Brown

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.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH 21/25] ASoC: dmaengine: Convert to generic PCM copy ops
  2023-08-15 14:00   ` Andy Shevchenko
@ 2023-08-15 14:55     ` Takashi Iwai
  2023-08-15 15:45       ` Andy Shevchenko
  0 siblings, 1 reply; 44+ messages in thread
From: Takashi Iwai @ 2023-08-15 14:55 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: alsa-devel, linux-kernel, Lars-Peter Clausen, Mark Brown

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

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

* Re: [PATCH 21/25] ASoC: dmaengine: Convert to generic PCM copy ops
  2023-08-15 14:55     ` Takashi Iwai
@ 2023-08-15 15:45       ` Andy Shevchenko
  0 siblings, 0 replies; 44+ messages in thread
From: Andy Shevchenko @ 2023-08-15 15:45 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, linux-kernel, Lars-Peter Clausen, Mark Brown

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!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2023-08-15 15:46 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-14 11:54 [PATCH 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
2023-08-14 11:54 ` [PATCH 01/25] iov_iter: Export import_ubuf() Takashi Iwai
2023-08-14 11:55 ` [PATCH 02/25] ALSA: pcm: Add copy ops with iov_iter Takashi Iwai
2023-08-14 11:55 ` [PATCH 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem Takashi Iwai
2023-08-15 13:51   ` Andy Shevchenko
2023-08-15 13:54     ` Takashi Iwai
2023-08-14 11:55 ` [PATCH 04/25] ALSA: dummy: Convert to generic PCM copy ops Takashi Iwai
2023-08-15 13:52   ` Andy Shevchenko
2023-08-14 11:55 ` [PATCH 05/25] ALSA: gus: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 06/25] ALSA: emu8000: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 07/25] ALSA: es1938: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 08/25] ALSA: korg1212: " Takashi Iwai
2023-08-15 13:55   ` Andy Shevchenko
2023-08-14 11:55 ` [PATCH 09/25] ALSA: nm256: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 10/25] ALSA: rme32: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 11/25] ALSA: rme96: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 12/25] ALSA: hdsp: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 13/25] ALSA: rme9652: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 14/25] ALSA: sh: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 15/25] ALSA: xen: " Takashi Iwai
2023-08-14 11:55 ` [PATCH 16/25] ALSA: pcmtest: Update comment about " Takashi Iwai
2023-08-14 11:55 ` [PATCH 17/25] media: solo6x10: Convert to generic " Takashi Iwai
2023-08-14 12:15   ` Ismael Luceno
2023-08-14 12:17     ` Takashi Iwai
2023-08-14 12:26       ` Ismael Luceno
2023-08-14 11:55 ` [PATCH 18/25] ASoC: component: Add " Takashi Iwai
2023-08-14 12:59   ` Mark Brown
2023-08-15 13:56   ` Andy Shevchenko
2023-08-14 11:55 ` [PATCH 19/25] ASoC: mediatek: Convert to " Takashi Iwai
2023-08-14 13:00   ` Mark Brown
2023-08-15 13:58   ` Andy Shevchenko
2023-08-14 11:55 ` [PATCH 20/25] ASoC: qcom: " Takashi Iwai
2023-08-14 13:06   ` Mark Brown
2023-08-14 11:55 ` [PATCH 21/25] ASoC: dmaengine: " Takashi Iwai
2023-08-14 13:18   ` Mark Brown
2023-08-15 14:00   ` Andy Shevchenko
2023-08-15 14:55     ` Takashi Iwai
2023-08-15 15:45       ` Andy Shevchenko
2023-08-14 11:55 ` [PATCH 22/25] ASoC: dmaengine: Use iov_iter for process callback, too Takashi Iwai
2023-08-14 13:19   ` Mark Brown
2023-08-14 11:55 ` [PATCH 23/25] ALSA: doc: Update description for the new PCM copy ops Takashi Iwai
2023-08-14 11:55 ` [PATCH 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops Takashi Iwai
2023-08-14 13:19   ` Mark Brown
2023-08-14 11:55 ` [PATCH 25/25] ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox