mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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
			
			
This commit is contained in:
		
							parent
							
								
									c72fad73ba
								
							
						
					
					
						commit
						8629eea901
					
				
					 1 changed files with 18 additions and 20 deletions
				
			
		| 
						 | 
					@ -3096,45 +3096,43 @@ static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
 | 
				
			||||||
			    struct snd_pcm_sync_ptr __user *_sync_ptr)
 | 
								    struct snd_pcm_sync_ptr __user *_sync_ptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct snd_pcm_runtime *runtime = substream->runtime;
 | 
						struct snd_pcm_runtime *runtime = substream->runtime;
 | 
				
			||||||
	struct snd_pcm_sync_ptr sync_ptr;
 | 
					 | 
				
			||||||
	volatile struct snd_pcm_mmap_status *status;
 | 
						volatile struct snd_pcm_mmap_status *status;
 | 
				
			||||||
	volatile struct snd_pcm_mmap_control *control;
 | 
						volatile struct snd_pcm_mmap_control *control;
 | 
				
			||||||
 | 
						u32 sflags;
 | 
				
			||||||
 | 
						struct snd_pcm_mmap_control scontrol;
 | 
				
			||||||
 | 
						struct snd_pcm_mmap_status sstatus;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(&sync_ptr, 0, sizeof(sync_ptr));
 | 
						if (snd_pcm_sync_ptr_get_user(sflags, scontrol, _sync_ptr))
 | 
				
			||||||
	if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags)))
 | 
					 | 
				
			||||||
		return -EFAULT;
 | 
							return -EFAULT;
 | 
				
			||||||
	if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), sizeof(struct snd_pcm_mmap_control)))
 | 
					 | 
				
			||||||
		return -EFAULT;	
 | 
					 | 
				
			||||||
	status = runtime->status;
 | 
						status = runtime->status;
 | 
				
			||||||
	control = runtime->control;
 | 
						control = runtime->control;
 | 
				
			||||||
	if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
 | 
						if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
 | 
				
			||||||
		err = snd_pcm_hwsync(substream);
 | 
							err = snd_pcm_hwsync(substream);
 | 
				
			||||||
		if (err < 0)
 | 
							if (err < 0)
 | 
				
			||||||
			return err;
 | 
								return err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	scoped_guard(pcm_stream_lock_irq, substream) {
 | 
						scoped_guard(pcm_stream_lock_irq, substream) {
 | 
				
			||||||
		if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) {
 | 
							if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) {
 | 
				
			||||||
			err = pcm_lib_apply_appl_ptr(substream,
 | 
								err = pcm_lib_apply_appl_ptr(substream, scontrol.appl_ptr);
 | 
				
			||||||
						     sync_ptr.c.control.appl_ptr);
 | 
					 | 
				
			||||||
			if (err < 0)
 | 
								if (err < 0)
 | 
				
			||||||
				return err;
 | 
									return err;
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			sync_ptr.c.control.appl_ptr = control->appl_ptr;
 | 
								scontrol.appl_ptr = control->appl_ptr;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
 | 
							if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN))
 | 
				
			||||||
			control->avail_min = sync_ptr.c.control.avail_min;
 | 
								control->avail_min = scontrol.avail_min;
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			sync_ptr.c.control.avail_min = control->avail_min;
 | 
								scontrol.avail_min = control->avail_min;
 | 
				
			||||||
		sync_ptr.s.status.state = status->state;
 | 
							sstatus.state = status->state;
 | 
				
			||||||
		sync_ptr.s.status.hw_ptr = status->hw_ptr;
 | 
							sstatus.hw_ptr = status->hw_ptr;
 | 
				
			||||||
		sync_ptr.s.status.tstamp = status->tstamp;
 | 
							sstatus.tstamp = status->tstamp;
 | 
				
			||||||
		sync_ptr.s.status.suspended_state = status->suspended_state;
 | 
							sstatus.suspended_state = status->suspended_state;
 | 
				
			||||||
		sync_ptr.s.status.audio_tstamp = status->audio_tstamp;
 | 
							sstatus.audio_tstamp = status->audio_tstamp;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL))
 | 
						if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL))
 | 
				
			||||||
		snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
 | 
							snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
 | 
				
			||||||
	if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr)))
 | 
						if (snd_pcm_sync_ptr_put_user(sstatus, scontrol, _sync_ptr))
 | 
				
			||||||
		return -EFAULT;
 | 
							return -EFAULT;
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue