Skip to content

Commit 239afba

Browse files
andy-shevlag-linaro
authored andcommitted
leds: pca955x: Avoid potential overflow when filling default_label (take 2)
GCC compiler v8.5.0 is not happy about printing into a too short buffer (when build with `make W=1`): drivers/leds/leds-pca955x.c:696:5: note: 'snprintf' output between 2 and 11 bytes into a destination of size 8 Unfortunately this is a false positive from the old GCC versions, but we may still improve the code by using '%hhu' format specifier and reduce buffer size by 4 bytes. Fixes: bd3d149 ("leds: pca955x: Avoid potential overflow when filling default_label") Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent cb33532 commit 239afba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/leds/leds-pca955x.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static int pca955x_probe(struct i2c_client *client)
587587
struct pca955x_platform_data *pdata;
588588
bool keep_psc0 = false;
589589
bool set_default_label = false;
590-
char default_label[8];
590+
char default_label[4];
591591
int bit, err, reg;
592592

593593
chip = i2c_get_match_data(client);
@@ -693,7 +693,7 @@ static int pca955x_probe(struct i2c_client *client)
693693
}
694694

695695
if (set_default_label) {
696-
snprintf(default_label, sizeof(default_label), "%u", i);
696+
snprintf(default_label, sizeof(default_label), "%hhu", i);
697697
init_data.default_label = default_label;
698698
} else {
699699
init_data.default_label = NULL;

0 commit comments

Comments
 (0)