[PATCH 5/7] ALSA: usb-audio: replace strlcat() with append_ctl_name()
From: Mahad Ibrahim
Date: Fri Aug 07 2026 - 07:45:25 EST
append_ctl_name() appended to kctl->id.name with strlcat() and
returned its result. build_connector_control() open-coded the same
append for the " Jack" suffix rather than calling the helper.
Take the length of the existing name and write the suffix at that
offset with strscpy(). The return value is rebuilt as the offset plus
the length of the appended string, which is what strlcat() returns:
the length the caller asked for, whether or not it fit. No caller
currently uses it. While here, call append_ctl_name() for the " Jack"
suffix instead of repeating the append inline.
The name that ends up in kctl->id.name is unchanged, and so is the
value returned to callers.
Signed-off-by: Mahad Ibrahim <mahad.ibrahim.dev@xxxxxxxxx>
---
sound/usb/mixer.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 703c118f9d4e..77335bc89aa0 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1748,7 +1748,11 @@ const struct snd_kcontrol_new *snd_usb_feature_unit_ctl = &usb_feature_unit_ctl;
*/
static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
{
- return strlcat(kctl->id.name, str, sizeof(kctl->id.name));
+ size_t len = strlen(kctl->id.name);
+
+ strscpy(kctl->id.name + len, str, sizeof(kctl->id.name) - len);
+
+ return len + strlen(str);
}
/*
@@ -2116,7 +2120,7 @@ static void build_connector_control(struct usb_mixer_interface *mixer,
}
if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)))
- strlcat(kctl->id.name, " Jack", sizeof(kctl->id.name));
+ append_ctl_name(kctl, " Jack");
else
get_connector_control_name(mixer, term, is_input, kctl->id.name,
sizeof(kctl->id.name));
--
2.54.0