* [PATCH 0/2] staging: fix W=1 format-truncation warnings
@ 2025-08-30 17:38 Masaharu Noguchi
2025-08-30 17:38 ` [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation Masaharu Noguchi
2025-08-30 17:38 ` [PATCH 2/2] staging: vc04_services: bcm2835-camera: " Masaharu Noguchi
0 siblings, 2 replies; 7+ messages in thread
From: Masaharu Noguchi @ 2025-08-30 17:38 UTC (permalink / raw)
To: gregkh, linux-staging
Cc: vaibhav.sr, mgreer, johan, elder, greybus-dev, florian.fainelli,
rjui, sbranden, bcm-kernel-feedback-list, dave.stevenson,
laurent.pinchart, hverkuil, linux-rpi-kernel, linux-arm-kernel,
linux-kernel, Masaharu Noguchi
- This series fixes -Wformat-truncation warnings in staging drivers found with W=1 builds:
- greybus: prefix device id to widget/control names safely
- vc04_services/bcm2835-camera: compose V4L2 bus_info safely
Both changes use scnprintf() for the prefix and strscpy() for the remainder. No functional change
intended.
Masaharu Noguchi (2):
staging: greybus: audio_topology: avoid -Wformat-truncation
staging: vc04_services: bcm2835-camera: avoid -Wformat-truncation
drivers/staging/greybus/audio_topology.c | 11 ++++++-----
.../vc04_services/bcm2835-camera/bcm2835-camera.c | 5 +++--
2 files changed, 9 insertions(+), 7 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation
2025-08-30 17:38 [PATCH 0/2] staging: fix W=1 format-truncation warnings Masaharu Noguchi
@ 2025-08-30 17:38 ` Masaharu Noguchi
2025-09-01 11:33 ` Dan Carpenter
2025-08-30 17:38 ` [PATCH 2/2] staging: vc04_services: bcm2835-camera: " Masaharu Noguchi
1 sibling, 1 reply; 7+ messages in thread
From: Masaharu Noguchi @ 2025-08-30 17:38 UTC (permalink / raw)
To: gregkh, linux-staging
Cc: vaibhav.sr, mgreer, johan, elder, greybus-dev, florian.fainelli,
rjui, sbranden, bcm-kernel-feedback-list, dave.stevenson,
laurent.pinchart, hverkuil, linux-rpi-kernel, linux-arm-kernel,
linux-kernel, Masaharu Noguchi
- Fix -Wformat-truncation when prefixing device id to widget/control
names.
- Write the prefix with scnprintf() and copy the remainder with
strscpy().
- This avoids potential truncation and satisfies W=1 builds in
drivers/staging/greybus.
Signed-off-by: Masaharu Noguchi <nogunix@gmail.com>
---
drivers/staging/greybus/audio_topology.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 6ca938dca4fd..5bf8b5e29dd8 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -1013,7 +1013,7 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
struct snd_soc_dapm_widget *dw,
struct gb_audio_widget *w, int *w_size)
{
- int i, ret, csize;
+ int i, ret, csize, n;
struct snd_kcontrol_new *widget_kctls;
struct gb_audio_control *curr;
struct gbaudio_control *control, *_control;
@@ -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);
+ n = scnprintf(w->name, sizeof(w->name), "GB %d ", module->dev_id);
+ strscpy(w->name + n, temp_name, sizeof(w->name) - n);
switch (w->type) {
case snd_soc_dapm_spk:
@@ -1138,7 +1139,7 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module,
struct gb_audio_control *controls)
{
- int i, csize, ret;
+ int i, csize, ret, n;
struct snd_kcontrol_new *dapm_kctls;
struct gb_audio_control *curr;
struct gbaudio_control *control, *_control;
@@ -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);
+ n = scnprintf(curr->name, sizeof(curr->name), "GB %d ", module->dev_id);
+ strscpy(curr->name + n, temp_name, sizeof(curr->name) - n);
control->name = curr->name;
if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) {
struct gb_audio_enumerated *gbenum =
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] staging: vc04_services: bcm2835-camera: avoid -Wformat-truncation
2025-08-30 17:38 [PATCH 0/2] staging: fix W=1 format-truncation warnings Masaharu Noguchi
2025-08-30 17:38 ` [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation Masaharu Noguchi
@ 2025-08-30 17:38 ` Masaharu Noguchi
2025-08-30 21:29 ` Laurent Pinchart
1 sibling, 1 reply; 7+ messages in thread
From: Masaharu Noguchi @ 2025-08-30 17:38 UTC (permalink / raw)
To: gregkh, linux-staging
Cc: vaibhav.sr, mgreer, johan, elder, greybus-dev, florian.fainelli,
rjui, sbranden, bcm-kernel-feedback-list, dave.stevenson,
laurent.pinchart, hverkuil, linux-rpi-kernel, linux-arm-kernel,
linux-kernel, Masaharu Noguchi
- Fix -Wformat-truncation in vidioc_querycap() when composing bus_info.
- Use scnprintf() for the prefix and strscpy() for the remainder.
Signed-off-by: Masaharu Noguchi <nogunix@gmail.com>
---
.../staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index fa7ea4ca4c36..c2788659af12 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -874,13 +874,14 @@ static int vidioc_querycap(struct file *file, void *priv,
struct bcm2835_mmal_dev *dev = video_drvdata(file);
u32 major;
u32 minor;
+ int n;
vchiq_mmal_version(dev->instance, &major, &minor);
strscpy(cap->driver, "bcm2835 mmal", sizeof(cap->driver));
snprintf((char *)cap->card, sizeof(cap->card), "mmal service %d.%d", major, minor);
-
- snprintf((char *)cap->bus_info, sizeof(cap->bus_info), "platform:%s", dev->v4l2_dev.name);
+ n = scnprintf((char *)cap->bus_info, sizeof(cap->bus_info), "platform:");
+ strscpy((char *)cap->bus_info + n, dev->v4l2_dev.name, sizeof(cap->bus_info) - n);
return 0;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] staging: vc04_services: bcm2835-camera: avoid -Wformat-truncation
2025-08-30 17:38 ` [PATCH 2/2] staging: vc04_services: bcm2835-camera: " Masaharu Noguchi
@ 2025-08-30 21:29 ` Laurent Pinchart
2025-09-01 12:30 ` Masaharu Noguchi
0 siblings, 1 reply; 7+ messages in thread
From: Laurent Pinchart @ 2025-08-30 21:29 UTC (permalink / raw)
To: Masaharu Noguchi
Cc: gregkh, linux-staging, vaibhav.sr, mgreer, johan, elder,
greybus-dev, florian.fainelli, rjui, sbranden,
bcm-kernel-feedback-list, dave.stevenson, hverkuil,
linux-rpi-kernel, linux-arm-kernel, linux-kernel
On Sun, Aug 31, 2025 at 02:38:50AM +0900, Masaharu Noguchi wrote:
> - Fix -Wformat-truncation in vidioc_querycap() when composing bus_info.
> - Use scnprintf() for the prefix and strscpy() for the remainder.
>
> Signed-off-by: Masaharu Noguchi <nogunix@gmail.com>
> ---
> .../staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> index fa7ea4ca4c36..c2788659af12 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> @@ -874,13 +874,14 @@ static int vidioc_querycap(struct file *file, void *priv,
> struct bcm2835_mmal_dev *dev = video_drvdata(file);
> u32 major;
> u32 minor;
> + int n;
>
> vchiq_mmal_version(dev->instance, &major, &minor);
>
> strscpy(cap->driver, "bcm2835 mmal", sizeof(cap->driver));
> snprintf((char *)cap->card, sizeof(cap->card), "mmal service %d.%d", major, minor);
> -
> - snprintf((char *)cap->bus_info, sizeof(cap->bus_info), "platform:%s", dev->v4l2_dev.name);
> + n = scnprintf((char *)cap->bus_info, sizeof(cap->bus_info), "platform:");
> + strscpy((char *)cap->bus_info + n, dev->v4l2_dev.name, sizeof(cap->bus_info) - n);
The fact that we need such a complicated construct is a sign that
there's something wrong in our APIs. The above code is too complicated
for what it does, making it less readable, more difficult to maintain,
and more bug-prone. I don't know if we need yet another sprintf variant
in the kernel, or something else, but this doens't seem to be what we
need.
> return 0;
> }
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation
2025-08-30 17:38 ` [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation Masaharu Noguchi
@ 2025-09-01 11:33 ` Dan Carpenter
2025-09-01 12:42 ` Masaharu Noguchi
0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2025-09-01 11:33 UTC (permalink / raw)
To: Masaharu Noguchi
Cc: gregkh, linux-staging, vaibhav.sr, mgreer, johan, elder,
greybus-dev, florian.fainelli, rjui, sbranden,
bcm-kernel-feedback-list, dave.stevenson, laurent.pinchart,
hverkuil, linux-rpi-kernel, linux-arm-kernel, linux-kernel
On Sun, Aug 31, 2025 at 02:38:49AM +0900, Masaharu Noguchi wrote:
> - Fix -Wformat-truncation when prefixing device id to widget/control
> names.
> - Write the prefix with scnprintf() and copy the remainder with
> strscpy().
> - This avoids potential truncation and satisfies W=1 builds in
> drivers/staging/greybus.
>
> Signed-off-by: Masaharu Noguchi <nogunix@gmail.com>
> ---
> drivers/staging/greybus/audio_topology.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
> index 6ca938dca4fd..5bf8b5e29dd8 100644
> --- a/drivers/staging/greybus/audio_topology.c
> +++ b/drivers/staging/greybus/audio_topology.c
> @@ -1013,7 +1013,7 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
> struct snd_soc_dapm_widget *dw,
> struct gb_audio_widget *w, int *w_size)
> {
> - int i, ret, csize;
> + int i, ret, csize, n;
> struct snd_kcontrol_new *widget_kctls;
> struct gb_audio_control *curr;
> struct gbaudio_control *control, *_control;
> @@ -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);
> + n = scnprintf(w->name, sizeof(w->name), "GB %d ", module->dev_id);
> + strscpy(w->name + n, temp_name, sizeof(w->name) - n);
The strscpy() doesn't make sense. If the string doesn't fit then you
can't *force* it to fit with strscpy(). :P
Here we're taking a buffer w->name and adding a prefix at the beginning
of the exact same buffer. Obviously the result is going to be larger.
The W=1 warning doesn't add any new information...
I feel like these W=1 warnings about string truncation are rarely useful.
These limits are not normally thought out that deeply. Poeople just say,
"This is probably something like a company name. Let's say that a
company name is probably 48 characters long." But really very few company
names are that long. It's just a rough estimate.
And really it's not the worst thing if these strings are truncated. Kernel
messages are mostly error messages. We'll still be able to debug the crash
even if the last couple characters in a really long name are chopped off.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] staging: vc04_services: bcm2835-camera: avoid -Wformat-truncation
2025-08-30 21:29 ` Laurent Pinchart
@ 2025-09-01 12:30 ` Masaharu Noguchi
0 siblings, 0 replies; 7+ messages in thread
From: Masaharu Noguchi @ 2025-09-01 12:30 UTC (permalink / raw)
To: Laurent Pinchart
Cc: gregkh, linux-staging, vaibhav.sr, mgreer, johan, elder,
greybus-dev, florian.fainelli, rjui, sbranden,
bcm-kernel-feedback-list, dave.stevenson, hverkuil,
linux-rpi-kernel, linux-arm-kernel, linux-kernel
Thanks for the explanation. I understand now that this patch is not needed.
Please drop it.
Best regards,
Masaharu Noguchi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation
2025-09-01 11:33 ` Dan Carpenter
@ 2025-09-01 12:42 ` Masaharu Noguchi
0 siblings, 0 replies; 7+ messages in thread
From: Masaharu Noguchi @ 2025-09-01 12:42 UTC (permalink / raw)
To: Dan Carpenter
Cc: gregkh, linux-staging, vaibhav.sr, mgreer, johan, elder,
greybus-dev, florian.fainelli, rjui, sbranden,
bcm-kernel-feedback-list, dave.stevenson, laurent.pinchart,
hverkuil, linux-rpi-kernel, linux-arm-kernel, linux-kernel
Thanks for the detailed explanation. I understand your point regarding W=1 warnings and string truncation.
Based on this, I will drop the previous patch and leave the code as is.
Best regards,
Masaharu Noguchi
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-09-01 16:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-30 17:38 [PATCH 0/2] staging: fix W=1 format-truncation warnings Masaharu Noguchi
2025-08-30 17:38 ` [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation Masaharu Noguchi
2025-09-01 11:33 ` Dan Carpenter
2025-09-01 12:42 ` Masaharu Noguchi
2025-08-30 17:38 ` [PATCH 2/2] staging: vc04_services: bcm2835-camera: " Masaharu Noguchi
2025-08-30 21:29 ` Laurent Pinchart
2025-09-01 12:30 ` Masaharu Noguchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).