mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: ac97: Use snprintf() in snd_ac97_get_name()
@ 2026-10-22  8:14 Thorsten Blum
  0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-10-22  8:14 UTC (permalink / raw)
  To: Jaroslav Kysela, Takashi Iwai, Hemanth Selam
  Cc: Thorsten Blum, Takashi Iwai, linux-sound, linux-kernel

To prepare for removing strlcat() from the kernel [1], use snprintf() to
append the codec name and the optional revision. Also use snprintf() for
the unknown vendor fallback.

Fix some formatting while at it.

No functional change.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 sound/pci/ac97/ac97_codec.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 0bb65be021d9..73deee7061a1 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -1832,36 +1832,39 @@ 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;
+	size_t len;
 
-	sprintf(name, "0x%x %c%c%c", id,
-		printable(id >> 24),
-		printable(id >> 16),
-		printable(id >> 8));
 	pid = look_for_codec_id(snd_ac97_codec_id_vendors, id);
-	if (! pid)
+	if (!pid) {
+		snprintf(name, maxlen, "0x%x %c%c%c", id,
+			 printable(id >> 24),
+			 printable(id >> 16),
+			 printable(id >> 8));
 		return;
+	}
 
 	strscpy(name, pid->name, maxlen);
 	if (ac97 && pid->patch) {
 		if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
-		    (! modem && ! (pid->flags & AC97_MODEM_PATCH)))
+		    (!modem && !(pid->flags & AC97_MODEM_PATCH)))
 			pid->patch(ac97);
-	} 
+	}
 
+	len = strnlen(name, maxlen);
 	pid = look_for_codec_id(snd_ac97_codec_ids, id);
 	if (pid) {
-		strlcat(name, " ", maxlen);
-		strlcat(name, pid->name, maxlen);
 		if (pid->mask != 0xffffffff)
-			sprintf(name + strlen(name), " rev %u", id & ~pid->mask);
+			snprintf(name + len, maxlen - len, " %s rev %u",
+				 pid->name, id & ~pid->mask);
+		else
+			snprintf(name + len, maxlen - len, " %s", pid->name);
 		if (ac97 && pid->patch) {
 			if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
-			    (! modem && ! (pid->flags & AC97_MODEM_PATCH)))
+			    (!modem && !(pid->flags & AC97_MODEM_PATCH)))
 				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);
 	}
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-22  8:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22  8:14 [PATCH] ALSA: ac97: Use snprintf() in snd_ac97_get_name() Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®