]> www.infradead.org Git - users/jedix/linux-maple.git/commit
leds: pca955x: Avoid potential overflow when filling default_label
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 7 Apr 2025 15:13:26 +0000 (18:13 +0300)
committerLee Jones <lee@kernel.org>
Wed, 14 May 2025 08:24:51 +0000 (09:24 +0100)
commitbd3d14932923a717ebe475122ca7e17200f87a0c
treeee63dc291e4f43c3826244ba509fff5421f79e07
parente35ca991a777ef513040cbb36bc8245a031a2633
leds: pca955x: Avoid potential overflow when filling default_label

GCC compiler (Debian 14.2.0-17) is not happy about printing
into a too short buffer (when build with `make W=1`):

  drivers/leds/leds-pca955x.c:554:33: note: ‘snprintf’ output between 2 and 12 bytes into a destination of size 8

Indeed, the buffer size is chosen based on some assumptions,
while in general the assigned value might not fit (GCC can't
prove it does).

Fix this by changing the bits field in the struct pca955x_chipdef to u8,
with a positive side effect of the better memory footprint, and convert
loop iterator to be unsigned. With that done, update format specifiers
accordingly.

In one case join back string literal as it improves the grepping over the code
based on the message and remove duplicating information (the driver name is
printed as pert of the dev_*() output [1]) as we touch the same line anyway.

Link: https://lore.kernel.org/r/4ac527f2-c59e-70a2-efd4-da52370ea557@dave.eu/
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250407151441.706378-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/leds-pca955x.c