drivers/staging/greybus/audio_topology.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
change snprintf() to scnprintf() in both gbaudio_tplg_create_widget()
and gbaudio_tplg_process_kcontrols() to prevent potential string
truncation warnings when prefixing the device id to the control name.
Signed-off-by: Rhys Tumelty <rhys@tumelty.co.uk>
---
drivers/staging/greybus/audio_topology.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 76146f91c..b19febabb 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -1087,7 +1087,7 @@ 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 %s", module->dev_id, temp_name);
switch (w->type) {
case snd_soc_dapm_spk:
@@ -1169,8 +1169,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 %s", module->dev_id,
+ temp_name);
control->name = curr->name;
if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) {
struct gb_audio_enumerated *gbenum =
--
2.54.0
On Fri, Jun 05, 2026 at 08:28:56PM +0100, Rhys Tumelty wrote: > change snprintf() to scnprintf() in both gbaudio_tplg_create_widget() > and gbaudio_tplg_process_kcontrols() to prevent potential string > truncation warnings when prefixing the device id to the control name. > This commit message is unclear. My understanding is that snprintf() is complaining that the array size of w->name is less than the array size of "GB %d %s" plus the array size of temp_name. This is a W=1 complaint. I hate this warning. We use snprintf() to deliberately truncate the string. Now it's complaining that the string might be truncated. Oh no! What we want to happen might happen! This is the same argument that people used to block safer alternatives to strcpy() into glibc because "it's still going to truncate the string and that's equally bad as a root exploit!" First of all, the string is not going to be truncated. (I haven't looked). Second of all, this warning makes no sense in the kernel. I have never once had a bug which I failed to debug because the last two bytes in a string were truncated. There has never been a scenario where I was looking through dmesg and snprintf() truncated some bytes so I couldn't guess what I was looking at. So your solution is to change it to scnprintf() which is kernel only and GCC doesn't know about it... I bet GCC eventually learns about scnprintf() and it eventually becomes a warning again. A better solution is to disable that annoying check. regards, dan carpenter
© 2016 - 2026 Red Hat, Inc.