* [PATCH] ALSA: timer: Simplify snd_timer_user_tselect()
@ 2026-11-20 11:52 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-11-20 11:52 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Norbert Szetei, bui duc phuc,
Kees Cook, Cássio Gabriel, Maoyi Xie
Cc: Thorsten Blum, Takashi Iwai, linux-sound
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 <blum@kernel.org>
---
sound/core/timer.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 905176bf6948..f977eea64f31 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -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;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 11:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 11:52 [PATCH] ALSA: timer: Simplify snd_timer_user_tselect() Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox