Skip to contentSkip to conversation

ALSA: timer: Simplify snd_timer_user_tselect()

PATCH Applied Thorsten Blum 2 participants 2 messages Nov 20 Sound

lore
Share & tools
lore
#0 lore raw

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.

---
 sound/core/timer.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
sound/core/timer.c +7 -11
index 905176bf6948..f977eea64f31 100644
@@ -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;
 }
 
Applied
#1 lore raw
Quoted 10 lines · Thorsten Blum

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.

Applied to for-next branch. Thanks.

Takashi