linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Masaharu Noguchi <nogunix@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
	vaibhav.sr@gmail.com, mgreer@animalcreek.com, johan@kernel.org,
	elder@kernel.org, greybus-dev@lists.linaro.org,
	florian.fainelli@broadcom.com, rjui@broadcom.com,
	sbranden@broadcom.com, bcm-kernel-feedback-list@broadcom.com,
	dave.stevenson@raspberrypi.com,
	laurent.pinchart@ideasonboard.com, hverkuil@kernel.org,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] staging: greybus: audio_topology: avoid -Wformat-truncation
Date: Mon, 1 Sep 2025 14:33:47 +0300	[thread overview]
Message-ID: <aLWEm2sQpmoNYLAC@stanley.mountain> (raw)
In-Reply-To: <20250830173850.323897-2-nogunix@gmail.com>

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


  reply	other threads:[~2025-09-01 11:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=aLWEm2sQpmoNYLAC@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=elder@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=hverkuil@kernel.org \
    --cc=johan@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mgreer@animalcreek.com \
    --cc=nogunix@gmail.com \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.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;
as well as URLs for NNTP newsgroup(s).