The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: audio: add size enforcement to name prefix in topology
@ 2026-11-18  3:44 Garrett Floyd
  2026-11-18  9:00 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Garrett Floyd @ 2026-11-18  3:44 UTC (permalink / raw)
  To: Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, Garrett Floyd

Copied name for certain functions can be 32 bytes, but destination is
also only 32 bytes. After adding prefix, name may be truncated, causing
compiler warning from -Wformat-truncation.

drivers/staging/greybus/audio_topology.c: In function ‘gbaudio_tplg_process_kcontrols’:
drivers/staging/greybus/audio_topology.c:1172:65: warning: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size between 17 and 27 [-Wformat-truncation=]
drivers/staging/greybus/audio_topology.c: In function ‘gbaudio_tplg_create_widget’:
drivers/staging/greybus/audio_topology.c:1090:51: warning: ‘%s’ directive output may be truncated writing up to 31 bytes into a region of size between 17 and 27 [-Wformat-truncation=]

Modify the temporary name buffer size in
gbaudio_tplg_process_kcontrols() and gbaudio_tplg_create_widget() to
match the maximum size that can be copied back to the name field. Add
a bitmask to the ID put in the prefix to assure values 0-63 as stated
in "include/linux/greybus/greybus_protocols.h" for struct
gb_audio_control. The compiler expects 2 digits max when bitmask is
presnet, allowing one more character in controls compared to widgets.

For the widgets, name may only be 24 bytes max for IDs 0-255. For the
controls, name may only be 25 bytes max for IDs 0-63. IDs with less
digits get truncated regardless.

Compile tested only.

Signed-off-by: Garrett Floyd <garrettfloyd345@hotmail.com>
---
 drivers/staging/greybus/audio_topology.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 76146f91cddc..1a6ef1bdf170 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -1018,7 +1018,8 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
 	struct gb_audio_control *curr;
 	struct gbaudio_control *control, *_control;
 	size_t size;
-	char temp_name[NAME_SIZE];
+	/* Subtracting 3 for "GB ", 3 for ID 0-255, 1 for final space */
+	char temp_name[NAME_SIZE - 7];
 
 	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);
+	snprintf(w->name, sizeof(w->name), "GB %u %s", module->dev_id,
+		 temp_name);
 
 	switch (w->type) {
 	case snd_soc_dapm_spk:
@@ -1143,7 +1145,8 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module,
 	struct gb_audio_control *curr;
 	struct gbaudio_control *control, *_control;
 	size_t size;
-	char temp_name[NAME_SIZE];
+	/* Subtracting 3 for "GB ", 2 for ID 0-63, 1 for final space */
+	char temp_name[NAME_SIZE - 6];
 
 	size = sizeof(struct snd_kcontrol_new) * module->num_controls;
 	dapm_kctls = devm_kzalloc(module->dev, size, GFP_KERNEL);
@@ -1169,7 +1172,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,
+		/* bitmask enforces values between 0-63 */
+		snprintf(curr->name, sizeof(curr->name), "GB %u %s", module->dev_id & 0x3f,
 			 temp_name);
 		control->name = curr->name;
 		if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) {
-- 
2.55.0


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

end of thread, other threads:[~2026-11-18  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  3:44 [PATCH] staging: greybus: audio: add size enforcement to name prefix in topology Garrett Floyd
2026-11-18  9:00 ` Dan Carpenter

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