Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

include/ and checkpatch: prefer __scanf to __attribute__((format(scanf,...)

It's equivalent to __printf, so prefer __scanf.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joe Perches and committed by
Linus Torvalds
6061d949 97e834c5

+14 -7
+2 -1
include/linux/compiler-gcc.h
··· 87 87 */ 88 88 #define __pure __attribute__((pure)) 89 89 #define __aligned(x) __attribute__((aligned(x))) 90 - #define __printf(a,b) __attribute__((format(printf,a,b))) 90 + #define __printf(a, b) __attribute__((format(printf, a, b))) 91 + #define __scanf(a, b) __attribute__((format(scanf, a, b))) 91 92 #define noinline __attribute__((noinline)) 92 93 #define __attribute_const__ __attribute__((__const__)) 93 94 #define __maybe_unused __attribute__((unused))
+4 -4
include/linux/kernel.h
··· 328 328 char *kasprintf(gfp_t gfp, const char *fmt, ...); 329 329 extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); 330 330 331 - extern int sscanf(const char *, const char *, ...) 332 - __attribute__ ((format (scanf, 2, 3))); 333 - extern int vsscanf(const char *, const char *, va_list) 334 - __attribute__ ((format (scanf, 2, 0))); 331 + extern __scanf(2, 3) 332 + int sscanf(const char *, const char *, ...); 333 + extern __scanf(2, 0) 334 + int vsscanf(const char *, const char *, va_list); 335 335 336 336 extern int get_option(char **str, int *pint); 337 337 extern char *get_options(const char *str, int nints, int *ints);
+2 -2
include/xen/xenbus.h
··· 139 139 int xenbus_transaction_end(struct xenbus_transaction t, int abort); 140 140 141 141 /* Single read and scanf: returns -errno or num scanned if > 0. */ 142 + __scanf(4, 5) 142 143 int xenbus_scanf(struct xenbus_transaction t, 143 - const char *dir, const char *node, const char *fmt, ...) 144 - __attribute__((format(scanf, 4, 5))); 144 + const char *dir, const char *node, const char *fmt, ...); 145 145 146 146 /* Single printf and write: returns -errno or 0. */ 147 147 __printf(4, 5)
+6
scripts/checkpatch.pl
··· 3123 3123 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr); 3124 3124 } 3125 3125 3126 + # Check for __attribute__ format(scanf, prefer __scanf 3127 + if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { 3128 + WARN("PREFER_SCANF", 3129 + "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr); 3130 + } 3131 + 3126 3132 # check for sizeof(&) 3127 3133 if ($line =~ /\bsizeof\s*\(\s*\&/) { 3128 3134 WARN("SIZEOF_ADDRESS",