[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250422125546.GF2843373@horms.kernel.org>
Date: Tue, 22 Apr 2025 13:55:46 +0100
From: Simon Horman <horms@...nel.org>
To: Justin Lai <justinlai0215@...ltek.com>
Cc: kuba@...nel.org, davem@...emloft.net, edumazet@...gle.com,
pabeni@...hat.com, andrew+netdev@...n.ch,
linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
pkshih@...ltek.com, larry.chiu@...ltek.com,
kernel test robot <lkp@...el.com>
Subject: Re: [PATCH net v3 2/3] rtase: Increase the size of ivec->name
On Thu, Apr 17, 2025 at 04:56:58PM +0800, Justin Lai wrote:
> Fix the following compile warning reported by the kernel test robot by
> increasing the size of ivec->name.
>
> drivers/net/ethernet/realtek/rtase/rtase_main.c: In function 'rtase_open':
> >> drivers/net/ethernet/realtek/rtase/rtase_main.c:1117:52: warning:
> '%i' directive output may be truncated writing between 1 and 10 bytes
> into a region of size between 7 and 22 [-Wformat-truncation=]
> snprintf(ivec->name, sizeof(ivec->name), "%s_int%i",
> ^~
> drivers/net/ethernet/realtek/rtase/rtase_main.c:1117:45: note:
> directive argument in the range [0, 2147483647]
> snprintf(ivec->name, sizeof(ivec->name), "%s_int%i",
> ^~~~~~~~~~
> drivers/net/ethernet/realtek/rtase/rtase_main.c:1117:4: note:
> 'snprintf' output between 6 and 30 bytes into a destination of
> size 26
> snprintf(ivec->name, sizeof(ivec->name), "%s_int%i",
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> tp->dev->name, i);
> ~~~~~~~~~~~~~~~~~
Hi Justin,
Given that the type of i is u16, it's theoretical range of values is [0, 65536].
(I expect that in practice the range is significantly smaller.)
So the string representation of i should fit in the minumum of 7 bytes available
(only a maximum of 5 are needed).
And I do notice that newer compilers do not seem to warn about this.
So I don't really think this needs updating.
And if so, certainly not as a fix for 'net'.
Also, as an aside, as i is unsigned, the format specifier really ought
to be %u instead of %i. Not that it seems to make any difference here
given the range of values discussed above.
> Reported-by: kernel test robot <lkp@...el.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202503182158.nkAlbJWX-lkp@intel.com/
> Fixes: a36e9f5cfe9e ("rtase: Add support for a pci table in this module")
> Signed-off-by: Justin Lai <justinlai0215@...ltek.com>
--
pw-bot: changes-requested
Powered by blists - more mailing lists