summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Blum <thorsten.blum@linux.dev>2026-01-25 18:51:56 +0300
committerTakashi Iwai <tiwai@suse.de>2026-01-27 11:58:37 +0300
commitbfa514c4613b39e536d4a9dfbcb8eb8e68776343 (patch)
treee82504f453492b8c03805ef3fde4ef1ba19269cc
parentcc051fbd7f40226cc407558bc97c5099513e8657 (diff)
downloadlinux-bfa514c4613b39e536d4a9dfbcb8eb8e68776343.tar.xz
ALSA: jack: Improve string handling in jack_kctl_name_gen
If appending " Jack" is not necessary, replace snprintf("%s", ...) with the faster strscpy(). Additionally, rename 'need_cat' to the clearer 'append_suf', use local variables for the suffix and its length, remove the confusing comment, compare strncmp() to 0, and use 'size_t' for the 'size' function parameter. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Link: https://patch.msgid.link/20260125155159.98720-1-thorsten.blum@linux.dev Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/core/ctljack.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c
index 709b1a9c2caa..6b6ab34fbde8 100644
--- a/sound/core/ctljack.c
+++ b/sound/core/ctljack.c
@@ -7,6 +7,7 @@
#include <linux/kernel.h>
#include <linux/export.h>
+#include <linux/string.h>
#include <sound/core.h>
#include <sound/control.h>
@@ -46,17 +47,20 @@ static int get_available_index(struct snd_card *card, const char *name)
return sid.index;
}
-static void jack_kctl_name_gen(char *name, const char *src_name, int size)
+static void jack_kctl_name_gen(char *name, const char *src_name, size_t size)
{
size_t count = strlen(src_name);
- bool need_cat = true;
+ const char *suf = " Jack";
+ size_t suf_len = strlen(suf);
+ bool append_suf = true;
- /* remove redundant " Jack" from src_name */
- if (count >= 5)
- need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false;
-
- snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name);
+ if (count >= suf_len)
+ append_suf = strncmp(&src_name[count - suf_len], suf, suf_len) != 0;
+ if (append_suf)
+ snprintf(name, size, "%s%s", src_name, suf);
+ else
+ strscpy(name, src_name, size);
}
struct snd_kcontrol *