From: Jani Nikula <jani.nikula@intel.com>
To: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev,
nouveau@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
Philipp Zabel <p.zabel@pengutronix.de>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>
Subject: Re: [PATCH 3/4] drm/imx: fix -Wformat-truncation warning in imx_ldb_probe()
Date: Fri, 24 May 2024 12:04:56 +0300 [thread overview]
Message-ID: <87jzjjoa13.fsf@intel.com> (raw)
In-Reply-To: <Zk99m4i82XnQPeKQ@intel.com>
On Thu, 23 May 2024, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> On Thu, May 23, 2024 at 06:51:08PM +0300, Jani Nikula wrote:
>> Enabling -Wformat-truncation yields the following warning:
>>
>> ../drivers/gpu/drm/imx/ipuv3/imx-ldb.c: In function ‘imx_ldb_probe’:
>> ../drivers/gpu/drm/imx/ipuv3/imx-ldb.c:658:57: error: ‘_sel’ directive output may be truncated writing 4 bytes into a region of size between 3 and 13 [-Werror=format-truncation=]
>> 658 | snprintf(clkname, sizeof(clkname), "di%d_sel", i);
>> | ^~~~
>> ../drivers/gpu/drm/imx/ipuv3/imx-ldb.c:658:17: note: ‘snprintf’ output between 8 and 18 bytes into a destination of size 16
>> 658 | snprintf(clkname, sizeof(clkname), "di%d_sel", i);
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> If only the compiler could count to three...
I did not try, but apparently using %hhd would hide the issue too:
snprintf(clkname, sizeof(clkname), "di%hhd_sel", i);
BR,
Jani.
>
>>
>> Silence the warning by checking the snprintf() return value.
>>
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>>
>> ---
>>
>> Cc: Philipp Zabel <p.zabel@pengutronix.de>
>> Cc: Shawn Guo <shawnguo@kernel.org>
>> Cc: Sascha Hauer <s.hauer@pengutronix.de>
>> Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
>> Cc: Fabio Estevam <festevam@gmail.com>
>> Cc: dri-devel@lists.freedesktop.org
>> Cc: imx@lists.linux.dev
>> ---
>> drivers/gpu/drm/imx/ipuv3/imx-ldb.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/imx/ipuv3/imx-ldb.c b/drivers/gpu/drm/imx/ipuv3/imx-ldb.c
>> index 71d70194fcbd..46f779fe60ee 100644
>> --- a/drivers/gpu/drm/imx/ipuv3/imx-ldb.c
>> +++ b/drivers/gpu/drm/imx/ipuv3/imx-ldb.c
>> @@ -654,8 +654,12 @@ static int imx_ldb_probe(struct platform_device *pdev)
>> */
>> for (i = 0; i < 4; i++) {
>> char clkname[16];
>> + int len;
>> +
>> + len = snprintf(clkname, sizeof(clkname), "di%d_sel", i);
>> + if (len >= sizeof(clkname))
>> + dev_err(dev, "clkname truncated\n");
>>
>> - snprintf(clkname, sizeof(clkname), "di%d_sel", i);
>> imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname);
>> if (IS_ERR(imx_ldb->clk_sel[i])) {
>> ret = PTR_ERR(imx_ldb->clk_sel[i]);
>> --
>> 2.39.2
--
Jani Nikula, Intel
next prev parent reply other threads:[~2024-05-24 9:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 15:51 [PATCH 0/4] drm: enable -Wformat-truncation Jani Nikula
2024-05-23 15:51 ` [PATCH 1/4] drm/amdgpu: fix -Wformat-truncation warning in amdgpu_gfx_kiq_init_ring() Jani Nikula
2024-05-23 18:07 ` Alex Deucher
2024-05-24 9:07 ` Jani Nikula
2024-05-23 15:51 ` [PATCH 2/4] drm/nouveau: fix -Wformat-truncation warning in nouveau_backlight_init() Jani Nikula
2024-05-23 15:51 ` [PATCH 3/4] drm/imx: fix -Wformat-truncation warning in imx_ldb_probe() Jani Nikula
2024-05-23 17:32 ` Ville Syrjälä
2024-05-24 9:04 ` Jani Nikula [this message]
2024-05-23 15:51 ` [PATCH 4/4] drm: enable -Wformat-truncation across the subsystem Jani Nikula
2024-05-23 18:41 ` Sam Ravnborg
2024-05-24 9:08 ` Jani Nikula
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=87jzjjoa13.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=nouveau@lists.freedesktop.org \
--cc=p.zabel@pengutronix.de \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=ville.syrjala@linux.intel.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).