ALSA: timer: Simplify snd_timer_user_tselect()
PATCH 1/1 ALSA: timer: Simplify snd_timer_user_tselect()
Return errors directly and remove the now-redundant goto statements and the __err label. Also drop the unnecessary err = 0 initialization.
While the current unbounded sprintf() works correctly, replace it with scnprintf() to bound the formatted string to the str buffer.
No functional change.
Signed-off-by Thorsten Blum <[email protected]>
--- sound/core/timer.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
sound/core/timer.c +7 -11
@@ -1802,7 +1802,7 @@ static int snd_timer_user_tselect(struct file *file,struct snd_timer_user *tu;struct snd_timer_select tselect;char str[32 ]; -int err =0 ; +int err; tu = file->private_data;if (tu->timeri) {
@@ -1810,18 +1810,15 @@ static int snd_timer_user_tselect(struct file *file,snd_timer_instance_free (tu->timeri); tu->timeri =NULL ; } -if (copy_from_user (&tselect, _tselect,sizeof (tselect))) { - err = -EFAULT ; - goto __err; - } -sprintf (str,"application %i" , current->pid); +if (copy_from_user (&tselect, _tselect,sizeof (tselect))) +return -EFAULT ; + +scnprintf (str,sizeof (str),"application %i" , current->pid);if (tselect.id.dev_class !=SNDRV_TIMER_CLASS_SLAVE ) tselect.id.dev_sclass =SNDRV_TIMER_SCLASS_APPLICATION ; tu->timeri =snd_timer_instance_new (str); -if (!tu->timeri) { - err = -ENOMEM ; - goto __err; - } +if (!tu->timeri) +return -ENOMEM ; tu->timeri->flags |=SNDRV_TIMER_IFLG_FAST ; tu->timeri->callback = tu->tread
@@ -1836,7 +1833,6 @@ static int snd_timer_user_tselect(struct file *file, tu->timeri =NULL ; } - __err:return err; }
Takashi Iwai
AppliedQuoted 10 lines · Thorsten Blum
Return errors directly and remove the now-redundant goto statements and the
__errlabel. Also drop the unnecessary err = 0 initialization.While the current unbounded
sprintf()works correctly, replace it withscnprintf()to bound the formatted string to the str buffer.No functional change.
Signed-off-by Thorsten Blum <[email protected]>
Applied to for-next branch. Thanks.
Takashi