From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
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, hverkuil@kernel.org,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] staging: vc04_services: bcm2835-camera: avoid -Wformat-truncation
Date: Sat, 30 Aug 2025 23:29:23 +0200 [thread overview]
Message-ID: <20250830212923.GB16364@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20250830173850.323897-3-nogunix@gmail.com>
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
next prev parent reply other threads:[~2025-08-30 21:29 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
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 [this message]
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=20250830212923.GB16364@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--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=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
all inboxes | Powered by JetHome®