mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eduard Zateev <hackerowskiy@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Vaibhav Agarwal <vaibhav.sr@gmail.com>,
	Mark Greer <mgreer@animalcreek.com>,
	Johan Hovold <johan@kernel.org>, Alex Elder <elder@kernel.org>,
	greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Eduard Zateev <hackerowskiy@gmail.com>
Subject: [PATCH] staging: greybus: avoid snprintf truncation in audio topology
Date: Wed, 23 Sep 2026 04:34:05 +0200	[thread overview]
Message-ID: <20260923023405.41700-1-hackerowskiy@gmail.com> (raw)

Building with W=1 reports format truncation warnings when prefixing
the Greybus device id to widget and control names.

The destination buffers are NAME_SIZE bytes, while the copied topology
names may already take most of that space. Split the operation into
writing the prefix first and then copying the remaining name into the
space left in the destination buffer.

This avoids the -Wformat-truncation warnings while preserving bounded
string handling.

Signed-off-by: Eduard Zateev <hackerowskiy@gmail.com>
---
 drivers/staging/greybus/audio_topology.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 76146f91cddc..72a71fd38312 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -1019,6 +1019,7 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
 	struct gbaudio_control *control, *_control;
 	size_t size;
 	char temp_name[NAME_SIZE];
+	int name_len;
 
 	ret = gbaudio_validate_kcontrol_count(w);
 	if (ret) {
@@ -1087,7 +1088,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);
+	name_len = scnprintf(w->name, sizeof(w->name), "GB %d ", module->dev_id);
+	strscpy(w->name + name_len, temp_name, sizeof(w->name) - name_len);
 
 	switch (w->type) {
 	case snd_soc_dapm_spk:
@@ -1144,6 +1146,7 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module,
 	struct gbaudio_control *control, *_control;
 	size_t size;
 	char temp_name[NAME_SIZE];
+	int name_len;
 
 	size = sizeof(struct snd_kcontrol_new) * module->num_controls;
 	dapm_kctls = devm_kzalloc(module->dev, size, GFP_KERNEL);
@@ -1169,8 +1172,10 @@ 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);
+		name_len = scnprintf(curr->name, sizeof(curr->name), "GB %d ",
+				     module->dev_id);
+		strscpy(curr->name + name_len, temp_name,
+			sizeof(curr->name) - name_len);
 		control->name = curr->name;
 		if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) {
 			struct gb_audio_enumerated *gbenum =
-- 
2.55.0


             reply	other threads:[~2026-09-23  2:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  2:34 Eduard Zateev [this message]
2026-09-23  8:01 ` Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260923023405.41700-1-hackerowskiy@gmail.com \
    --to=hackerowskiy@gmail.com \
    --cc=elder@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mgreer@animalcreek.com \
    --cc=vaibhav.sr@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®