summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2012-03-23 15:02:16 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 16:58:36 -0700
commit6061d949dd984c762ee272a88e77699fa675d1c8 (patch)
tree2e19eecd34a716fc5ed9fa3f18a7db0a3edf6f5b
parent97e834c5040b85e133d8d922111a62b2b853a406 (diff)
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>
-rw-r--r--include/linux/compiler-gcc.h3
-rw-r--r--include/linux/kernel.h8
-rw-r--r--include/xen/xenbus.h4
-rwxr-xr-xscripts/checkpatch.pl6
4 files changed, 14 insertions, 7 deletions
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 3fd17c249221..e5834aa24b9e 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -87,7 +87,8 @@
*/
#define __pure __attribute__((pure))
#define __aligned(x) __attribute__((aligned(x)))
-#define __printf(a,b) __attribute__((format(printf,a,b)))
+#define __printf(a, b) __attribute__((format(printf, a, b)))
+#define __scanf(a, b) __attribute__((format(scanf, a, b)))
#define noinline __attribute__((noinline))
#define __attribute_const__ __attribute__((__const__))
#define __maybe_unused __attribute__((unused))
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d801acb5e680..f2085b541a24 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -328,10 +328,10 @@ extern __printf(2, 3)
char *kasprintf(gfp_t gfp, const char *fmt, ...);
extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
-extern int sscanf(const char *, const char *, ...)
- __attribute__ ((format (scanf, 2, 3)));
-extern int vsscanf(const char *, const char *, va_list)
- __attribute__ ((format (scanf, 2, 0)));
+extern __scanf(2, 3)
+int sscanf(const char *, const char *, ...);
+extern __scanf(2, 0)
+int vsscanf(const char *, const char *, va_list);
extern int get_option(char **str, int *pint);
extern char *get_options(const char *str, int nints, int *ints);
diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
index e8c599b237c2..0a7515c1e3a4 100644
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -139,9 +139,9 @@ int xenbus_transaction_start(struct xenbus_transaction *t);
int xenbus_transaction_end(struct xenbus_transaction t, int abort);
/* Single read and scanf: returns -errno or num scanned if > 0. */
+__scanf(4, 5)
int xenbus_scanf(struct xenbus_transaction t,
- const char *dir, const char *node, const char *fmt, ...)
- __attribute__((format(scanf, 4, 5)));
+ const char *dir, const char *node, const char *fmt, ...);
/* Single printf and write: returns -errno or 0. */
__printf(4, 5)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a3b9782441f9..89d24b3ea438 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3123,6 +3123,12 @@ sub process {
"__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr);
}
+# Check for __attribute__ format(scanf, prefer __scanf
+ if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
+ WARN("PREFER_SCANF",
+ "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr);
+ }
+
# check for sizeof(&)
if ($line =~ /\bsizeof\s*\(\s*\&/) {
WARN("SIZEOF_ADDRESS",