ALSA: korg1212: Convert to generic PCM copy ops

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.

Link: https://lore.kernel.org/r/20230815190136.8987-9-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2023-08-15 21:01:19 +02:00
parent 07ee02a2e1
commit 49aa6ed94c

View File

@ -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, static int snd_korg1212_copy_to(struct snd_pcm_substream *substream,
void __user *dst, int pos, int count, struct iov_iter *dst, int pos, int count)
bool in_kernel)
{ {
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); 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 K1212_DEBUG_LEVEL > 0
if ( (void *) src < (void *) korg1212->recordDataBufsPtr || if ( (void *) src < (void *) korg1212->recordDataBufsPtr ||
(void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) { (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; return -EFAULT;
} }
#endif #endif
if (in_kernel) if (copy_to_iter(src, size, dst) != size)
memcpy((__force void *)dst, src, size);
else if (copy_to_user(dst, src, size))
return -EFAULT; return -EFAULT;
src++; src++;
dst += size;
} }
return 0; return 0;
} }
static int snd_korg1212_copy_from(struct snd_pcm_substream *substream, static int snd_korg1212_copy_from(struct snd_pcm_substream *substream,
void __user *src, int pos, int count, struct iov_iter *src, int pos, int count)
bool in_kernel)
{ {
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); 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 K1212_DEBUG_LEVEL > 0
if ( (void *) dst < (void *) korg1212->playDataBufsPtr || if ( (void *) dst < (void *) korg1212->playDataBufsPtr ||
(void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { (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; return -EFAULT;
} }
#endif #endif
if (in_kernel) if (copy_from_iter(dst, size, src) != size)
memcpy(dst, (__force void *)src, size);
else if (copy_from_user(dst, src, size))
return -EFAULT; return -EFAULT;
dst++; dst++;
src += size;
} }
return 0; 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, static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream,
int channel, unsigned long pos, 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); return snd_korg1212_copy_from(substream, src, pos, count);
}
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);
} }
static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, 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, static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream,
int channel, unsigned long pos, 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); return snd_korg1212_copy_to(substream, dst, pos, count);
}
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);
} }
static const struct snd_pcm_ops snd_korg1212_playback_ops = { 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, .prepare = snd_korg1212_prepare,
.trigger = snd_korg1212_trigger, .trigger = snd_korg1212_trigger,
.pointer = snd_korg1212_playback_pointer, .pointer = snd_korg1212_playback_pointer,
.copy_user = snd_korg1212_playback_copy, .copy = snd_korg1212_playback_copy,
.copy_kernel = snd_korg1212_playback_copy_kernel,
.fill_silence = snd_korg1212_playback_silence, .fill_silence = snd_korg1212_playback_silence,
}; };
@ -1704,8 +1679,7 @@ static const struct snd_pcm_ops snd_korg1212_capture_ops = {
.prepare = snd_korg1212_prepare, .prepare = snd_korg1212_prepare,
.trigger = snd_korg1212_trigger, .trigger = snd_korg1212_trigger,
.pointer = snd_korg1212_capture_pointer, .pointer = snd_korg1212_capture_pointer,
.copy_user = snd_korg1212_capture_copy, .copy = snd_korg1212_capture_copy,
.copy_kernel = snd_korg1212_capture_copy_kernel,
}; };
/* /*