Skip to content

Commit 8629eea

Browse files
chleroytiwai
authored andcommitted
ALSA: pcm: Convert snd_pcm_sync_ptr() to user_access_begin/user_access_end()
Now that snd_pcm_sync_ptr_get_user() and snd_pcm_sync_ptr_put_user() are converted to user_access_begin/user_access_end(), snd_pcm_sync_ptr_get_user() is more efficient than a raw get_user() followed by a copy_from_user(). And because copy_{to/from}_user() are generic functions focussed on transfer of big data blocks to/from user, snd_pcm_sync_ptr_put_user() is also more efficient for small amont of data. So use snd_pcm_sync_ptr_get_user() and snd_pcm_sync_ptr_put_user() in snd_pcm_sync_ptr() too. snd_pcm_ioctl_sync_ptr_buggy() is left as it is because the conversion wouldn't be straigh-forward due to the workaround it provides. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/6ce6bc4da498ea7ea2be5f279b374370b1613b13.1749883041.git.christophe.leroy@csgroup.eu
1 parent c72fad7 commit 8629eea

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

sound/core/pcm_native.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,45 +3096,43 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
30963096
struct snd_pcm_sync_ptr __user *_sync_ptr)
30973097
{
30983098
struct snd_pcm_runtime *runtime = substream->runtime;
3099-
struct snd_pcm_sync_ptr sync_ptr;
31003099
volatile struct snd_pcm_mmap_status *status;
31013100
volatile struct snd_pcm_mmap_control *control;
3101+
u32 sflags;
3102+
struct snd_pcm_mmap_control scontrol;
3103+
struct snd_pcm_mmap_status sstatus;
31023104
int err;
31033105

3104-
memset(&sync_ptr, 0, sizeof(sync_ptr));
3105-
if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags)))
3106+
if (snd_pcm_sync_ptr_get_user(sflags, scontrol, _sync_ptr))
31063107
return -EFAULT;
3107-
if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), sizeof(struct snd_pcm_mmap_control)))
3108-
return -EFAULT;
31093108
status = runtime->status;
31103109
control = runtime->control;
3111-
if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
3110+
if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
31123111
err = snd_pcm_hwsync(substream);
31133112
if (err < 0)
31143113
return err;
31153114
}
31163115
scoped_guard(pcm_stream_lock_irq, substream) {
3117-
if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) {
3118-
err = pcm_lib_apply_appl_ptr(substream,
3119-
sync_ptr.c.control.appl_ptr);
3116+
if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) {
3117+
err = pcm_lib_apply_appl_ptr(substream, scontrol.appl_ptr);
31203118
if (err < 0)
31213119
return err;
31223120
} else {
3123-
sync_ptr.c.control.appl_ptr = control->appl_ptr;
3121+
scontrol.appl_ptr = control->appl_ptr;
31243122
}
3125-
if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
3126-
control->avail_min = sync_ptr.c.control.avail_min;
3123+
if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
3124+
control->avail_min = scontrol.avail_min;
31273125
else
3128-
sync_ptr.c.control.avail_min = control->avail_min;
3129-
sync_ptr.s.status.state = status->state;
3130-
sync_ptr.s.status.hw_ptr = status->hw_ptr;
3131-
sync_ptr.s.status.tstamp = status->tstamp;
3132-
sync_ptr.s.status.suspended_state = status->suspended_state;
3133-
sync_ptr.s.status.audio_tstamp = status->audio_tstamp;
3126+
scontrol.avail_min = control->avail_min;
3127+
sstatus.state = status->state;
3128+
sstatus.hw_ptr = status->hw_ptr;
3129+
sstatus.tstamp = status->tstamp;
3130+
sstatus.suspended_state = status->suspended_state;
3131+
sstatus.audio_tstamp = status->audio_tstamp;
31343132
}
3135-
if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL))
3133+
if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
31363134
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
3137-
if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
3135+
if (snd_pcm_sync_ptr_put_user(sstatus, scontrol, _sync_ptr))
31383136
return -EFAULT;
31393137
return 0;
31403138
}

0 commit comments

Comments
 (0)