* [PATCH] staging: greybus: audio: fix snprintf truncation errors
@ 2026-06-05 19:28 Rhys Tumelty
2026-06-06 7:08 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Rhys Tumelty @ 2026-06-05 19:28 UTC (permalink / raw)
To: gregkh
Cc: Rhys Tumelty, Vaibhav Agarwal, Mark Greer, Johan Hovold,
Alex Elder, greybus-dev, linux-staging, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] staging: greybus: audio: fix snprintf truncation errors
2026-06-05 19:28 [PATCH] staging: greybus: audio: fix snprintf truncation errors Rhys Tumelty
@ 2026-06-06 7:08 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-06-06 7:08 UTC (permalink / raw)
To: Rhys Tumelty
Cc: gregkh, Vaibhav Agarwal, Mark Greer, Johan Hovold, Alex Elder,
greybus-dev, linux-staging, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-06 7:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-05 19:28 [PATCH] staging: greybus: audio: fix snprintf truncation errors Rhys Tumelty
2026-06-06 7:08 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox