public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: audio: avoid snprintf truncation warnings
@ 2025-12-29 11:26 Sun Jian
  2025-12-29 14:17 ` David Laight
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sun Jian @ 2025-12-29 11:26 UTC (permalink / raw)
  To: Vaibhav Agarwal
  Cc: Mark Greer, Alex Elder, Greg Kroah-Hartman, greybus-dev,
	linux-staging, linux-kernel, Sun Jian

W=1 reports possible truncation when formatting widget and control names
using snprintf() with a %s argument and fixed-size buffers. Build the
prefixed names using scnprintf() plus strlcat() instead, so truncation,
if any, is handled by the string helpers rather than during printf
formatting.

No functional change intended.

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 drivers/staging/greybus/audio_topology.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 76146f91cddc..4293ab899390 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -1087,7 +1087,8 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
 
 	/* Prefix dev_id to widget control_name */
 	strscpy(temp_name, w->name, sizeof(temp_name));
-	snprintf(w->name, sizeof(w->name), "GB %d %s", module->dev_id, temp_name);
+	scnprintf(w->name, sizeof(w->name), "GB %d ", module->dev_id);
+	strlcat(w->name, temp_name, sizeof(w->name));
 
 	switch (w->type) {
 	case snd_soc_dapm_spk:
@@ -1169,8 +1170,8 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module,
 		control->id = curr->id;
 		/* Prefix dev_id to widget_name */
 		strscpy(temp_name, curr->name, sizeof(temp_name));
-		snprintf(curr->name, sizeof(curr->name), "GB %d %s", module->dev_id,
-			 temp_name);
+		scnprintf(curr->name, sizeof(curr->name), "GB %d ", module->dev_id);
+		strlcat(curr->name, temp_name, sizeof(curr->name));
 		control->name = curr->name;
 		if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) {
 			struct gb_audio_enumerated *gbenum =
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-01-05 15:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-29 11:26 [PATCH] staging: greybus: audio: avoid snprintf truncation warnings Sun Jian
2025-12-29 14:17 ` David Laight
2025-12-29 16:13 ` [PATCH v2] " Sun Jian
2025-12-29 16:52   ` Greg Kroah-Hartman
2025-12-30  1:29 ` [PATCH v3] " Sun Jian
2025-12-30  7:40   ` Greg Kroah-Hartman
2025-12-30 22:20     ` David Laight
2026-01-05 11:55   ` Dan Carpenter
2026-01-05 15:37     ` sun jian

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