Skip to content

Commit 08e8734

Browse files
Chester LinLinus Walleij
authored andcommitted
pinctrl: s32cc: Avoid possible string truncation
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>
1 parent edd48fd commit 08e8734

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/pinctrl/nxp/pinctrl-s32cc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,8 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
843843
if (!np)
844844
return -ENODEV;
845845

846-
if (mem_regions == 0) {
847-
dev_err(&pdev->dev, "mem_regions is 0\n");
846+
if (mem_regions == 0 || mem_regions >= 10000) {
847+
dev_err(&pdev->dev, "mem_regions is invalid: %u\n", mem_regions);
848848
return -EINVAL;
849849
}
850850

0 commit comments

Comments
 (0)