Skip to contentSkip to conversation

ALSA: usb-audio: Use strscpy() in append_ctl_name()

PATCH In review Thorsten Blum 2 participants 2 messages Oct 21 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb-audio: Use strscpy() in append_ctl_name()

To prepare for removing strlcat() from the kernel [1], use strscpy() instead with the current name length as the append offset. Change append_ctl_name() to return void since no caller uses its return value.

Use append_ctl_name() to append " Jack" in build_connector_control().

No functional change.

---
 sound/usb/mixer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
sound/usb/mixer.c +5 -3
index ecaa8bc08d7c..0320a3e8af92 100644
@@ -1720,9 +1720,11 @@ const struct snd_kcontrol_new *snd_usb_feature_unit_ctl = &usb_feature_unit_ctl;
 /*
  * build a feature control
  */
-static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
+static void 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);
 }
 
 /*
@@ -2090,7 +2092,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));
#1 lore raw
Quoted 11 lines · Thorsten Blum

To prepare for removing strlcat() from the kernel [1], use strscpy() instead with the current name length as the append offset. Change append_ctl_name() to return void since no caller uses its return value.

Use append_ctl_name() to append " Jack" in build_connector_control().

No functional change.

Applied now. Thanks.

Takashi