[PATCH 2/7] ALSA: ac97: replace strlcat() with scnprintf()
From: Mahad Ibrahim
Date: Fri Aug 07 2026 - 07:47:44 EST
At this point name holds the vendor name written by the earlier
strscpy(). A space and then the codec name were appended with two
strlcat() calls. The else branch below already took its own offset
with strlen() before calling snprintf().
Take that offset once, before the branch, and use it for both. The
two appends become a single scnprintf() writing " %s" at the offset,
and the else branch uses the same variable instead of computing its
own.
The bytes written and the point at which the result is truncated are
unchanged.
Signed-off-by: Mahad Ibrahim <mahad.ibrahim.dev@xxxxxxxxx>
---
sound/pci/ac97/ac97_codec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 0bb65be021d9..dfd712ef0c63 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -1832,6 +1832,7 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name,
size_t maxlen, int modem)
{
const struct ac97_codec_id *pid;
+ int len;
sprintf(name, "0x%x %c%c%c", id,
printable(id >> 24),
@@ -1849,9 +1850,9 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name,
}
pid = look_for_codec_id(snd_ac97_codec_ids, id);
+ len = strlen(name);
if (pid) {
- strlcat(name, " ", maxlen);
- strlcat(name, pid->name, maxlen);
+ scnprintf(name + len, maxlen - len, " %s", pid->name);
if (pid->mask != 0xffffffff)
sprintf(name + strlen(name), " rev %u", id & ~pid->mask);
if (ac97 && pid->patch) {
@@ -1860,8 +1861,7 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name,
pid->patch(ac97);
}
} else {
- int l = strlen(name);
- snprintf(name + l, maxlen - l, " id %x", id & 0xff);
+ snprintf(name + len, maxlen - len, " id %x", id & 0xff);
}
}
--
2.54.0