Skip to content

Commit 811b544

Browse files
arndbpavelmachek
authored andcommitted
led-class-flash: fix -Wrestrict warning
gcc-11 warns when building with W=1: drivers/leds/led-class-flash.c: In function 'flash_fault_show': drivers/leds/led-class-flash.c:210:16: error: 'sprintf' argument 3 overlaps destination object 'buf' [-Werror=restrict] 210 | return sprintf(buf, "%s\n", buf); | ^~~~~~~~~~~~~~~~~~~~~~~~~ drivers/leds/led-class-flash.c:187:54: note: destination object referenced by 'restrict'-qualified argument 1 was declared here 187 | struct device_attribute *attr, char *buf) | ~~~~~~^~~ There is no need for the sprintf() here when a strcat() does the same thing without invoking undefined behavior. Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent 6880fa6 commit 811b544

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/leds/led-class-flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static ssize_t flash_fault_show(struct device *dev,
207207
mask <<= 1;
208208
}
209209

210-
return sprintf(buf, "%s\n", buf);
210+
return strlen(strcat(buf, "\n"));
211211
}
212212
static DEVICE_ATTR_RO(flash_fault);
213213

0 commit comments

Comments
 (0)