Skip to content

Commit 6061d94

Browse files
JoePerchestorvalds
authored andcommitted
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>
1 parent 97e834c commit 6061d94

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

include/linux/compiler-gcc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
*/
8888
#define __pure __attribute__((pure))
8989
#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)))
9192
#define noinline __attribute__((noinline))
9293
#define __attribute_const__ __attribute__((__const__))
9394
#define __maybe_unused __attribute__((unused))

include/linux/kernel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ extern __printf(2, 3)
328328
char *kasprintf(gfp_t gfp, const char *fmt, ...);
329329
extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
330330

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);
335335

336336
extern int get_option(char **str, int *pint);
337337
extern char *get_options(const char *str, int nints, int *ints);

include/xen/xenbus.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ int xenbus_transaction_start(struct xenbus_transaction *t);
139139
int xenbus_transaction_end(struct xenbus_transaction t, int abort);
140140

141141
/* Single read and scanf: returns -errno or num scanned if > 0. */
142+
__scanf(4, 5)
142143
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, ...);
145145

146146
/* Single printf and write: returns -errno or 0. */
147147
__printf(4, 5)

scripts/checkpatch.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,6 +3123,12 @@ sub process {
31233123
"__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr);
31243124
}
31253125

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+
31263132
# check for sizeof(&)
31273133
if ($line =~ /\bsizeof\s*\(\s*\&/) {
31283134
WARN("SIZEOF_ADDRESS",

0 commit comments

Comments
 (0)