diff options
author | Nicolas Iooss <nicolas.iooss_linux@m4x.org> | 2015-07-17 19:23:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-07-17 19:39:53 -0400 |
commit | 8db1486065141e619e4855b84e350ef32064f7e1 (patch) | |
tree | 438cace62ece1251656b38fbf428cf5aa5184fb8 /include/linux/kernel.h | |
parent | 7f9be77555bb2e52de84e9dddf7b4eb20cc6e171 (diff) |
include, lib: add __printf attributes to several function prototypes
Using __printf attributes helps to detect several format string issues
at compile time (even though -Wformat-security is currently disabled in
Makefile). For example it can detect when formatting a pointer as a
number, like the issue fixed in commit a3fa71c40f18 ("wl18xx: show
rx_frames_per_rates as an array as it really is"), or when the arguments
do not match the format string, c.f. for example commit 5ce1aca81435
("reiserfs: fix __RASSERT format string").
To prevent similar bugs in the future, add a __printf attribute to every
function prototype which needs one in include/linux/ and lib/. These
functions were mostly found by using gcc's -Wsuggest-attribute=format
flag.
Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5f0be58640ea..5582410727cb 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -411,7 +411,8 @@ extern __printf(3, 0) | |||
411 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); | 411 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); |
412 | extern __printf(2, 3) | 412 | extern __printf(2, 3) |
413 | char *kasprintf(gfp_t gfp, const char *fmt, ...); | 413 | char *kasprintf(gfp_t gfp, const char *fmt, ...); |
414 | extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); | 414 | extern __printf(2, 0) |
415 | char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); | ||
415 | 416 | ||
416 | extern __scanf(2, 3) | 417 | extern __scanf(2, 3) |
417 | int sscanf(const char *, const char *, ...); | 418 | int sscanf(const char *, const char *, ...); |
@@ -679,10 +680,10 @@ do { \ | |||
679 | __ftrace_vprintk(_THIS_IP_, fmt, vargs); \ | 680 | __ftrace_vprintk(_THIS_IP_, fmt, vargs); \ |
680 | } while (0) | 681 | } while (0) |
681 | 682 | ||
682 | extern int | 683 | extern __printf(2, 0) int |
683 | __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); | 684 | __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); |
684 | 685 | ||
685 | extern int | 686 | extern __printf(2, 0) int |
686 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); | 687 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); |
687 | 688 | ||
688 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); | 689 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
@@ -702,7 +703,7 @@ int trace_printk(const char *fmt, ...) | |||
702 | { | 703 | { |
703 | return 0; | 704 | return 0; |
704 | } | 705 | } |
705 | static inline int | 706 | static __printf(1, 0) inline int |
706 | ftrace_vprintk(const char *fmt, va_list ap) | 707 | ftrace_vprintk(const char *fmt, va_list ap) |
707 | { | 708 | { |
708 | return 0; | 709 | return 0; |