pinctrl: s32cc: Avoid possible string truncation
authorChester Lin <clin@suse.com>
Tue, 7 Nov 2023 14:10:44 +0000 (22:10 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Jan 2024 10:51:37 +0000 (11:51 +0100)
commitf88c602fd0ab289d03e0e279ce83ddf01c24ec22
treeb44aa3a266583b6c63e65af1a5e3be1995f64ca7
parent2525d1ba225b5c167162fa344013c408e8b4de36
pinctrl: s32cc: Avoid possible string truncation

[ Upstream commit 08e8734d877a9a0fb8af1254a4ce58734fbef296 ]

With "W=1" and "-Wformat-truncation" build options, the kernel test robot
found a possible string truncation warning in pinctrl-s32cc.c, which uses
an 8-byte char array to hold a memory region name "map%u". Since the
maximum number of digits that a u32 value can present is 10, and the "map"
string occupies 3 bytes with a termination '\0', which means the rest 4
bytes cannot fully present the integer "X" that exceeds 4 digits.

Here we check if the number >= 10000, which is the lowest value that
contains more than 4 digits.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311030159.iyUGjNGF-lkp@intel.com/
Signed-off-by: Chester Lin <clin@suse.com>
Link: https://lore.kernel.org/r/20231107141044.24058-1-clin@suse.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pinctrl/nxp/pinctrl-s32cc.c