ALSA: Generic PCM copy ops using iov_iter
Subsystems (16)
v2 cover ALSA: Generic PCM copy ops using iov_iter
Hi,
this is a v2 patch set for cleaning up the PCM copy ops using iov_iter to deal with kernel / user-space pointers consistently.
v1->v2:
* The error condition checks of copy_to/from_iter() are changed to be more strictly
* Put Acked and Reviewed tags
* The indents in the patch in dmaengine was slightly changed
v1:
https://lore.kernel.org/r/[email protected]
Takashi
===
===
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 | 39 ++------ 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 | 27 ++---- sound/soc/qcom/lpass-platform.c | 13 +-- sound/soc/soc-component.c | 16 ++-- 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 | 56 +++-------- 29 files changed, 269 insertions(+), 587 deletions(-)
Signature · 1 line
2.35.3
PATCH v2 1/25 iov_iter: Export import_ubuf()
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.
--- lib/iov_iter.c | 1 + 1 file changed, 1 insertion(+)
lib/iov_iter.c +1 -0
@@ -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
Signature · 1 line
2.35.3
PATCH v2 2/25 ALSA: pcm: Add copy ops with iov_iter
In reply to Takashi Iwaiiov_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.
--- include/sound/pcm.h | 3 ++ sound/core/pcm_lib.c | 111 ++++++++++++++++++++++++---------------- sound/core/pcm_native.c | 2 +- 3 files changed, 71 insertions(+), 45 deletions(-)
include/sound/pcm.h +3 -0
@@ -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);
sound/core/pcm_lib.c +67 -44
202 lines not on this page · raw message
sound/core/pcm_native.c +1 -1
@@ -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 )
Signature · 1 line
2.35.3
Al Viro
maintainerRe: [PATCH v2 02/25] ALSA: pcm: Add copy ops with iov_iter
sound/core/pcm_lib.c static void *get_dma_ptr(struct snd_pcm_runtime *runtime, · line 1996
Quoted 4 lines · Takashi Iwai
sound/core/pcm_lib.c +2
-2-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))
The former is "if not everything got copied", the latter - "if nothing got copied"; the same goes for other places like that.
Re: [PATCH v2 02/25] ALSA: pcm: Add copy ops with iov_iter
Quoted 10 lines · Al Viro
sound/core/pcm_lib.c static void *get_dma_ptr(struct snd_pcm_runtime *runtime, · line 1996
Quoted 4 lines · Takashi Iwai
sound/core/pcm_lib.c +2
-2-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))The former is "if not everything got copied", the latter - "if nothing got copied"; the same goes for other places like that.
Thanks, yes, this should be
if (copy_from_iter(...) != bytes)
Other places have been already corrected in v2 patchset, but this place was overseen. Will fix it.
Takashi
PATCH v2 3/25 ALSA: core: Add memory copy helpers between iov_iter and iomem
In reply to Takashi IwaiAdd 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 adjusted accordingly.
--- include/sound/pcm.h | 5 ++++ sound/core/memory.c | 56 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 8 deletions(-)
include/sound/pcm.h +5 -0
@@ -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 ];
sound/core/memory.c +48 -8
102 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH v2 4/25 ALSA: dummy: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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.
--- sound/drivers/dummy.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
sound/drivers/dummy.c +2 -10
@@ -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, };
Signature · 1 line
2.35.3
PATCH v2 5/25 ALSA: gus: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/isa/gus/gus_pcm.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-)
sound/isa/gus/gus_pcm.c +3 -20
@@ -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) != len)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, };
Signature · 1 line
2.35.3
PATCH v2 6/25 ALSA: emu8000: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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.
--- sound/isa/sb/emu8000_pcm.c | 74 +++++++++----------------------------- 1 file changed, 16 insertions(+), 58 deletions(-)
sound/isa/sb/emu8000_pcm.c +16 -58
@@ -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) != 2) \ + 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, };
Signature · 1 line
2.35.3
Al Viro
maintainerRe: [PATCH v2 06/25] ALSA: emu8000: Convert to generic PCM copy ops
sound/isa/sb/emu8000_pcm.c do { \ · line 417
Quoted 2 lines · Takashi Iwai
sound/isa/sb/emu8000_pcm.c +2
-0+else if (copy_from_iter (&sval,2 , iter) !=2 ) \ +return -EFAULT ; \
copy_from_iter_full()?
Quoted 15 lines
sound/isa/sb/emu8000_pcm.c +1
-10-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 ; }
sound/isa/sb/emu8000_pcm.c static int emu8k_pcm_silence(struct snd_pcm_substream *subs, · line 459
Quoted 5 lines
sound/isa/sb/emu8000_pcm.c +1
-1@@ -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);
USER_SOCKPTR?
Re: [PATCH v2 06/25] ALSA: emu8000: Convert to generic PCM copy ops
Quoted 6 lines · Al Viro
sound/isa/sb/emu8000_pcm.c do { \ · line 417
Quoted 2 lines · Takashi Iwai
sound/isa/sb/emu8000_pcm.c +2
-0+else if (copy_from_iter (&sval,2 , iter) !=2 ) \ +return -EFAULT ; \
copy_from_iter_full()?
It's a place in an internal copy to carry each 16bit word, so this is intentional.
Quoted 14 lines
Quoted 14 lines
sound/isa/sb/emu8000_pcm.c +1
-10-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 ; }
Quoted 8 lines
sound/isa/sb/emu8000_pcm.c static int emu8k_pcm_silence(struct snd_pcm_substream *subs, · line 459
Quoted 6 lines
sound/isa/sb/emu8000_pcm.c +1
-1@@ -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);
USER_SOCKPTR?
Oh, obviously a leftover :-<
It's a code in #if-0 block, and compiler didn't catch it.
Takashi
PATCH v2 7/25 ALSA: es1938: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/pci/es1938.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-)
sound/pci/es1938.c +5 -25
@@ -824,7 +824,7 @@ static snd_pcm_uframes_t snd_es1938_playback_pointer(struct snd_pcm_substream *sstatic 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) != count)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) != count -1 )return -EFAULT ; -if (put_user (runtime->dma_area[0 ], - ((unsigned char __user *)dst) + count -1 )) +if (copy_to_iter (runtime->dma_area,1 , dst) !=1 )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)
Signature · 1 line
2.35.3
PATCH v2 8/25 ALSA: korg1212: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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.
--- sound/pci/korg1212/korg1212.c | 50 +++++++++-------------------------- 1 file changed, 12 insertions(+), 38 deletions(-)
sound/pci/korg1212/korg1212.c +12 -38
@@ -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, };/*
Signature · 1 line
2.35.3
PATCH v2 9/25 ALSA: nm256: Convert to generic PCM copy ops
In reply to Takashi IwaiThis patch converts the nm256 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants.
--- sound/pci/nm256/nm256.c | 42 ++++++----------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-)
sound/pci/nm256/nm256.c +6 -36
@@ -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, };
Signature · 1 line
2.35.3
PATCH v2 10/25 ALSA: rme32: Convert to generic PCM copy ops
In reply to Takashi IwaiThis patch converts the rme32 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants.
--- sound/pci/rme32.c | 50 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 39 deletions(-)
sound/pci/rme32.c +11 -39
@@ -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, };
Signature · 1 line
2.35.3
PATCH v2 11/25 ALSA: rme96: Convert to generic PCM copy ops
In reply to Takashi IwaiThis patch converts the rme96 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants.
--- sound/pci/rme96.c | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-)
sound/pci/rme96.c +8 -34
@@ -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, };
Signature · 1 line
2.35.3
PATCH v2 12/25 ALSA: hdsp: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/pci/rme9652/hdsp.c | 42 ++++++---------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-)
sound/pci/rme9652/hdsp.c +6 -36
@@ -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) != count)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) != count)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)
Signature · 1 line
2.35.3
PATCH v2 13/25 ALSA: rme9652: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/pci/rme9652/rme9652.c | 46 +++++-------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-)
sound/pci/rme9652/rme9652.c +6 -40
@@ -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) != count)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) != count)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,
Signature · 1 line
2.35.3
PATCH v2 14/25 ALSA: sh: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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.
--- sound/sh/sh_dac_audio.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-)
sound/sh/sh_dac_audio.c +3 -22
@@ -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, };
Signature · 1 line
2.35.3
PATCH v2 15/25 ALSA: xen: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/xen/xen_snd_front_alsa.c | 56 +++++++--------------------------- 1 file changed, 11 insertions(+), 45 deletions(-)
sound/xen/xen_snd_front_alsa.c +11 -45
@@ -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) != count)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,26 +631,8 @@ 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) ? - -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); - +if (copy_to_iter (stream->buffer + pos, count, dst) != count) +return -EFAULT ;return 0 ; }
@@ -697,8 +665,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 +677,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,
Signature · 1 line
2.35.3
PATCH v2 16/25 ALSA: pcmtest: Update comment about PCM copy ops
In reply to Takashi IwaiJust an update of a comment mentioning the old PCM callbacks to correct to the new PCM copy ops.
--- sound/drivers/pcmtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/drivers/pcmtest.c +1 -1
@@ -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'.
Signature · 1 line
2.35.3
PATCH v2 17/25 media: solo6x10: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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_to_iter() returns the copied bytes, hence the error condition is adjusted accordingly.
--- drivers/media/pci/solo6x10/solo6x10-g723.c | 39 ++++------------------ 1 file changed, 6 insertions(+), 33 deletions(-)
drivers/media/pci/solo6x10/solo6x10-g723.c +6 -33
@@ -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,9 @@ 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) != +G723_PERIOD_BYTES )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 +237,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,
Signature · 1 line
2.35.3
Re: [PATCH v2 17/25] media: solo6x10: Convert to generic PCM copy ops
Quoted 9 lines · Takashi Iwai
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. Ascopy_to_iter()updates the internal offest at each write, we can drop the dst counter update in the loop, too.Note that
copy_to_iter()returns the copied bytes, hence the error condition is adjusted accordingly.Acked-by Ismael Luceno <[email protected]>
Regards,
Hans
Quoted 75 lines
Cc Bluecherry Maintainers <[email protected]>Cc Anton Sviridenko <[email protected]>Cc Andrey Utkin <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Signed-off-by Takashi Iwai <[email protected]>--- drivers/media/pci/solo6x10/solo6x10-g723.c | 39 ++++------------------ 1 file changed, 6 insertions(+), 33 deletions(-)drivers/media/pci/solo6x10/solo6x10-g723.c +6
-33@@ -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,9 @@ 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) != +G723_PERIOD_BYTES )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 +237,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,
PATCH v2 18/25 ASoC: component: Add generic PCM copy ops
In reply to Takashi IwaiFor 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.
--- include/sound/soc-component.h | 7 +++++++ sound/soc/soc-component.c | 18 ++++++++++++++++++ sound/soc/soc-pcm.c | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-)
include/sound/soc-component.h +7 -0
@@ -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,
sound/soc/soc-component.c +18 -0
@@ -1052,6 +1052,24 @@ 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)
sound/soc/soc-pcm.c +3 -1
@@ -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;
Signature · 1 line
2.35.3
PATCH v2 19/25 ASoC: mediatek: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/soc/mediatek/common/mtk-btcvsd.c | 27 ++++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-)
sound/soc/mediatek/common/mtk-btcvsd.c +10 -17
@@ -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,10 +742,9 @@ 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)) { -dev_warn (bt->dev,"%s(), copy_to_user fail\n" , +if (copy_to_iter (bt->rx_packet_buf + cur_read_idx, + read_size, buf) != read_size) { +dev_warn (bt->dev,"%s(), copy_to_iter 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,11 +831,9 @@ 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)) { -dev_warn (bt->dev,"%s(), copy_from_user fail\n" , +if (copy_from_iter (bt->tx_packet_buf + cur_write_idx, + write_size, buf) != write_size) { +dev_warn (bt->dev,"%s(), copy_from_iter 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)
Signature · 1 line
2.35.3
PATCH v2 20/25 ASoC: qcom: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/soc/qcom/lpass-platform.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
sound/soc/qcom/lpass-platform.c +7 -6
@@ -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) != bytes) 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) != bytes) 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, };
Signature · 1 line
2.35.3
PATCH v2 21/25 ASoC: dmaengine: Convert to generic PCM copy ops
In reply to Takashi IwaiThis 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 adjusted accordingly.
--- sound/soc/soc-generic-dmaengine-pcm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
sound/soc/soc-generic-dmaengine-pcm.c +9 -8
@@ -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) != bytes)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) != bytes)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, };
Signature · 1 line
2.35.3
PATCH v2 22/25 ASoC: dmaengine: Use iov_iter for process callback, too
In reply to Takashi IwaiAlong 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).
--- 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(-)
include/sound/dmaengine_pcm.h +1 -1
@@ -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 ];
sound/soc/atmel/mchp-pdmc.c +1 -1
@@ -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 +
sound/soc/soc-generic-dmaengine-pcm.c +2 -3
@@ -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) != bytes)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; }
sound/soc/stm/stm32_sai_sub.c +1 -1
@@ -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);
Signature · 1 line
2.35.3
PATCH v2 23/25 ALSA: doc: Update description for the new PCM copy ops
In reply to Takashi IwaiUpdate 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.
--- .../kernel-api/writing-an-alsa-driver.rst | 58 ++++++------------- 1 file changed, 19 insertions(+), 39 deletions(-)
Documentation/sound/kernel-api/writing-an-alsa-driver.rst +19 -39
@@ -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
Signature · 1 line
2.35.3
PATCH v2 24/25 ASoC: pcm: Drop obsoleted PCM copy_user ops
In reply to Takashi IwaiNow 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.
--- include/sound/soc-component.h | 7 ------- sound/soc/soc-component.c | 20 -------------------- sound/soc/soc-pcm.c | 2 -- 3 files changed, 29 deletions(-)
include/sound/soc-component.h +0 -7
@@ -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);
sound/soc/soc-component.c +0 -20
@@ -1070,26 +1070,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) {
sound/soc/soc-pcm.c +0 -2
@@ -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)
Signature · 1 line
2.35.3
PATCH v2 25/25 ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops
In reply to Takashi IwaiFinally all users have been converted to the new PCM copy ops, let's drop the obsoleted copy_kernel and copy_user ops completely.
--- include/sound/pcm.h | 5 ----- sound/core/pcm_lib.c | 18 +----------------- sound/core/pcm_native.c | 2 +- 3 files changed, 2 insertions(+), 23 deletions(-)
include/sound/pcm.h +0 -5
@@ -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);
sound/core/pcm_lib.c +1 -17
@@ -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;
sound/core/pcm_native.c +1 -1
@@ -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 )
Signature · 1 line
2.35.3