mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Cc: linux-kernel@vger.kernel.org, Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v2 08/25] ALSA: korg1212: Convert to generic PCM copy ops
Date: Tue, 15 Aug 2023 21:01:19 +0200	[thread overview]
Message-ID: <20230815190136.8987-9-tiwai@suse.de> (raw)
In-Reply-To: <20230815190136.8987-1-tiwai@suse.de>

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 adjusted accordingly.

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..5c2cac201a28 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) != size)
 			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) != size)
 			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


  parent reply	other threads:[~2023-08-15 19:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 19:01 [PATCH v2 00/25] ALSA: Generic PCM copy ops using iov_iter Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 01/25] iov_iter: Export import_ubuf() Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 02/25] ALSA: pcm: Add copy ops with iov_iter Takashi Iwai
2023-09-02  5:30   ` Al Viro
2023-09-02  6:00     ` Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 04/25] ALSA: dummy: Convert to generic PCM copy ops Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 05/25] ALSA: gus: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 06/25] ALSA: emu8000: " Takashi Iwai
2023-09-02  5:36   ` Al Viro
2023-09-02  6:01     ` Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 07/25] ALSA: es1938: " Takashi Iwai
2023-08-15 19:01 ` Takashi Iwai [this message]
2023-08-15 19:01 ` [PATCH v2 09/25] ALSA: nm256: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 10/25] ALSA: rme32: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 11/25] ALSA: rme96: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 12/25] ALSA: hdsp: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 13/25] ALSA: rme9652: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 14/25] ALSA: sh: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 15/25] ALSA: xen: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 16/25] ALSA: pcmtest: Update comment about " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 17/25] media: solo6x10: Convert to generic " Takashi Iwai
2023-08-18  7:48   ` Hans Verkuil
2023-08-15 19:01 ` [PATCH v2 18/25] ASoC: component: Add " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 19/25] ASoC: mediatek: Convert to " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 20/25] ASoC: qcom: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 21/25] ASoC: dmaengine: " Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 22/25] ASoC: dmaengine: Use iov_iter for process callback, too Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 23/25] ALSA: doc: Update description for the new PCM copy ops Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops Takashi Iwai
2023-08-15 19:01 ` [PATCH v2 25/25] ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230815190136.8987-9-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®