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/device.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/device.h')
| -rw-r--r-- | include/linux/device.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/include/linux/device.h b/include/linux/device.h index 5a31bf3a4024..a2b4ea70a946 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
| @@ -637,8 +637,9 @@ extern int devres_release_group(struct device *dev, void *id); | |||
| 637 | 637 | ||
| 638 | /* managed devm_k.alloc/kfree for device drivers */ | 638 | /* managed devm_k.alloc/kfree for device drivers */ |
| 639 | extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); | 639 | extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp); |
| 640 | extern char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, | 640 | extern __printf(3, 0) |
| 641 | va_list ap); | 641 | char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, |
| 642 | va_list ap); | ||
| 642 | extern __printf(3, 4) | 643 | extern __printf(3, 4) |
| 643 | char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...); | 644 | char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...); |
| 644 | static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) | 645 | static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) |
| @@ -1011,12 +1012,10 @@ extern int __must_check device_reprobe(struct device *dev); | |||
| 1011 | /* | 1012 | /* |
| 1012 | * Easy functions for dynamically creating devices on the fly | 1013 | * Easy functions for dynamically creating devices on the fly |
| 1013 | */ | 1014 | */ |
| 1014 | extern struct device *device_create_vargs(struct class *cls, | 1015 | extern __printf(5, 0) |
| 1015 | struct device *parent, | 1016 | struct device *device_create_vargs(struct class *cls, struct device *parent, |
| 1016 | dev_t devt, | 1017 | dev_t devt, void *drvdata, |
| 1017 | void *drvdata, | 1018 | const char *fmt, va_list vargs); |
| 1018 | const char *fmt, | ||
| 1019 | va_list vargs); | ||
| 1020 | extern __printf(5, 6) | 1019 | extern __printf(5, 6) |
| 1021 | struct device *device_create(struct class *cls, struct device *parent, | 1020 | struct device *device_create(struct class *cls, struct device *parent, |
| 1022 | dev_t devt, void *drvdata, | 1021 | dev_t devt, void *drvdata, |
