Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: "Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Norbert Szetei" <norbert@doyensec.com>,
	"bui duc phuc" <phucduc.bui@gmail.com>,
	"Kees Cook" <kees+treewide@kernel.org>,
	"Cássio Gabriel" <cassiogabrielcontato@gmail.com>,
	"Maoyi Xie" <maoyixie.tju@gmail.com>
Cc: Thorsten Blum <blum@kernel.org>, Takashi Iwai <tiwai@suse.de>,
	linux-sound@vger.kernel.org
Subject: [PATCH] ALSA: timer: Simplify snd_timer_user_tselect()
Date: Fri, 20 Nov 2026 12:52:06 +0100	[thread overview]
Message-ID: <20261120115207.810114-2-blum@kernel.org> (raw)

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;
 }
 

                 reply	other threads:[~2026-11-20 11:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120115207.810114-2-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=cassiogabrielcontato@gmail.com \
    --cc=kees+treewide@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=maoyixie.tju@gmail.com \
    --cc=norbert@doyensec.com \
    --cc=perex@perex.cz \
    --cc=phucduc.bui@gmail.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox