db: export get_static_filter()
[smatch.git] / check_kernel_printf.c
blob70b7ad13983de5961a23e4af1a9caa1f6a18d2ec
1 /*
2 * Copyright (C) 2015 Rasmus Villemoes.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include <assert.h>
19 #include <ctype.h>
20 #include <string.h>
21 #include "smatch.h"
23 #define spam(args...) do { \
24 if (option_spammy) \
25 sm_msg(args); \
26 } while (0)
28 static int my_id;
31 * Much of this is taken directly from the kernel (mostly vsprintf.c),
32 * with a few modifications here and there.
35 #define KERN_SOH_ASCII '\001'
37 typedef unsigned char u8;
38 typedef signed short s16;
40 #define ZEROPAD 1 /* pad with zero */
41 #define SIGN 2 /* unsigned/signed long */
42 #define PLUS 4 /* show plus */
43 #define SPACE 8 /* space if plus */
44 #define LEFT 16 /* left justified */
45 #define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
46 #define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
48 enum format_type {
49 FORMAT_TYPE_NONE, /* Just a string part */
50 FORMAT_TYPE_WIDTH,
51 FORMAT_TYPE_PRECISION,
52 FORMAT_TYPE_CHAR,
53 FORMAT_TYPE_STR,
54 FORMAT_TYPE_PTR,
55 FORMAT_TYPE_PERCENT_CHAR,
56 FORMAT_TYPE_INVALID,
57 FORMAT_TYPE_LONG_LONG,
58 FORMAT_TYPE_ULONG,
59 FORMAT_TYPE_LONG,
60 FORMAT_TYPE_UBYTE,
61 FORMAT_TYPE_BYTE,
62 FORMAT_TYPE_USHORT,
63 FORMAT_TYPE_SHORT,
64 FORMAT_TYPE_UINT,
65 FORMAT_TYPE_INT,
66 FORMAT_TYPE_SIZE_T,
67 FORMAT_TYPE_PTRDIFF,
68 FORMAT_TYPE_NRCHARS, /* Reintroduced for this checker */
69 FORMAT_TYPE_FLOAT, /* for various floating point formatters */
72 struct printf_spec {
73 u8 type; /* format_type enum */
74 u8 flags; /* flags to number() */
75 u8 base; /* number base, 8, 10 or 16 only */
76 u8 qualifier; /* number qualifier, one of 'hHlLtzZ' */
77 s16 field_width; /* width of output field */
78 s16 precision; /* # of digits/chars */
81 static int
82 skip_atoi(const char **s)
84 int i = 0;
86 while (isdigit(**s))
87 i = i*10 + *((*s)++) - '0';
89 return i;
92 static int
93 format_decode(const char *fmt, struct printf_spec *spec)
95 const char *start = fmt;
97 /* we finished early by reading the field width */
98 if (spec->type == FORMAT_TYPE_WIDTH) {
99 if (spec->field_width < 0) {
100 spec->field_width = -spec->field_width;
101 spec->flags |= LEFT;
103 spec->type = FORMAT_TYPE_NONE;
104 goto precision;
107 /* we finished early by reading the precision */
108 if (spec->type == FORMAT_TYPE_PRECISION) {
109 if (spec->precision < 0)
110 spec->precision = 0;
112 spec->type = FORMAT_TYPE_NONE;
113 goto qualifier;
116 /* By default */
117 spec->type = FORMAT_TYPE_NONE;
119 for (; *fmt ; ++fmt) {
120 if (*fmt == '%')
121 break;
124 /* Return the current non-format string */
125 if (fmt != start || !*fmt)
126 return fmt - start;
128 /* Process flags */
129 spec->flags = 0;
131 while (1) { /* this also skips first '%' */
132 bool found = true;
134 ++fmt;
136 switch (*fmt) {
137 case '-': spec->flags |= LEFT; break;
138 case '+': spec->flags |= PLUS; break;
139 case ' ': spec->flags |= SPACE; break;
140 case '#': spec->flags |= SPECIAL; break;
141 case '0': spec->flags |= ZEROPAD; break;
142 default: found = false;
145 if (!found)
146 break;
149 /* get field width */
150 spec->field_width = -1;
152 if (isdigit(*fmt))
153 spec->field_width = skip_atoi(&fmt);
154 else if (*fmt == '*') {
155 /* it's the next argument */
156 spec->type = FORMAT_TYPE_WIDTH;
157 return ++fmt - start;
160 precision:
161 /* get the precision */
162 spec->precision = -1;
163 if (*fmt == '.') {
164 ++fmt;
165 if (isdigit(*fmt)) {
166 spec->precision = skip_atoi(&fmt);
167 if (spec->precision < 0)
168 spec->precision = 0;
169 } else if (*fmt == '*') {
170 /* it's the next argument */
171 spec->type = FORMAT_TYPE_PRECISION;
172 return ++fmt - start;
176 qualifier:
177 /* get the conversion qualifier */
178 spec->qualifier = 0;
179 if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
180 _tolower(*fmt) == 'z' || *fmt == 't') {
181 spec->qualifier = *fmt++;
182 if (spec->qualifier == *fmt) {
183 if (spec->qualifier == 'l') {
184 spec->qualifier = 'L';
185 ++fmt;
186 } else if (spec->qualifier == 'h') {
187 spec->qualifier = 'H';
188 ++fmt;
189 } else {
190 sm_msg("warn: invalid repeated qualifier '%c'", *fmt);
195 /* default base */
196 spec->base = 10;
197 switch (*fmt) {
198 case 'c':
199 spec->type = FORMAT_TYPE_CHAR;
200 return ++fmt - start;
202 case 's':
203 spec->type = FORMAT_TYPE_STR;
204 return ++fmt - start;
206 case 'p':
207 spec->type = FORMAT_TYPE_PTR;
208 return ++fmt - start;
210 case '%':
211 spec->type = FORMAT_TYPE_PERCENT_CHAR;
212 return ++fmt - start;
214 /* integer number formats - set up the flags and "break" */
215 case 'o':
216 spec->base = 8;
217 break;
219 case 'x':
220 spec->flags |= SMALL;
222 case 'X':
223 spec->base = 16;
224 break;
226 case 'd':
227 case 'i':
228 spec->flags |= SIGN;
229 case 'u':
230 break;
232 case 'n':
233 spec->type = FORMAT_TYPE_NRCHARS;
234 return ++fmt - start;
236 case 'a': case 'A':
237 case 'e': case 'E':
238 case 'f': case 'F':
239 case 'g': case 'G':
240 spec->type = FORMAT_TYPE_FLOAT;
241 return ++fmt - start;
243 default:
244 spec->type = FORMAT_TYPE_INVALID;
245 /* Unlike the kernel code, we 'consume' the invalid
246 * character so that it can get included in the
247 * report. After that, we bail out. */
248 return ++fmt - start;
251 if (spec->qualifier == 'L')
252 spec->type = FORMAT_TYPE_LONG_LONG;
253 else if (spec->qualifier == 'l') {
254 if (spec->flags & SIGN)
255 spec->type = FORMAT_TYPE_LONG;
256 else
257 spec->type = FORMAT_TYPE_ULONG;
258 } else if (_tolower(spec->qualifier) == 'z') {
259 spec->type = FORMAT_TYPE_SIZE_T;
260 } else if (spec->qualifier == 't') {
261 spec->type = FORMAT_TYPE_PTRDIFF;
262 } else if (spec->qualifier == 'H') {
263 if (spec->flags & SIGN)
264 spec->type = FORMAT_TYPE_BYTE;
265 else
266 spec->type = FORMAT_TYPE_UBYTE;
267 } else if (spec->qualifier == 'h') {
268 if (spec->flags & SIGN)
269 spec->type = FORMAT_TYPE_SHORT;
270 else
271 spec->type = FORMAT_TYPE_USHORT;
272 } else {
273 if (spec->flags & SIGN)
274 spec->type = FORMAT_TYPE_INT;
275 else
276 spec->type = FORMAT_TYPE_UINT;
279 return ++fmt - start;
282 static int is_struct_tag(struct symbol *type, const char *tag)
284 return type->type == SYM_STRUCT && type->ident && !strcmp(type->ident->name, tag);
287 static int is_char_type(struct symbol *type)
289 return type == &uchar_ctype || type == &char_ctype || type == &schar_ctype;
293 * I have absolutely no idea if this is how one is supposed to get the
294 * symbol representing a typedef, but it seems to work.
296 struct typedef_lookup {
297 const char *name;
298 struct symbol *sym;
299 int failed;
302 static struct symbol *_typedef_lookup(const char *name)
304 struct ident *id;
305 struct symbol *node;
307 id = built_in_ident(name);
308 if (!id)
309 return NULL;
310 node = lookup_symbol(id, NS_TYPEDEF);
311 if (!node || node->type != SYM_NODE)
312 return NULL;
313 return node->ctype.base_type;
316 static void typedef_lookup(struct typedef_lookup *tl)
318 if (tl->sym || tl->failed)
319 return;
320 tl->sym = _typedef_lookup(tl->name);
321 if (!tl->sym) {
322 sm_msg("internal error: could not find typedef '%s'", tl->name);
323 tl->failed = 1;
328 static void ip4(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
330 enum { ENDIAN_BIG, ENDIAN_LITTLE, ENDIAN_HOST } endian = ENDIAN_BIG;
332 assert(fmt[0] == 'i' || fmt[0] == 'I');
333 assert(fmt[1] == '4');
335 if (isalnum(fmt[2])) {
336 switch (fmt[2]) {
337 case 'h':
338 endian = ENDIAN_HOST;
339 break;
340 case 'l':
341 endian = ENDIAN_LITTLE;
342 break;
343 case 'n':
344 case 'b':
345 endian = ENDIAN_BIG;
346 break;
347 default:
348 sm_msg("warn: '%%p%c4' can only be followed by one of [hnbl], not '%c'", fmt[0], fmt[2]);
350 if (isalnum(fmt[3]))
351 sm_msg("warn: '%%p%c4' can only be followed by precisely one of [hnbl]", fmt[0]);
355 if (type->ctype.modifiers & MOD_NODEREF)
356 sm_msg("error: passing __user pointer to '%%p%c4'", fmt[0]);
359 * If we have a pointer to char/u8/s8, we expect the caller to
360 * handle endianness; I don't think there's anything we can
361 * do. I'd like to check that if we're passed a pointer to a
362 * __bitwise u32 (most likely a __be32), we should have endian
363 * == ENDIAN_BIG. But I can't figure out how to get that
364 * information (it also seems to require ensuring certain
365 * macros are defined). But struct in_addr certainly consists
366 * of only a single __be32, so in that case we can do a check.
368 if (is_char_type(basetype))
369 return;
371 if (is_struct_tag(basetype, "in_addr") && endian != ENDIAN_BIG)
372 sm_msg("warn: passing struct in_addr* to '%%p%c4%c', is the endianness ok?", fmt[0], fmt[2]);
374 /* ... */
377 static void ip6(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
379 assert(fmt[0] == 'i' || fmt[0] == 'I');
380 assert(fmt[1] == '6');
382 if (isalnum(fmt[2])) {
383 if (fmt[2] != 'c')
384 sm_msg("warn: '%%p%c6' can only be followed by c", fmt[0]);
385 else if (fmt[0] == 'i')
386 sm_msg("warn: '%%pi6' does not allow flag c");
387 if (isalnum(fmt[3]))
388 sm_msg("warn: '%%p%c6%c' cannot be followed by other alphanumerics", fmt[0], fmt[2]);
391 if (type->ctype.modifiers & MOD_NODEREF)
392 sm_msg("error: passing __user pointer to '%%p%c6'", fmt[0]);
395 static void ipS(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
397 const char *f;
399 assert(tolower(fmt[0]) == 'i');
400 assert(fmt[1] == 'S');
402 for (f = fmt+2; isalnum(*f); ++f) {
403 /* It's probably too anal checking for duplicate flags. */
404 if (!strchr("pfschnbl", *f))
405 sm_msg("warn: '%%p%cS' cannot be followed by '%c'", fmt[0], *f);
409 * XXX: Should we also allow passing a pointer to a union, one
410 * member of which is a struct sockaddr? It may be slightly
411 * cleaner actually passing &u.raw instead of just &u, though
412 * the generated code is of course exactly the same. For now,
413 * we do accept struct sockaddr_in and struct sockaddr_in6,
414 * since those are easy to handle and rather harmless.
416 if (!is_struct_tag(basetype, "sockaddr") &&
417 !is_struct_tag(basetype, "sockaddr_in") &&
418 !is_struct_tag(basetype, "sockaddr_in6"))
419 sm_msg("error: '%%p%cS' expects argument of type struct sockaddr *, "
420 "argument %d has type '%s'", fmt[0], vaidx, type_to_str(type));
423 static void hex_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
425 assert(fmt[0] == 'h');
426 if (isalnum(fmt[1])) {
427 if (!strchr("CDN", fmt[1]))
428 sm_msg("warn: '%%ph' cannot be followed by '%c'", fmt[1]);
429 if (isalnum(fmt[2]))
430 sm_msg("warn: '%%ph' can be followed by at most one of [CDN], and no other alphanumerics");
432 if (type->ctype.modifiers & MOD_NODEREF)
433 sm_msg("error: passing __user pointer to %%ph");
436 static void escaped_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
438 assert(fmt[0] == 'E');
439 while (isalnum(*++fmt)) {
440 if (!strchr("achnops", *fmt))
441 sm_msg("warn: %%pE can only be followed by a combination of [achnops]");
443 if (type->ctype.modifiers & MOD_NODEREF)
444 sm_msg("error: passing __user pointer to %%pE");
447 static void resource_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
449 assert(tolower(fmt[0]) == 'r');
450 if (!is_struct_tag(basetype, "resource")) {
451 sm_msg("error: '%%p%c' expects argument of type struct resource *, "
452 "but argument %d has type '%s'", fmt[0], vaidx, type_to_str(type));
454 if (isalnum(fmt[1]))
455 sm_msg("warn: '%%p%c' cannot be followed by '%c'", fmt[0], fmt[1]);
458 static void mac_address_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
460 assert(tolower(fmt[0]) == 'm');
461 if (isalnum(fmt[1])) {
462 if (!(fmt[1] == 'F' || fmt[1] == 'R'))
463 sm_msg("warn: '%%p%c' cannot be followed by '%c'", fmt[0], fmt[1]);
464 if (fmt[0] == 'm' && fmt[1] == 'F')
465 sm_msg("warn: it is pointless to pass flag F to %%pm");
466 if (isalnum(fmt[2]))
467 sm_msg("warn: '%%p%c%c' cannot be followed by other alphanumeric", fmt[0], fmt[1]);
469 /* Technically, bdaddr_t is a typedef for an anonymous struct, but this still seems to work. */
470 if (!is_char_type(basetype) && !is_struct_tag(basetype, "bdaddr_t") && basetype != &void_ctype) {
471 sm_msg("warn: '%%p%c' expects argument of type u8 * or bdaddr_t *, argument %d has type '%s'",
472 fmt[0], vaidx, type_to_str(type));
474 if (type->ctype.modifiers & MOD_NODEREF)
475 sm_msg("error: passing __user pointer to '%%p%c'", fmt[0]);
478 static void dentry_file(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
480 const char *tag;
482 assert(tolower(fmt[0]) == 'd');
483 tag = fmt[0] == 'd' ? "dentry" : "file";
485 if (isalnum(fmt[1])) {
486 if (!strchr("234", fmt[1]))
487 sm_msg("warn: '%%p%c' can only be followed by one of [234]", fmt[0]);
488 if (isalnum(fmt[2]))
489 sm_msg("warn: '%%p%c%c' cannot be followed by '%c'", fmt[0], fmt[1], fmt[2]);
492 if (!is_struct_tag(basetype, tag))
493 sm_msg("error: '%%p%c' expects argument of type struct '%s*', argument %d has type '%s'",
494 fmt[0], tag, vaidx, type_to_str(type));
497 static void va_format(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
499 assert(fmt[0] == 'V');
500 if (isalnum(fmt[1]))
501 sm_msg("warn: %%pV cannot be followed by any alphanumerics");
502 if (!is_struct_tag(basetype, "va_format"))
503 sm_msg("error: %%pV expects argument of type struct va_format*, argument %d has type '%s'", vaidx, type_to_str(type));
506 static void netdev_feature(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
508 static struct typedef_lookup netdev = { .name = "netdev_features_t" };
510 assert(fmt[0] == 'N');
511 if (fmt[1] != 'F') {
512 sm_msg("error: %%pN must be followed by 'F'");
513 return;
515 if (isalnum(fmt[2]))
516 sm_msg("warn: %%pNF cannot be followed by '%c'", fmt[2]);
518 typedef_lookup(&netdev);
519 if (!netdev.sym)
520 return;
521 if (basetype != netdev.sym)
522 sm_msg("error: %%pNF expects argument of type netdev_features_t*, argument %d has type '%s'",
523 vaidx, type_to_str(type));
526 static void address_val(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
528 static struct typedef_lookup dma = { .name = "dma_addr_t" };
529 static struct typedef_lookup phys = { .name = "phys_addr_t" };
530 struct typedef_lookup *which = &phys;
531 const char *suf = "";
532 assert(fmt[0] == 'a');
534 if (isalnum(fmt[1])) {
535 switch (fmt[1]) {
536 case 'd':
537 which = &dma;
538 suf = "d";
539 break;
540 case 'p':
541 suf = "p";
542 break;
543 default:
544 sm_msg("error: '%%pa' can only be followed by one of [dp]");
546 if (isalnum(fmt[2]))
547 sm_msg("error: '%%pa%c' cannot be followed by '%c'", fmt[1], fmt[2]);
550 typedef_lookup(which);
551 if (!which->sym)
552 return;
553 if (basetype != which->sym) {
554 sm_msg("error: '%%pa%s' expects argument of type '%s*', argument %d has type '%s'",
555 suf, which->name, vaidx, type_to_str(type));
559 static void
560 pointer(const char *fmt, struct expression *arg, int vaidx)
562 struct symbol *type, *basetype;
564 type = get_type(arg);
565 if (!type) {
566 sm_msg("warn: could not determine type of argument %d", vaidx);
567 return;
569 if (!is_ptr_type(type)) {
570 sm_msg("error: %%p expects pointer argument, but argument %d has type '%s'",
571 vaidx, type_to_str(type));
572 return;
574 /* Just plain %p, nothing to check. */
575 if (!isalnum(*fmt))
576 return;
578 basetype = get_real_base_type(type);
580 * Passing a pointer-to-array is harmless, but most likely one
581 * meant to pass pointer-to-first-element. If basetype is
582 * array type, we issue a notice and "dereference" the types
583 * once more.
585 if (basetype->type == SYM_ARRAY) {
586 spam("note: passing pointer-to-array; is the address-of redundant?");
587 type = basetype;
588 basetype = get_real_base_type(type);
592 * We pass both the type and the basetype to the helpers. If,
593 * for example, the pointer is really a decayed array which is
594 * passed to %pI4, we might want to check that it is in fact
595 * an array of four bytes. But most are probably only
596 * interested in whether the basetype makes sense. Also, the
597 * pointer may carry some annotation such as __user which
598 * might be worth checking in the handlers which actually
599 * dereference the pointer.
602 switch (*fmt) {
603 case 'b':
604 case 'F':
605 case 'f':
606 case 'S':
607 case 's':
608 case 'B':
609 /* Can we do anything sensible? Check that the arg is a function pointer, for example? */
610 break;
612 case 'R':
613 case 'r':
614 resource_string(fmt, type, basetype, vaidx);
615 break;
616 case 'M':
617 case 'm':
618 mac_address_string(fmt, type, basetype, vaidx);
619 break;
620 case 'I':
621 case 'i':
622 switch (fmt[1]) {
623 case '4':
624 ip4(fmt, type, basetype, vaidx);
625 break;
626 case '6':
627 ip6(fmt, type, basetype, vaidx);
628 break;
629 case 'S':
630 ipS(fmt, type, basetype, vaidx);
631 break;
632 default:
633 sm_msg("warn: '%%p%c' must be followed by one of [46S]", fmt[0]);
634 break;
636 break;
638 * %pE and %ph can handle any valid pointer. We still check
639 * whether all the subsequent alphanumerics are valid for the
640 * particular %pX conversion.
642 case 'E':
643 escaped_string(fmt, type, basetype, vaidx);
644 break;
645 case 'h':
646 hex_string(fmt, type, basetype, vaidx);
647 break;
648 case 'U': /* TODO */
649 break;
650 case 'V':
651 va_format(fmt, type, basetype, vaidx);
652 break;
653 case 'K': /* TODO */
654 break;
655 case 'N':
656 netdev_feature(fmt, type, basetype, vaidx);
657 break;
658 case 'a':
659 address_val(fmt, type, basetype, vaidx);
660 break;
661 case 'D':
662 case 'd':
663 dentry_file(fmt, type, basetype, vaidx);
664 break;
665 default:
666 sm_msg("error: unrecognized %%p extension '%c', treated as normal %%p", *fmt);
670 static int
671 check_format_string(const char *fmt, const char *caller)
673 const char *f;
675 for (f = fmt; *f; ++f) {
676 unsigned char c = *f;
677 switch (c) {
678 case KERN_SOH_ASCII:
680 * This typically arises from bad conversion
681 * to pr_*, e.g. pr_warn(KERN_WARNING "something").
683 if (f != fmt)
684 sm_msg("warn: KERN_* level not at start of string");
686 * In a very few cases, the level is actually
687 * computed and passed via %c, as in KERN_SOH
688 * "%c...". printk explicitly supports
689 * this.
691 if (!(('0' <= f[1] && f[1] <= '7') || f[1] == 'd'))
692 sm_msg("warn: invalid KERN_* level: KERN_SOH_ASCII followed by '\\x%02x'", (unsigned char)f[1]);
693 break;
694 case '\t':
695 case '\n':
696 case '\r':
697 case 0x20 ... 0x7e:
698 break;
699 case 0x80 ... 0xff:
700 sm_msg("warn: format string contains non-ascii character '\\x%02x'", c);
701 break;
702 case 0x08:
703 if (f == fmt)
704 break;
705 /* fall through */
706 default:
707 sm_msg("warn: format string contains unusual character '\\x%02x'", c);
708 break;
712 f = strstr(fmt, caller);
713 if (f && strstr(f+1, caller))
714 sm_msg("note: format string contains name of enclosing function '%s' twice", caller);
716 return f != NULL;
719 static int arg_is___func__(struct expression *arg)
721 if (arg->type != EXPR_SYMBOL)
722 return 0;
723 return !strcmp(arg->symbol_name->name, "__func__") ||
724 !strcmp(arg->symbol_name->name, "__FUNCTION__") ||
725 !strcmp(arg->symbol_name->name, "__PRETTY_FUNCTION__");
727 static int arg_contains_caller(struct expression *arg, const char *caller)
729 if (arg->type != EXPR_STRING)
730 return 0;
731 return strstr(arg->string->data, caller) != NULL;
734 static int is_array_of_const_char(struct symbol *sym)
736 struct symbol *base = sym->ctype.base_type;
737 if (base->type != SYM_ARRAY)
738 return 0;
739 if (!(base->ctype.modifiers & MOD_CONST))
740 return 0;
741 if (!is_char_type(base->ctype.base_type)) {
742 spam("weird: format argument is array of const '%s'", type_to_str(base->ctype.base_type));
743 return 0;
745 return 1;
748 static int is_const_pointer_to_const_char(struct symbol *sym)
750 struct symbol *base = sym->ctype.base_type;
751 if (!(sym->ctype.modifiers & MOD_CONST))
752 return 0;
753 if (base->type != SYM_PTR)
754 return 0;
755 if (!(base->ctype.modifiers & MOD_CONST))
756 return 0;
757 if (!is_char_type(base->ctype.base_type)) {
758 spam("weird: format argument is pointer to const '%s'", type_to_str(base->ctype.base_type));
759 return 0;
761 return 1;
765 static void
766 do_check_printf_call(const char *caller, const char *name, struct expression *callexpr, struct expression *fmtexpr, int vaidx)
768 struct printf_spec spec = {0};
769 const char *fmt;
770 int caller_in_fmt;
772 fmtexpr = strip_parens(fmtexpr);
773 if (fmtexpr->type == EXPR_CONDITIONAL) {
774 do_check_printf_call(caller, name, callexpr, fmtexpr->cond_true ? : fmtexpr->conditional, vaidx);
775 do_check_printf_call(caller, name, callexpr, fmtexpr->cond_false, vaidx);
776 return;
778 if (fmtexpr->type == EXPR_SYMBOL) {
780 * If the symbol has an initializer, we can handle
782 * const char foo[] = "abc"; and
783 * const char * const foo = "abc";
785 * We simply replace fmtexpr with the initializer
786 * expression. If foo is not one of the above, or if
787 * the initializer expression is somehow not a string
788 * literal, fmtexpr->type != EXPR_STRING will trigger
789 * below and we'll spam+return.
791 struct symbol *sym = fmtexpr->symbol;
792 if (sym->initializer &&
793 (is_array_of_const_char(sym) ||
794 is_const_pointer_to_const_char(sym))) {
795 fmtexpr = strip_parens(sym->initializer);
799 if (fmtexpr->type != EXPR_STRING) {
801 * Since we're now handling both ?: and static const
802 * char[] arguments, we don't get as much noise. It's
803 * still spammy, though.
805 spam("warn: call of '%s' with non-constant format argument", name);
806 return;
809 fmt = fmtexpr->string->data;
810 caller_in_fmt = check_format_string(fmt, caller);
812 while (*fmt) {
813 const char *old_fmt = fmt;
814 int read = format_decode(fmt, &spec);
815 struct expression *arg;
817 fmt += read;
818 if (spec.type == FORMAT_TYPE_NONE ||
819 spec.type == FORMAT_TYPE_PERCENT_CHAR)
820 continue;
823 * vaidx is currently the correct 0-based index for
824 * get_argument_from_call_expr. We post-increment it
825 * here so that it is the correct 1-based index for
826 * all the handlers below. This of course requires
827 * that we handle all FORMAT_TYPE_* things not taking
828 * an argument above.
830 arg = get_argument_from_call_expr(callexpr->args, vaidx++);
832 switch (spec.type) {
833 /* case FORMAT_TYPE_NONE: */
834 /* case FORMAT_TYPE_PERCENT_CHAR: */
835 /* break; */
837 case FORMAT_TYPE_INVALID:
838 sm_msg("error: format specifier '%.*s' invalid", read, old_fmt);
839 return;
841 case FORMAT_TYPE_FLOAT:
842 sm_msg("error: no floats in the kernel; invalid format specifier '%.*s'", read, old_fmt);
843 return;
845 case FORMAT_TYPE_NRCHARS:
846 sm_msg("error: %%n not supported in kernel");
847 return;
849 case FORMAT_TYPE_WIDTH:
850 case FORMAT_TYPE_PRECISION:
851 /* check int argument */
852 break;
854 case FORMAT_TYPE_STR:
856 * If the format string already contains the
857 * function name, it probably doesn't make
858 * sense to pass __func__ as well (or rather
859 * vice versa: If pr_fmt(fmt) has been defined
860 * to '"%s: " fmt, __func__', it doesn't make
861 * sense to use a format string containing the
862 * function name).
864 * This produces a lot of hits. They are not
865 * false positives, but it is easier to handle
866 * the things which don't occur that often
867 * first, so we use spam().
869 if (spec.qualifier)
870 sm_msg("warn: qualifier '%c' ignored for %%s specifier", spec.qualifier);
872 if (caller_in_fmt) {
873 if (arg_is___func__(arg))
874 spam("warn: passing __func__ while the format string already contains the name of the function '%s'",
875 caller);
876 else if (arg_contains_caller(arg, caller))
877 sm_msg("warn: passing string constant '%s' containing '%s' which is already part of the format string",
878 arg->string->data, caller);
880 break;
882 case FORMAT_TYPE_PTR:
883 /* This is the most important part: Checking %p extensions. */
884 pointer(fmt, arg, vaidx);
885 while (isalnum(*fmt))
886 fmt++;
887 break;
889 case FORMAT_TYPE_CHAR:
890 if (spec.qualifier)
891 sm_msg("warn: qualifier '%c' ignored for %%s specifier", spec.qualifier);
893 case FORMAT_TYPE_UBYTE:
894 case FORMAT_TYPE_BYTE:
895 case FORMAT_TYPE_USHORT:
896 case FORMAT_TYPE_SHORT:
897 case FORMAT_TYPE_INT:
898 /* argument should have integer type of width <= sizeof(int) */
899 break;
901 case FORMAT_TYPE_UINT:
902 case FORMAT_TYPE_LONG:
903 case FORMAT_TYPE_ULONG:
904 case FORMAT_TYPE_LONG_LONG:
905 case FORMAT_TYPE_PTRDIFF:
906 case FORMAT_TYPE_SIZE_T:
907 break;
913 if (get_argument_from_call_expr(callexpr->args, vaidx))
914 sm_msg("warn: excess argument passed to '%s'", name);
919 static void
920 check_printf_call(const char *name, struct expression *callexpr, void *_info)
923 * Note: attribute(printf) uses 1-based indexing, but
924 * get_argument_from_call_expr() uses 0-based indexing.
926 int info = PTR_INT(_info);
927 int fmtidx = (info & 0xff) - 1;
928 int vaidx = ((info >> 8) & 0xff) - 1;
929 struct expression *fmtexpr;
930 const char *caller = get_function();
933 * Calling a v*printf function with a literal format arg is
934 * extremely rare, so we don't bother doing the only checking
935 * we could do, namely checking that the format string is
936 * valid.
938 if (vaidx < 0)
939 return;
942 * For the things we use the name of the calling function for,
943 * it is more appropriate to skip a potential SyS_ prefix; the
944 * same goes for leading underscores.
946 if (!strncmp(caller, "SyS_", 4))
947 caller += 4;
948 while (*caller == '_')
949 ++caller;
951 /* Lack of format argument is a bug. */
952 fmtexpr = get_argument_from_call_expr(callexpr->args, fmtidx);
953 if (!fmtexpr) {
954 sm_msg("error: call of '%s' with no format argument", name);
955 return;
958 do_check_printf_call(caller, name, callexpr, fmtexpr, vaidx);
962 void check_kernel_printf(int id)
964 if (option_project != PROJ_KERNEL)
965 return;
967 my_id = id;
969 #define printf_hook(func, fmt, first_to_check) \
970 add_function_hook(#func, check_printf_call, INT_PTR(fmt + (first_to_check << 8)))
972 /* Extracted using stupid perl script. */
974 #if 0
975 printf_hook(srm_printk, 1, 2); /* arch/alpha/include/asm/console.h */
976 printf_hook(die_if_kernel, 1, 2); /* arch/frv/include/asm/bug.h */
977 printf_hook(ia64_mca_printk, 1, 2); /* arch/ia64/include/asm/mca.h */
978 printf_hook(nfprint, 1, 2); /* arch/m68k/include/asm/natfeat.h */
979 printf_hook(gdbstub_printk, 1, 2); /* arch/mn10300/include/asm/gdb-stub.h */
980 printf_hook(DBG, 1, 2); /* arch/powerpc/boot/ps3.c */
981 printf_hook(printf, 1, 2); /* arch/powerpc/boot/stdio.h */
982 printf_hook(udbg_printf, 1, 2); /* arch/powerpc/include/asm/udbg.h */
983 printf_hook(__debug_sprintf_event, 3, 4); /* arch/s390/include/asm/debug.h */
984 printf_hook(__debug_sprintf_exception, 3, 4); /* arch/s390/include/asm/debug.h */
985 printf_hook(prom_printf, 1, 2); /* arch/sparc/include/asm/oplib_32.h */
987 printf_hook(fail, 1, 2); /* arch/x86/vdso/vdso2c.c */
988 #endif
990 printf_hook(_ldm_printk, 3, 4); /* block/partitions/ldm.c */
991 printf_hook(rbd_warn, 2, 3); /* drivers/block/rbd.c */
992 printf_hook(fw_err, 2, 3); /* drivers/firewire/core.h */
993 printf_hook(fw_notice, 2, 3); /* drivers/firewire/core.h */
994 printf_hook(i915_error_printf, 2, 3); /* drivers/gpu/drm/i915/i915_drv.h */
995 printf_hook(i915_handle_error, 3, 4); /* drivers/gpu/drm/i915/i915_drv.h */
996 printf_hook(nv_printk_, 3, 4); /* drivers/gpu/drm/nouveau/core/include/core/printk.h */
997 printf_hook(host1x_debug_output, 2, 3); /* drivers/gpu/host1x/debug.h */
998 printf_hook(callc_debug, 2, 3); /* drivers/isdn/hisax/callc.c */
999 printf_hook(link_debug, 3, 4); /* drivers/isdn/hisax/callc.c */
1000 printf_hook(HiSax_putstatus, 3, 4); /* drivers/isdn/hisax/hisax.h */
1001 printf_hook(VHiSax_putstatus, 3, 0); /* drivers/isdn/hisax/hisax.h */
1002 printf_hook(debugl1, 2, 3); /* drivers/isdn/hisax/isdnl1.h */
1003 printf_hook(l3m_debug, 2, 3); /* drivers/isdn/hisax/isdnl3.c */
1004 printf_hook(dout_debug, 2, 3); /* drivers/isdn/hisax/st5481_d.c */
1005 printf_hook(l1m_debug, 2, 3); /* drivers/isdn/hisax/st5481_d.c */
1006 printf_hook(bch_cache_set_error, 2, 3); /* drivers/md/bcache/bcache.h */
1007 printf_hook(_tda_printk, 4, 5); /* drivers/media/tuners/tda18271-priv.h */
1008 printf_hook(i40evf_debug_d, 3, 4); /* drivers/net/ethernet/intel/i40evf/i40e_osdep.h */
1009 printf_hook(en_print, 3, 4); /* drivers/net/ethernet/mellanox/mlx4/mlx4_en.h */
1010 printf_hook(_ath_dbg, 3, 4); /* drivers/net/wireless/ath/ath.h */
1011 printf_hook(ath_printk, 3, 4); /* drivers/net/wireless/ath/ath.h */
1012 printf_hook(ath10k_dbg, 3, 4); /* drivers/net/wireless/ath/ath10k/debug.h */
1013 printf_hook(ath10k_err, 2, 3); /* drivers/net/wireless/ath/ath10k/debug.h */
1014 printf_hook(ath10k_info, 2, 3); /* drivers/net/wireless/ath/ath10k/debug.h */
1015 printf_hook(ath10k_warn, 2, 3); /* drivers/net/wireless/ath/ath10k/debug.h */
1016 printf_hook(_ath5k_printk, 3, 4); /* drivers/net/wireless/ath/ath5k/ath5k.h */
1017 printf_hook(ATH5K_DBG, 3, 4); /* drivers/net/wireless/ath/ath5k/debug.h */
1018 printf_hook(ATH5K_DBG_UNLIMIT, 3, 4); /* drivers/net/wireless/ath/ath5k/debug.h */
1019 printf_hook(ath6kl_printk, 2, 3); /* drivers/net/wireless/ath/ath6kl/common.h */
1020 printf_hook(ath6kl_err, 1, 2); /* drivers/net/wireless/ath/ath6kl/debug.h */
1021 printf_hook(ath6kl_info, 1, 2); /* drivers/net/wireless/ath/ath6kl/debug.h */
1022 printf_hook(ath6kl_warn, 1, 2); /* drivers/net/wireless/ath/ath6kl/debug.h */
1023 printf_hook(wil_dbg_trace, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1024 printf_hook(wil_err, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1025 printf_hook(wil_err_ratelimited, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1026 printf_hook(wil_info, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1027 printf_hook(b43dbg, 2, 3); /* drivers/net/wireless/b43/b43.h */
1028 printf_hook(b43err, 2, 3); /* drivers/net/wireless/b43/b43.h */
1029 printf_hook(b43info, 2, 3); /* drivers/net/wireless/b43/b43.h */
1030 printf_hook(b43warn, 2, 3); /* drivers/net/wireless/b43/b43.h */
1031 printf_hook(b43legacydbg, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1032 printf_hook(b43legacyerr, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1033 printf_hook(b43legacyinfo, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1034 printf_hook(b43legacywarn, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1035 printf_hook(__brcmf_dbg, 3, 4); /* drivers/net/wireless/brcm80211/brcmfmac/debug.h */
1036 printf_hook(__brcmf_err, 2, 3); /* drivers/net/wireless/brcm80211/brcmfmac/debug.h */
1037 printf_hook(__brcms_crit, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1038 printf_hook(__brcms_dbg, 4, 5); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1039 printf_hook(__brcms_err, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1040 printf_hook(__brcms_info, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1041 printf_hook(__brcms_warn, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1042 printf_hook(brcmu_dbg_hex_dump, 3, 4); /* drivers/net/wireless/brcm80211/include/brcmu_utils.h */
1043 printf_hook(__iwl_crit, 2, 3); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1044 printf_hook(__iwl_dbg, 5, 6); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1045 printf_hook(__iwl_err, 4, 5); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1046 printf_hook(__iwl_info, 2, 3); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1047 printf_hook(__iwl_warn, 2, 3); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1048 printf_hook(rsi_dbg, 2, 3); /* drivers/net/wireless/rsi/rsi_main.h */
1049 printf_hook(RTPRINT, 4, 5); /* drivers/net/wireless/rtlwifi/debug.h */
1050 printf_hook(RT_ASSERT, 2, 3); /* drivers/net/wireless/rtlwifi/debug.h */
1051 printf_hook(RT_TRACE, 4, 5); /* drivers/net/wireless/rtlwifi/debug.h */
1052 printf_hook(__of_node_dup, 2, 3); /* drivers/of/of_private.h */
1053 printf_hook(BNX2FC_HBA_DBG, 2, 3); /* drivers/scsi/bnx2fc/bnx2fc_debug.h */
1054 printf_hook(BNX2FC_IO_DBG, 2, 3); /* drivers/scsi/bnx2fc/bnx2fc_debug.h */
1055 printf_hook(BNX2FC_TGT_DBG, 2, 3); /* drivers/scsi/bnx2fc/bnx2fc_debug.h */
1056 printf_hook(ql_dbg, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1057 printf_hook(ql_dbg_pci, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1058 printf_hook(ql_log, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1059 printf_hook(ql_log_pci, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1060 printf_hook(libcfs_debug_msg, 2, 3); /* drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h */
1061 printf_hook(libcfs_debug_vmsg2, 4, 5); /* drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h */
1062 printf_hook(_ldlm_lock_debug, 3, 4); /* drivers/staging/lustre/lustre/include/lustre_dlm.h */
1063 printf_hook(_debug_req, 3, 4); /* drivers/staging/lustre/lustre/include/lustre_net.h */
1064 printf_hook(iscsi_change_param_sprintf, 2, 3); /* drivers/target/iscsi/iscsi_target_login.c */
1065 printf_hook(dbg, 1, 2); /* drivers/tty/serial/samsung.c */
1066 printf_hook(_usb_stor_dbg, 2, 3); /* drivers/usb/storage/debug.h */
1067 printf_hook(usb_stor_dbg, 2, 3); /* drivers/usb/storage/debug.h */
1068 printf_hook(vringh_bad, 1, 2); /* drivers/vhost/vringh.c */
1069 printf_hook(__adfs_error, 3, 4); /* fs/adfs/adfs.h */
1070 printf_hook(affs_error, 3, 4); /* fs/affs/affs.h */
1071 printf_hook(affs_warning, 3, 4); /* fs/affs/affs.h */
1072 printf_hook(befs_debug, 2, 3); /* fs/befs/befs.h */
1073 printf_hook(befs_error, 2, 3); /* fs/befs/befs.h */
1074 printf_hook(befs_warning, 2, 3); /* fs/befs/befs.h */
1075 printf_hook(__btrfs_panic, 5, 6); /* fs/btrfs/ctree.h */
1076 printf_hook(__btrfs_std_error, 5, 6); /* fs/btrfs/ctree.h */
1077 printf_hook(btrfs_printk, 2, 3); /* fs/btrfs/ctree.h */
1078 printf_hook(cifs_vfs_err, 1, 2); /* fs/cifs/cifs_debug.h */
1079 printf_hook(__ecryptfs_printk, 1, 2); /* fs/ecryptfs/ecryptfs_kernel.h */
1080 printf_hook(ext2_error, 3, 4); /* fs/ext2/ext2.h */
1081 printf_hook(ext2_msg, 3, 4); /* fs/ext2/ext2.h */
1082 printf_hook(ext3_abort, 3, 4); /* fs/ext3/ext3.h */
1083 printf_hook(ext3_error, 3, 4); /* fs/ext3/ext3.h */
1084 printf_hook(ext3_msg, 3, 4); /* fs/ext3/ext3.h */
1085 printf_hook(ext3_warning, 3, 4); /* fs/ext3/ext3.h */
1086 printf_hook(__ext4_abort, 4, 5); /* fs/ext4/ext4.h */
1087 printf_hook(__ext4_error, 4, 5); /* fs/ext4/ext4.h */
1088 printf_hook(__ext4_error_file, 5, 6); /* fs/ext4/ext4.h */
1089 printf_hook(__ext4_error_inode, 5, 6); /* fs/ext4/ext4.h */
1090 printf_hook(__ext4_grp_locked_error, 7, 8); /* fs/ext4/ext4.h */
1091 printf_hook(__ext4_msg, 3, 4); /* fs/ext4/ext4.h */
1092 printf_hook(__ext4_warning, 4, 5); /* fs/ext4/ext4.h */
1093 printf_hook(f2fs_msg, 3, 4); /* fs/f2fs/f2fs.h */
1094 printf_hook(__fat_fs_error, 3, 4); /* fs/fat/fat.h */
1095 printf_hook(fat_msg, 3, 4); /* fs/fat/fat.h */
1096 printf_hook(gfs2_print_dbg, 2, 3); /* fs/gfs2/glock.h */
1097 printf_hook(gfs2_lm_withdraw, 2, 3); /* fs/gfs2/util.h */
1098 printf_hook(hpfs_error, 2, 3); /* fs/hpfs/hpfs_fn.h */
1099 printf_hook(jfs_error, 2, 3); /* fs/jfs/jfs_superblock.h */
1100 printf_hook(nilfs_error, 3, 4); /* fs/nilfs2/nilfs.h */
1101 printf_hook(nilfs_warning, 3, 4); /* fs/nilfs2/nilfs.h */
1102 printf_hook(__ntfs_debug, 4, 5); /* fs/ntfs/debug.h */
1103 printf_hook(__ntfs_error, 3, 4); /* fs/ntfs/debug.h */
1104 printf_hook(__ntfs_warning, 3, 4); /* fs/ntfs/debug.h */
1105 printf_hook(__ocfs2_abort, 3, 4); /* fs/ocfs2/super.h */
1106 printf_hook(__ocfs2_error, 3, 4); /* fs/ocfs2/super.h */
1107 printf_hook(_udf_err, 3, 4); /* fs/udf/udfdecl.h */
1108 printf_hook(_udf_warn, 3, 4); /* fs/udf/udfdecl.h */
1109 printf_hook(ufs_error, 3, 4); /* fs/ufs/ufs.h */
1110 printf_hook(ufs_panic, 3, 4); /* fs/ufs/ufs.h */
1111 printf_hook(ufs_warning, 3, 4); /* fs/ufs/ufs.h */
1112 printf_hook(xfs_alert, 2, 3); /* fs/xfs/xfs_message.h */
1113 printf_hook(xfs_alert_tag, 3, 4); /* fs/xfs/xfs_message.h */
1114 printf_hook(xfs_crit, 2, 3); /* fs/xfs/xfs_message.h */
1115 printf_hook(xfs_debug, 2, 3); /* fs/xfs/xfs_message.h */
1116 printf_hook(xfs_emerg, 2, 3); /* fs/xfs/xfs_message.h */
1117 printf_hook(xfs_err, 2, 3); /* fs/xfs/xfs_message.h */
1118 printf_hook(xfs_info, 2, 3); /* fs/xfs/xfs_message.h */
1119 printf_hook(xfs_notice, 2, 3); /* fs/xfs/xfs_message.h */
1120 printf_hook(xfs_warn, 2, 3); /* fs/xfs/xfs_message.h */
1121 printf_hook(warn_slowpath_fmt, 3, 4); /* include/asm-generic/bug.h */
1122 printf_hook(warn_slowpath_fmt_taint, 4, 5); /* include/asm-generic/bug.h */
1123 printf_hook(drm_err, 1, 2); /* include/drm/drmP.h */
1124 printf_hook(drm_ut_debug_printk, 2, 3); /* include/drm/drmP.h */
1125 printf_hook(__acpi_handle_debug, 3, 4); /* include/linux/acpi.h */
1126 printf_hook(acpi_handle_printk, 3, 4); /* include/linux/acpi.h */
1127 printf_hook(audit_log, 4, 5); /* include/linux/audit.h */
1128 printf_hook(audit_log_format, 2, 3); /* include/linux/audit.h */
1129 printf_hook(bdi_register, 3, 4); /* include/linux/backing-dev.h */
1130 printf_hook(__trace_note_message, 2, 3); /* include/linux/blktrace_api.h */
1131 printf_hook(_dev_info, 2, 3); /* include/linux/device.h */
1132 printf_hook(dev_alert, 2, 3); /* include/linux/device.h */
1133 printf_hook(dev_crit, 2, 3); /* include/linux/device.h */
1134 printf_hook(dev_emerg, 2, 3); /* include/linux/device.h */
1135 printf_hook(dev_err, 2, 3); /* include/linux/device.h */
1136 printf_hook(dev_notice, 2, 3); /* include/linux/device.h */
1137 printf_hook(dev_printk, 3, 4); /* include/linux/device.h */
1138 printf_hook(dev_printk_emit, 3, 4); /* include/linux/device.h */
1139 printf_hook(dev_set_name, 2, 3); /* include/linux/device.h */
1140 printf_hook(dev_vprintk_emit, 3, 0); /* include/linux/device.h */
1141 printf_hook(dev_warn, 2, 3); /* include/linux/device.h */
1142 printf_hook(device_create, 5, 6); /* include/linux/device.h */
1143 printf_hook(device_create_with_groups, 6, 7); /* include/linux/device.h */
1144 printf_hook(devm_kasprintf, 3, 4); /* include/linux/device.h */
1145 printf_hook(__dynamic_dev_dbg, 3, 4); /* include/linux/dynamic_debug.h */
1146 printf_hook(__dynamic_netdev_dbg, 3, 4); /* include/linux/dynamic_debug.h */
1147 printf_hook(__dynamic_pr_debug, 2, 3); /* include/linux/dynamic_debug.h */
1148 printf_hook(__simple_attr_check_format, 1, 2); /* include/linux/fs.h */
1149 printf_hook(fscache_init_cache, 3, 4); /* include/linux/fscache-cache.h */
1150 printf_hook(gameport_set_phys, 2, 3); /* include/linux/gameport.h */
1151 printf_hook(iio_trigger_alloc, 1, 2); /* include/linux/iio/trigger.h */
1152 printf_hook(__check_printsym_format, 1, 2); /* include/linux/kallsyms.h */
1153 printf_hook(kdb_printf, 1, 2); /* include/linux/kdb.h */
1154 printf_hook(vkdb_printf, 1, 0); /* include/linux/kdb.h */
1155 printf_hook(____trace_printk_check_format, 1, 2); /* include/linux/kernel.h */
1156 printf_hook(__trace_bprintk, 2, 3); /* include/linux/kernel.h */
1157 printf_hook(__trace_printk, 2, 3); /* include/linux/kernel.h */
1158 printf_hook(kasprintf, 2, 3); /* include/linux/kernel.h */
1159 printf_hook(panic, 1, 2); /* include/linux/kernel.h */
1160 printf_hook(scnprintf, 3, 4); /* include/linux/kernel.h */
1161 printf_hook(snprintf, 3, 4); /* include/linux/kernel.h */
1162 printf_hook(sprintf, 2, 3); /* include/linux/kernel.h */
1163 printf_hook(trace_printk, 1, 2); /* include/linux/kernel.h */
1164 printf_hook(vscnprintf, 3, 0); /* include/linux/kernel.h */
1165 printf_hook(vsnprintf, 3, 0); /* include/linux/kernel.h */
1166 printf_hook(vsprintf, 2, 0); /* include/linux/kernel.h */
1167 printf_hook(vmcoreinfo_append_str, 1, 2); /* include/linux/kexec.h */
1168 printf_hook(__request_module, 2, 3); /* include/linux/kmod.h */
1169 printf_hook(add_uevent_var, 2, 3); /* include/linux/kobject.h */
1170 printf_hook(kobject_add, 3, 4); /* include/linux/kobject.h */
1171 printf_hook(kobject_init_and_add, 4, 5); /* include/linux/kobject.h */
1172 printf_hook(kobject_set_name, 2, 3); /* include/linux/kobject.h */
1173 printf_hook(kthread_create_on_node, 4, 5); /* include/linux/kthread.h */
1174 printf_hook(__ata_ehi_push_desc, 2, 3); /* include/linux/libata.h */
1175 printf_hook(ata_dev_printk, 3, 4); /* include/linux/libata.h */
1176 printf_hook(ata_ehi_push_desc, 2, 3); /* include/linux/libata.h */
1177 printf_hook(ata_link_printk, 3, 4); /* include/linux/libata.h */
1178 printf_hook(ata_port_desc, 2, 3); /* include/linux/libata.h */
1179 printf_hook(ata_port_printk, 3, 4); /* include/linux/libata.h */
1180 printf_hook(warn_alloc_failed, 3, 4); /* include/linux/mm.h */
1181 printf_hook(mmiotrace_printk, 1, 2); /* include/linux/mmiotrace.h */
1182 printf_hook(netdev_alert, 2, 3); /* include/linux/netdevice.h */
1183 printf_hook(netdev_crit, 2, 3); /* include/linux/netdevice.h */
1184 printf_hook(netdev_emerg, 2, 3); /* include/linux/netdevice.h */
1185 printf_hook(netdev_err, 2, 3); /* include/linux/netdevice.h */
1186 printf_hook(netdev_info, 2, 3); /* include/linux/netdevice.h */
1187 printf_hook(netdev_notice, 2, 3); /* include/linux/netdevice.h */
1188 printf_hook(netdev_printk, 3, 4); /* include/linux/netdevice.h */
1189 printf_hook(netdev_warn, 2, 3); /* include/linux/netdevice.h */
1190 printf_hook(early_printk, 1, 2); /* include/linux/printk.h */
1191 printf_hook(no_printk, 1, 2); /* include/linux/printk.h */
1192 printf_hook(printk, 1, 2); /* include/linux/printk.h */
1193 printf_hook(printk_deferred, 1, 2); /* include/linux/printk.h */
1194 printf_hook(printk_emit, 5, 6); /* include/linux/printk.h */
1195 printf_hook(vprintk, 1, 0); /* include/linux/printk.h */
1196 printf_hook(vprintk_emit, 5, 0); /* include/linux/printk.h */
1197 printf_hook(__quota_error, 3, 4); /* include/linux/quotaops.h */
1198 printf_hook(seq_buf_printf, 2, 3); /* include/linux/seq_buf.h */
1199 printf_hook(seq_buf_vprintf, 2, 0); /* include/linux/seq_buf.h */
1200 printf_hook(seq_printf, 2, 3); /* include/linux/seq_file.h */
1201 printf_hook(seq_vprintf, 2, 0); /* include/linux/seq_file.h */
1202 printf_hook(bprintf, 3, 4); /* include/linux/string.h */
1203 printf_hook(trace_seq_printf, 2, 3); /* include/linux/trace_seq.h */
1204 printf_hook(trace_seq_vprintf, 2, 0); /* include/linux/trace_seq.h */
1205 printf_hook(__alloc_workqueue_key, 1, 6); /* include/linux/workqueue.h */
1206 printf_hook(set_worker_desc, 1, 2); /* include/linux/workqueue.h */
1207 printf_hook(_p9_debug, 3, 4); /* include/net/9p/9p.h */
1208 printf_hook(bt_err, 1, 2); /* include/net/bluetooth/bluetooth.h */
1209 printf_hook(bt_info, 1, 2); /* include/net/bluetooth/bluetooth.h */
1210 printf_hook(nf_ct_helper_log, 3, 4); /* include/net/netfilter/nf_conntrack_helper.h */
1211 printf_hook(nf_log_buf_add, 2, 3); /* include/net/netfilter/nf_log.h */
1212 printf_hook(nf_log_packet, 8, 9); /* include/net/netfilter/nf_log.h */
1213 printf_hook(SOCK_DEBUG, 2, 3); /* include/net/sock.h */
1214 printf_hook(__snd_printk, 4, 5); /* include/sound/core.h */
1215 printf_hook(_snd_printd, 2, 3); /* include/sound/core.h */
1216 printf_hook(snd_printd, 1, 2); /* include/sound/core.h */
1217 printf_hook(snd_printdd, 1, 2); /* include/sound/core.h */
1218 printf_hook(snd_iprintf, 2, 3); /* include/sound/info.h */
1219 printf_hook(snd_seq_create_kernel_client, 3, 4); /* include/sound/seq_kernel.h */
1220 printf_hook(xen_raw_printk, 1, 2); /* include/xen/hvc-console.h */
1221 printf_hook(xenbus_dev_error, 3, 4); /* include/xen/xenbus.h */
1222 printf_hook(xenbus_dev_fatal, 3, 4); /* include/xen/xenbus.h */
1223 printf_hook(xenbus_printf, 4, 5); /* include/xen/xenbus.h */
1224 printf_hook(xenbus_watch_pathfmt, 4, 5); /* include/xen/xenbus.h */
1225 printf_hook(batadv_fdebug_log, 2, 3); /* net/batman-adv/debugfs.c */
1226 printf_hook(_batadv_dbg, 4, 5); /* net/batman-adv/main.h */
1227 printf_hook(batadv_debug_log, 2, 3); /* net/batman-adv/main.h */
1228 printf_hook(__sdata_dbg, 2, 3); /* net/mac80211/debug.h */
1229 printf_hook(__sdata_err, 1, 2); /* net/mac80211/debug.h */
1230 printf_hook(__sdata_info, 1, 2); /* net/mac80211/debug.h */
1231 printf_hook(__wiphy_dbg, 3, 4); /* net/mac80211/debug.h */
1232 printf_hook(mac80211_format_buffer, 4, 5); /* net/mac80211/debugfs.h */
1233 printf_hook(__rds_conn_error, 2, 3); /* net/rds/rds.h */
1234 printf_hook(rdsdebug, 1, 2); /* net/rds/rds.h */
1235 printf_hook(printl, 1, 2); /* net/sctp/probe.c */
1236 printf_hook(svc_printk, 2, 3); /* net/sunrpc/svc.c */
1237 printf_hook(tomoyo_io_printf, 2, 3); /* security/tomoyo/common.c */
1238 printf_hook(tomoyo_supervisor, 2, 3); /* security/tomoyo/common.h */
1239 printf_hook(tomoyo_write_log, 2, 3); /* security/tomoyo/common.h */
1240 printf_hook(cmp_error, 2, 3); /* sound/firewire/cmp.c */