Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Thorsten Blum and committed by
Takashi Iwai
bfa514c4 cc051fbd

+11 -7
+11 -7
sound/core/ctljack.c
··· 7 7 8 8 #include <linux/kernel.h> 9 9 #include <linux/export.h> 10 + #include <linux/string.h> 10 11 #include <sound/core.h> 11 12 #include <sound/control.h> 12 13 ··· 47 46 return sid.index; 48 47 } 49 48 50 - static void jack_kctl_name_gen(char *name, const char *src_name, int size) 49 + static void jack_kctl_name_gen(char *name, const char *src_name, size_t size) 51 50 { 52 51 size_t count = strlen(src_name); 53 - bool need_cat = true; 52 + const char *suf = " Jack"; 53 + size_t suf_len = strlen(suf); 54 + bool append_suf = true; 54 55 55 - /* remove redundant " Jack" from src_name */ 56 - if (count >= 5) 57 - need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false; 56 + if (count >= suf_len) 57 + append_suf = strncmp(&src_name[count - suf_len], suf, suf_len) != 0; 58 58 59 - snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name); 60 - 59 + if (append_suf) 60 + snprintf(name, size, "%s%s", src_name, suf); 61 + else 62 + strscpy(name, src_name, size); 61 63 } 62 64 63 65 struct snd_kcontrol *