extra, db: don't use PARAM_VALUE for return states
[smatch.git] / check_kernel_printf.c
blob4a4ee711f02744e6ea90b4b5a5bd6314d31f1c2e
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"
22 #include "smatch_slist.h"
24 #define spam(args...) do { \
25 if (option_spammy) \
26 sm_msg(args); \
27 } while (0)
29 static int my_id;
32 * Much of this is taken directly from the kernel (mostly vsprintf.c),
33 * with a few modifications here and there.
36 #define KERN_SOH_ASCII '\001'
38 typedef unsigned char u8;
39 typedef signed short s16;
41 #define ZEROPAD 1 /* pad with zero */
42 #define SIGN 2 /* unsigned/signed long */
43 #define PLUS 4 /* show plus */
44 #define SPACE 8 /* space if plus */
45 #define LEFT 16 /* left justified */
46 #define SMALL 32 /* use lowercase in hex (must be 32 == 0x20) */
47 #define SPECIAL 64 /* prefix hex with "0x", octal with "0" */
49 enum format_type {
50 FORMAT_TYPE_NONE, /* Just a string part */
51 FORMAT_TYPE_WIDTH,
52 FORMAT_TYPE_PRECISION,
53 FORMAT_TYPE_CHAR,
54 FORMAT_TYPE_STR,
55 FORMAT_TYPE_PTR,
56 FORMAT_TYPE_PERCENT_CHAR,
57 FORMAT_TYPE_INVALID,
58 FORMAT_TYPE_LONG_LONG,
59 FORMAT_TYPE_ULONG,
60 FORMAT_TYPE_LONG,
61 FORMAT_TYPE_UBYTE,
62 FORMAT_TYPE_BYTE,
63 FORMAT_TYPE_USHORT,
64 FORMAT_TYPE_SHORT,
65 FORMAT_TYPE_UINT,
66 FORMAT_TYPE_INT,
67 FORMAT_TYPE_SIZE_T,
68 FORMAT_TYPE_PTRDIFF,
69 FORMAT_TYPE_NRCHARS, /* Reintroduced for this checker */
70 FORMAT_TYPE_FLOAT, /* for various floating point formatters */
73 struct printf_spec {
74 u8 type; /* format_type enum */
75 u8 flags; /* flags to number() */
76 u8 base; /* number base, 8, 10 or 16 only */
77 u8 qualifier; /* number qualifier, one of 'hHlLtzZ' */
78 s16 field_width; /* width of output field */
79 s16 precision; /* # of digits/chars */
82 static int
83 skip_atoi(const char **s)
85 int i = 0;
87 while (isdigit(**s))
88 i = i*10 + *((*s)++) - '0';
90 return i;
93 static int
94 format_decode(const char *fmt, struct printf_spec *spec)
96 const char *start = fmt;
98 /* we finished early by reading the field width */
99 if (spec->type == FORMAT_TYPE_WIDTH) {
100 if (spec->field_width < 0) {
101 spec->field_width = -spec->field_width;
102 spec->flags |= LEFT;
104 spec->type = FORMAT_TYPE_NONE;
105 goto precision;
108 /* we finished early by reading the precision */
109 if (spec->type == FORMAT_TYPE_PRECISION) {
110 if (spec->precision < 0)
111 spec->precision = 0;
113 spec->type = FORMAT_TYPE_NONE;
114 goto qualifier;
117 /* By default */
118 spec->type = FORMAT_TYPE_NONE;
120 for (; *fmt ; ++fmt) {
121 if (*fmt == '%')
122 break;
125 /* Return the current non-format string */
126 if (fmt != start || !*fmt)
127 return fmt - start;
129 /* Process flags */
130 spec->flags = 0;
132 while (1) { /* this also skips first '%' */
133 bool found = true;
135 ++fmt;
137 switch (*fmt) {
138 case '-': spec->flags |= LEFT; break;
139 case '+': spec->flags |= PLUS; break;
140 case ' ': spec->flags |= SPACE; break;
141 case '#': spec->flags |= SPECIAL; break;
142 case '0': spec->flags |= ZEROPAD; break;
143 default: found = false;
146 if (!found)
147 break;
150 /* get field width */
151 spec->field_width = -1;
153 if (isdigit(*fmt))
154 spec->field_width = skip_atoi(&fmt);
155 else if (*fmt == '*') {
156 /* it's the next argument */
157 spec->type = FORMAT_TYPE_WIDTH;
158 return ++fmt - start;
161 precision:
162 /* get the precision */
163 spec->precision = -1;
164 if (*fmt == '.') {
165 ++fmt;
166 if (isdigit(*fmt)) {
167 spec->precision = skip_atoi(&fmt);
168 if (spec->precision < 0)
169 spec->precision = 0;
170 } else if (*fmt == '*') {
171 /* it's the next argument */
172 spec->type = FORMAT_TYPE_PRECISION;
173 return ++fmt - start;
177 qualifier:
178 /* get the conversion qualifier */
179 spec->qualifier = 0;
180 if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
181 _tolower(*fmt) == 'z' || *fmt == 't') {
182 spec->qualifier = *fmt++;
183 if (spec->qualifier == *fmt) {
184 if (spec->qualifier == 'l') {
185 spec->qualifier = 'L';
186 ++fmt;
187 } else if (spec->qualifier == 'h') {
188 spec->qualifier = 'H';
189 ++fmt;
190 } else {
191 sm_msg("warn: invalid repeated qualifier '%c'", *fmt);
196 /* default base */
197 spec->base = 10;
198 switch (*fmt) {
199 case 'c':
200 spec->type = FORMAT_TYPE_CHAR;
201 return ++fmt - start;
203 case 's':
204 spec->type = FORMAT_TYPE_STR;
205 return ++fmt - start;
207 case 'p':
208 spec->type = FORMAT_TYPE_PTR;
209 return ++fmt - start;
211 case '%':
212 spec->type = FORMAT_TYPE_PERCENT_CHAR;
213 return ++fmt - start;
215 /* integer number formats - set up the flags and "break" */
216 case 'o':
217 spec->base = 8;
218 break;
220 case 'x':
221 spec->flags |= SMALL;
223 case 'X':
224 spec->base = 16;
225 break;
227 case 'd':
228 case 'i':
229 spec->flags |= SIGN;
230 case 'u':
231 break;
233 case 'n':
234 spec->type = FORMAT_TYPE_NRCHARS;
235 return ++fmt - start;
237 case 'a': case 'A':
238 case 'e': case 'E':
239 case 'f': case 'F':
240 case 'g': case 'G':
241 spec->type = FORMAT_TYPE_FLOAT;
242 return ++fmt - start;
244 default:
245 spec->type = FORMAT_TYPE_INVALID;
246 /* Unlike the kernel code, we 'consume' the invalid
247 * character so that it can get included in the
248 * report. After that, we bail out. */
249 return ++fmt - start;
252 if (spec->qualifier == 'L')
253 spec->type = FORMAT_TYPE_LONG_LONG;
254 else if (spec->qualifier == 'l') {
255 if (spec->flags & SIGN)
256 spec->type = FORMAT_TYPE_LONG;
257 else
258 spec->type = FORMAT_TYPE_ULONG;
259 } else if (_tolower(spec->qualifier) == 'z') {
260 spec->type = FORMAT_TYPE_SIZE_T;
261 } else if (spec->qualifier == 't') {
262 spec->type = FORMAT_TYPE_PTRDIFF;
263 } else if (spec->qualifier == 'H') {
264 if (spec->flags & SIGN)
265 spec->type = FORMAT_TYPE_BYTE;
266 else
267 spec->type = FORMAT_TYPE_UBYTE;
268 } else if (spec->qualifier == 'h') {
269 if (spec->flags & SIGN)
270 spec->type = FORMAT_TYPE_SHORT;
271 else
272 spec->type = FORMAT_TYPE_USHORT;
273 } else {
274 if (spec->flags & SIGN)
275 spec->type = FORMAT_TYPE_INT;
276 else
277 spec->type = FORMAT_TYPE_UINT;
280 return ++fmt - start;
283 static int is_struct_tag(struct symbol *type, const char *tag)
285 return type->type == SYM_STRUCT && type->ident && !strcmp(type->ident->name, tag);
288 static int has_struct_tag(struct symbol *type, const char *tag)
290 struct symbol *tmp;
292 if (type->type == SYM_STRUCT)
293 return is_struct_tag(type, tag);
294 if (type->type == SYM_UNION) {
295 FOR_EACH_PTR(type->symbol_list, tmp) {
296 tmp = get_real_base_type(tmp);
297 if (tmp && is_struct_tag(tmp, tag))
298 return 1;
299 } END_FOR_EACH_PTR(tmp);
301 return 0;
304 static int is_char_type(struct symbol *type)
306 return type == &uchar_ctype || type == &char_ctype || type == &schar_ctype;
310 * I have absolutely no idea if this is how one is supposed to get the
311 * symbol representing a typedef, but it seems to work.
313 struct typedef_lookup {
314 const char *name;
315 struct symbol *sym;
316 int failed;
319 static struct symbol *_typedef_lookup(const char *name)
321 struct ident *id;
322 struct symbol *node;
324 id = built_in_ident(name);
325 if (!id)
326 return NULL;
327 node = lookup_symbol(id, NS_TYPEDEF);
328 if (!node || node->type != SYM_NODE)
329 return NULL;
330 return node->ctype.base_type;
333 static void typedef_lookup(struct typedef_lookup *tl)
335 if (tl->sym || tl->failed)
336 return;
337 tl->sym = _typedef_lookup(tl->name);
338 if (!tl->sym) {
339 sm_msg("internal error: could not find typedef '%s'", tl->name);
340 tl->failed = 1;
345 static void ip4(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
347 enum { ENDIAN_BIG, ENDIAN_LITTLE, ENDIAN_HOST } endian = ENDIAN_BIG;
349 assert(fmt[0] == 'i' || fmt[0] == 'I');
350 assert(fmt[1] == '4');
352 if (isalnum(fmt[2])) {
353 switch (fmt[2]) {
354 case 'h':
355 endian = ENDIAN_HOST;
356 break;
357 case 'l':
358 endian = ENDIAN_LITTLE;
359 break;
360 case 'n':
361 case 'b':
362 endian = ENDIAN_BIG;
363 break;
364 default:
365 sm_msg("warn: '%%p%c4' can only be followed by one of [hnbl], not '%c'", fmt[0], fmt[2]);
367 if (isalnum(fmt[3]))
368 sm_msg("warn: '%%p%c4' can only be followed by precisely one of [hnbl]", fmt[0]);
372 if (type->ctype.modifiers & MOD_NODEREF)
373 sm_msg("error: passing __user pointer to '%%p%c4'", fmt[0]);
376 * If we have a pointer to char/u8/s8, we expect the caller to
377 * handle endianness; I don't think there's anything we can
378 * do. I'd like to check that if we're passed a pointer to a
379 * __bitwise u32 (most likely a __be32), we should have endian
380 * == ENDIAN_BIG. But I can't figure out how to get that
381 * information (it also seems to require ensuring certain
382 * macros are defined). But struct in_addr certainly consists
383 * of only a single __be32, so in that case we can do a check.
385 if (is_char_type(basetype))
386 return;
388 if (is_struct_tag(basetype, "in_addr") && endian != ENDIAN_BIG)
389 sm_msg("warn: passing struct in_addr* to '%%p%c4%c', is the endianness ok?", fmt[0], fmt[2]);
391 /* ... */
394 static void ip6(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
396 assert(fmt[0] == 'i' || fmt[0] == 'I');
397 assert(fmt[1] == '6');
399 if (isalnum(fmt[2])) {
400 if (fmt[2] != 'c')
401 sm_msg("warn: '%%p%c6' can only be followed by c", fmt[0]);
402 else if (fmt[0] == 'i')
403 sm_msg("warn: '%%pi6' does not allow flag c");
404 if (isalnum(fmt[3]))
405 sm_msg("warn: '%%p%c6%c' cannot be followed by other alphanumerics", fmt[0], fmt[2]);
408 if (type->ctype.modifiers & MOD_NODEREF)
409 sm_msg("error: passing __user pointer to '%%p%c6'", fmt[0]);
412 static void ipS(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
414 const char *f;
416 assert(tolower(fmt[0]) == 'i');
417 assert(fmt[1] == 'S');
419 for (f = fmt+2; isalnum(*f); ++f) {
420 /* It's probably too anal checking for duplicate flags. */
421 if (!strchr("pfschnbl", *f))
422 sm_msg("warn: '%%p%cS' cannot be followed by '%c'", fmt[0], *f);
426 * XXX: Should we also allow passing a pointer to a union, one
427 * member of which is a struct sockaddr? It may be slightly
428 * cleaner actually passing &u.raw instead of just &u, though
429 * the generated code is of course exactly the same. For now,
430 * we do accept struct sockaddr_in and struct sockaddr_in6,
431 * since those are easy to handle and rather harmless.
433 if (!has_struct_tag(basetype, "sockaddr") &&
434 !has_struct_tag(basetype, "sockaddr_in") &&
435 !has_struct_tag(basetype, "sockaddr_in6"))
436 sm_msg("error: '%%p%cS' expects argument of type struct sockaddr *, "
437 "argument %d has type '%s'", fmt[0], vaidx, type_to_str(type));
440 static void hex_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
442 assert(fmt[0] == 'h');
443 if (isalnum(fmt[1])) {
444 if (!strchr("CDN", fmt[1]))
445 sm_msg("warn: '%%ph' cannot be followed by '%c'", fmt[1]);
446 if (isalnum(fmt[2]))
447 sm_msg("warn: '%%ph' can be followed by at most one of [CDN], and no other alphanumerics");
449 if (type->ctype.modifiers & MOD_NODEREF)
450 sm_msg("error: passing __user pointer to %%ph");
453 static void escaped_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
455 assert(fmt[0] == 'E');
456 while (isalnum(*++fmt)) {
457 if (!strchr("achnops", *fmt))
458 sm_msg("warn: %%pE can only be followed by a combination of [achnops]");
460 if (type->ctype.modifiers & MOD_NODEREF)
461 sm_msg("error: passing __user pointer to %%pE");
464 static void resource_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
466 assert(tolower(fmt[0]) == 'r');
467 if (!is_struct_tag(basetype, "resource")) {
468 sm_msg("error: '%%p%c' expects argument of type struct resource *, "
469 "but argument %d has type '%s'", fmt[0], vaidx, type_to_str(type));
471 if (isalnum(fmt[1]))
472 sm_msg("warn: '%%p%c' cannot be followed by '%c'", fmt[0], fmt[1]);
475 static void mac_address_string(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
477 assert(tolower(fmt[0]) == 'm');
478 if (isalnum(fmt[1])) {
479 if (!(fmt[1] == 'F' || fmt[1] == 'R'))
480 sm_msg("warn: '%%p%c' cannot be followed by '%c'", fmt[0], fmt[1]);
481 if (fmt[0] == 'm' && fmt[1] == 'F')
482 sm_msg("warn: it is pointless to pass flag F to %%pm");
483 if (isalnum(fmt[2]))
484 sm_msg("warn: '%%p%c%c' cannot be followed by other alphanumeric", fmt[0], fmt[1]);
486 /* Technically, bdaddr_t is a typedef for an anonymous struct, but this still seems to work. */
487 if (!is_char_type(basetype) && !is_struct_tag(basetype, "bdaddr_t") && basetype != &void_ctype) {
488 sm_msg("warn: '%%p%c' expects argument of type u8 * or bdaddr_t *, argument %d has type '%s'",
489 fmt[0], vaidx, type_to_str(type));
491 if (type->ctype.modifiers & MOD_NODEREF)
492 sm_msg("error: passing __user pointer to '%%p%c'", fmt[0]);
495 static void dentry_file(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
497 const char *tag;
499 assert(tolower(fmt[0]) == 'd');
500 tag = fmt[0] == 'd' ? "dentry" : "file";
502 if (isalnum(fmt[1])) {
503 if (!strchr("234", fmt[1]))
504 sm_msg("warn: '%%p%c' can only be followed by one of [234]", fmt[0]);
505 if (isalnum(fmt[2]))
506 sm_msg("warn: '%%p%c%c' cannot be followed by '%c'", fmt[0], fmt[1], fmt[2]);
509 if (!is_struct_tag(basetype, tag))
510 sm_msg("error: '%%p%c' expects argument of type struct '%s*', argument %d has type '%s'",
511 fmt[0], tag, vaidx, type_to_str(type));
514 static void va_format(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
516 assert(fmt[0] == 'V');
517 if (isalnum(fmt[1]))
518 sm_msg("warn: %%pV cannot be followed by any alphanumerics");
519 if (!is_struct_tag(basetype, "va_format"))
520 sm_msg("error: %%pV expects argument of type struct va_format*, argument %d has type '%s'", vaidx, type_to_str(type));
523 static void netdev_feature(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
525 static struct typedef_lookup netdev = { .name = "netdev_features_t" };
527 assert(fmt[0] == 'N');
528 if (fmt[1] != 'F') {
529 sm_msg("error: %%pN must be followed by 'F'");
530 return;
532 if (isalnum(fmt[2]))
533 sm_msg("warn: %%pNF cannot be followed by '%c'", fmt[2]);
535 typedef_lookup(&netdev);
536 if (!netdev.sym)
537 return;
538 if (basetype != netdev.sym)
539 sm_msg("error: %%pNF expects argument of type netdev_features_t*, argument %d has type '%s'",
540 vaidx, type_to_str(type));
543 static void address_val(const char *fmt, struct symbol *type, struct symbol *basetype, int vaidx)
545 static struct typedef_lookup dma = { .name = "dma_addr_t" };
546 static struct typedef_lookup phys = { .name = "phys_addr_t" };
547 struct typedef_lookup *which = &phys;
548 const char *suf = "";
549 assert(fmt[0] == 'a');
551 if (isalnum(fmt[1])) {
552 switch (fmt[1]) {
553 case 'd':
554 which = &dma;
555 suf = "d";
556 break;
557 case 'p':
558 suf = "p";
559 break;
560 default:
561 sm_msg("error: '%%pa' can only be followed by one of [dp]");
563 if (isalnum(fmt[2]))
564 sm_msg("error: '%%pa%c' cannot be followed by '%c'", fmt[1], fmt[2]);
567 typedef_lookup(which);
568 if (!which->sym)
569 return;
570 if (basetype != which->sym) {
571 sm_msg("error: '%%pa%s' expects argument of type '%s*', argument %d has type '%s'",
572 suf, which->name, vaidx, type_to_str(type));
576 static void
577 pointer(const char *fmt, struct expression *arg, int vaidx)
579 struct symbol *type, *basetype;
581 type = get_type(arg);
582 if (!type) {
583 sm_msg("warn: could not determine type of argument %d", vaidx);
584 return;
586 if (!is_ptr_type(type)) {
587 sm_msg("error: %%p expects pointer argument, but argument %d has type '%s'",
588 vaidx, type_to_str(type));
589 return;
591 /* Just plain %p, nothing to check. */
592 if (!isalnum(*fmt))
593 return;
595 basetype = get_real_base_type(type);
597 * Passing a pointer-to-array is harmless, but most likely one
598 * meant to pass pointer-to-first-element. If basetype is
599 * array type, we issue a notice and "dereference" the types
600 * once more.
602 if (basetype->type == SYM_ARRAY) {
603 spam("note: passing pointer-to-array; is the address-of redundant?");
604 type = basetype;
605 basetype = get_real_base_type(type);
609 * We pass both the type and the basetype to the helpers. If,
610 * for example, the pointer is really a decayed array which is
611 * passed to %pI4, we might want to check that it is in fact
612 * an array of four bytes. But most are probably only
613 * interested in whether the basetype makes sense. Also, the
614 * pointer may carry some annotation such as __user which
615 * might be worth checking in the handlers which actually
616 * dereference the pointer.
619 switch (*fmt) {
620 case 'b':
621 case 'F':
622 case 'f':
623 case 'S':
624 case 's':
625 case 'B':
626 /* Can we do anything sensible? Check that the arg is a function pointer, for example? */
627 break;
629 case 'R':
630 case 'r':
631 resource_string(fmt, type, basetype, vaidx);
632 break;
633 case 'M':
634 case 'm':
635 mac_address_string(fmt, type, basetype, vaidx);
636 break;
637 case 'I':
638 case 'i':
639 switch (fmt[1]) {
640 case '4':
641 ip4(fmt, type, basetype, vaidx);
642 break;
643 case '6':
644 ip6(fmt, type, basetype, vaidx);
645 break;
646 case 'S':
647 ipS(fmt, type, basetype, vaidx);
648 break;
649 default:
650 sm_msg("warn: '%%p%c' must be followed by one of [46S]", fmt[0]);
651 break;
653 break;
655 * %pE and %ph can handle any valid pointer. We still check
656 * whether all the subsequent alphanumerics are valid for the
657 * particular %pX conversion.
659 case 'E':
660 escaped_string(fmt, type, basetype, vaidx);
661 break;
662 case 'h':
663 hex_string(fmt, type, basetype, vaidx);
664 break;
665 case 'U': /* TODO */
666 break;
667 case 'V':
668 va_format(fmt, type, basetype, vaidx);
669 break;
670 case 'K': /* TODO */
671 break;
672 case 'N':
673 netdev_feature(fmt, type, basetype, vaidx);
674 break;
675 case 'a':
676 address_val(fmt, type, basetype, vaidx);
677 break;
678 case 'D':
679 case 'd':
680 dentry_file(fmt, type, basetype, vaidx);
681 break;
682 default:
683 sm_msg("error: unrecognized %%p extension '%c', treated as normal %%p", *fmt);
687 static int
688 check_format_string(const char *fmt, const char *caller)
690 const char *f;
692 for (f = fmt; *f; ++f) {
693 unsigned char c = *f;
694 switch (c) {
695 case KERN_SOH_ASCII:
697 * This typically arises from bad conversion
698 * to pr_*, e.g. pr_warn(KERN_WARNING "something").
700 if (f != fmt)
701 sm_msg("warn: KERN_* level not at start of string");
703 * In a very few cases, the level is actually
704 * computed and passed via %c, as in KERN_SOH
705 * "%c...". printk explicitly supports
706 * this.
708 if (!(('0' <= f[1] && f[1] <= '7') || f[1] == 'd'))
709 sm_msg("warn: invalid KERN_* level: KERN_SOH_ASCII followed by '\\x%02x'", (unsigned char)f[1]);
710 break;
711 case '\t':
712 case '\n':
713 case '\r':
714 case 0x20 ... 0x7e:
715 break;
716 case 0x80 ... 0xff:
717 sm_msg("warn: format string contains non-ascii character '\\x%02x'", c);
718 break;
719 case 0x08:
720 if (f == fmt)
721 break;
722 /* fall through */
723 default:
724 sm_msg("warn: format string contains unusual character '\\x%02x'", c);
725 break;
729 f = strstr(fmt, caller);
730 if (f && strstr(f+1, caller))
731 sm_msg("note: format string contains name of enclosing function '%s' twice", caller);
733 return f != NULL;
736 static int arg_is___func__(struct expression *arg)
738 if (arg->type != EXPR_SYMBOL)
739 return 0;
740 return !strcmp(arg->symbol_name->name, "__func__") ||
741 !strcmp(arg->symbol_name->name, "__FUNCTION__") ||
742 !strcmp(arg->symbol_name->name, "__PRETTY_FUNCTION__");
744 static int arg_contains_caller(struct expression *arg, const char *caller)
746 if (arg->type != EXPR_STRING)
747 return 0;
748 return strstr(arg->string->data, caller) != NULL;
751 static int is_array_of_const_char(struct symbol *sym)
753 struct symbol *base = sym->ctype.base_type;
754 if (base->type != SYM_ARRAY)
755 return 0;
756 if (!(base->ctype.modifiers & MOD_CONST))
757 return 0;
758 if (!is_char_type(base->ctype.base_type)) {
759 spam("weird: format argument is array of const '%s'", type_to_str(base->ctype.base_type));
760 return 0;
762 return 1;
765 static int is_const_pointer_to_const_char(struct symbol *sym)
767 struct symbol *base = sym->ctype.base_type;
768 if (!(sym->ctype.modifiers & MOD_CONST))
769 return 0;
770 if (base->type != SYM_PTR)
771 return 0;
772 if (!(base->ctype.modifiers & MOD_CONST))
773 return 0;
774 if (!is_char_type(base->ctype.base_type)) {
775 spam("weird: format argument is pointer to const '%s'", type_to_str(base->ctype.base_type));
776 return 0;
778 return 1;
781 static int unknown_format(struct expression *expr)
783 struct state_list *slist;
785 slist = get_strings(expr);
786 if (!slist)
787 return 1;
788 if (slist_has_state(slist, &undefined))
789 return 1;
790 free_slist(&slist);
791 return 0;
794 static void
795 do_check_printf_call(const char *caller, const char *name, struct expression *callexpr, struct expression *fmtexpr, int vaidx)
797 struct printf_spec spec = {0};
798 const char *fmt;
799 int caller_in_fmt;
801 fmtexpr = strip_parens(fmtexpr);
802 if (fmtexpr->type == EXPR_CONDITIONAL) {
803 do_check_printf_call(caller, name, callexpr, fmtexpr->cond_true ? : fmtexpr->conditional, vaidx);
804 do_check_printf_call(caller, name, callexpr, fmtexpr->cond_false, vaidx);
805 return;
807 if (fmtexpr->type == EXPR_SYMBOL) {
809 * If the symbol has an initializer, we can handle
811 * const char foo[] = "abc"; and
812 * const char * const foo = "abc";
814 * We simply replace fmtexpr with the initializer
815 * expression. If foo is not one of the above, or if
816 * the initializer expression is somehow not a string
817 * literal, fmtexpr->type != EXPR_STRING will trigger
818 * below and we'll spam+return.
820 struct symbol *sym = fmtexpr->symbol;
821 if (sym->initializer &&
822 (is_array_of_const_char(sym) ||
823 is_const_pointer_to_const_char(sym))) {
824 fmtexpr = strip_parens(sym->initializer);
828 if (fmtexpr->type != EXPR_STRING) {
829 if (!unknown_format(fmtexpr))
830 return;
832 * Since we're now handling both ?: and static const
833 * char[] arguments, we don't get as much noise. It's
834 * still spammy, though.
836 spam("warn: call of '%s' with non-constant format argument", name);
837 return;
840 fmt = fmtexpr->string->data;
841 caller_in_fmt = check_format_string(fmt, caller);
843 while (*fmt) {
844 const char *old_fmt = fmt;
845 int read = format_decode(fmt, &spec);
846 struct expression *arg;
848 fmt += read;
849 if (spec.type == FORMAT_TYPE_NONE ||
850 spec.type == FORMAT_TYPE_PERCENT_CHAR)
851 continue;
854 * vaidx is currently the correct 0-based index for
855 * get_argument_from_call_expr. We post-increment it
856 * here so that it is the correct 1-based index for
857 * all the handlers below. This of course requires
858 * that we handle all FORMAT_TYPE_* things not taking
859 * an argument above.
861 arg = get_argument_from_call_expr(callexpr->args, vaidx++);
863 switch (spec.type) {
864 /* case FORMAT_TYPE_NONE: */
865 /* case FORMAT_TYPE_PERCENT_CHAR: */
866 /* break; */
868 case FORMAT_TYPE_INVALID:
869 sm_msg("error: format specifier '%.*s' invalid", read, old_fmt);
870 return;
872 case FORMAT_TYPE_FLOAT:
873 sm_msg("error: no floats in the kernel; invalid format specifier '%.*s'", read, old_fmt);
874 return;
876 case FORMAT_TYPE_NRCHARS:
877 sm_msg("error: %%n not supported in kernel");
878 return;
880 case FORMAT_TYPE_WIDTH:
881 case FORMAT_TYPE_PRECISION:
882 /* check int argument */
883 break;
885 case FORMAT_TYPE_STR:
887 * If the format string already contains the
888 * function name, it probably doesn't make
889 * sense to pass __func__ as well (or rather
890 * vice versa: If pr_fmt(fmt) has been defined
891 * to '"%s: " fmt, __func__', it doesn't make
892 * sense to use a format string containing the
893 * function name).
895 * This produces a lot of hits. They are not
896 * false positives, but it is easier to handle
897 * the things which don't occur that often
898 * first, so we use spam().
900 if (spec.qualifier)
901 sm_msg("warn: qualifier '%c' ignored for %%s specifier", spec.qualifier);
903 if (caller_in_fmt) {
904 if (arg_is___func__(arg))
905 spam("warn: passing __func__ while the format string already contains the name of the function '%s'",
906 caller);
907 else if (arg_contains_caller(arg, caller))
908 sm_msg("warn: passing string constant '%s' containing '%s' which is already part of the format string",
909 arg->string->data, caller);
911 break;
913 case FORMAT_TYPE_PTR:
914 /* This is the most important part: Checking %p extensions. */
915 pointer(fmt, arg, vaidx);
916 while (isalnum(*fmt))
917 fmt++;
918 break;
920 case FORMAT_TYPE_CHAR:
921 if (spec.qualifier)
922 sm_msg("warn: qualifier '%c' ignored for %%s specifier", spec.qualifier);
924 case FORMAT_TYPE_UBYTE:
925 case FORMAT_TYPE_BYTE:
926 case FORMAT_TYPE_USHORT:
927 case FORMAT_TYPE_SHORT:
928 case FORMAT_TYPE_INT:
929 /* argument should have integer type of width <= sizeof(int) */
930 break;
932 case FORMAT_TYPE_UINT:
933 case FORMAT_TYPE_LONG:
934 case FORMAT_TYPE_ULONG:
935 case FORMAT_TYPE_LONG_LONG:
936 case FORMAT_TYPE_PTRDIFF:
937 case FORMAT_TYPE_SIZE_T:
938 break;
944 if (get_argument_from_call_expr(callexpr->args, vaidx))
945 sm_msg("warn: excess argument passed to '%s'", name);
950 static void
951 check_printf_call(const char *name, struct expression *callexpr, void *_info)
954 * Note: attribute(printf) uses 1-based indexing, but
955 * get_argument_from_call_expr() uses 0-based indexing.
957 int info = PTR_INT(_info);
958 int fmtidx = (info & 0xff) - 1;
959 int vaidx = ((info >> 8) & 0xff) - 1;
960 struct expression *fmtexpr;
961 const char *caller = get_function();
964 * Calling a v*printf function with a literal format arg is
965 * extremely rare, so we don't bother doing the only checking
966 * we could do, namely checking that the format string is
967 * valid.
969 if (vaidx < 0)
970 return;
973 * For the things we use the name of the calling function for,
974 * it is more appropriate to skip a potential SyS_ prefix; the
975 * same goes for leading underscores.
977 if (!strncmp(caller, "SyS_", 4))
978 caller += 4;
979 while (*caller == '_')
980 ++caller;
982 /* Lack of format argument is a bug. */
983 fmtexpr = get_argument_from_call_expr(callexpr->args, fmtidx);
984 if (!fmtexpr) {
985 sm_msg("error: call of '%s' with no format argument", name);
986 return;
989 do_check_printf_call(caller, name, callexpr, fmtexpr, vaidx);
993 void check_kernel_printf(int id)
995 if (option_project != PROJ_KERNEL)
996 return;
998 my_id = id;
1000 #define printf_hook(func, fmt, first_to_check) \
1001 add_function_hook(#func, check_printf_call, INT_PTR(fmt + (first_to_check << 8)))
1003 /* Extracted using stupid perl script. */
1005 #if 0
1006 printf_hook(srm_printk, 1, 2); /* arch/alpha/include/asm/console.h */
1007 printf_hook(die_if_kernel, 1, 2); /* arch/frv/include/asm/bug.h */
1008 printf_hook(ia64_mca_printk, 1, 2); /* arch/ia64/include/asm/mca.h */
1009 printf_hook(nfprint, 1, 2); /* arch/m68k/include/asm/natfeat.h */
1010 printf_hook(gdbstub_printk, 1, 2); /* arch/mn10300/include/asm/gdb-stub.h */
1011 printf_hook(DBG, 1, 2); /* arch/powerpc/boot/ps3.c */
1012 printf_hook(printf, 1, 2); /* arch/powerpc/boot/stdio.h */
1013 printf_hook(udbg_printf, 1, 2); /* arch/powerpc/include/asm/udbg.h */
1014 printf_hook(__debug_sprintf_event, 3, 4); /* arch/s390/include/asm/debug.h */
1015 printf_hook(__debug_sprintf_exception, 3, 4); /* arch/s390/include/asm/debug.h */
1016 printf_hook(prom_printf, 1, 2); /* arch/sparc/include/asm/oplib_32.h */
1018 printf_hook(fail, 1, 2); /* arch/x86/vdso/vdso2c.c */
1019 #endif
1021 printf_hook(_ldm_printk, 3, 4); /* block/partitions/ldm.c */
1022 printf_hook(rbd_warn, 2, 3); /* drivers/block/rbd.c */
1023 printf_hook(fw_err, 2, 3); /* drivers/firewire/core.h */
1024 printf_hook(fw_notice, 2, 3); /* drivers/firewire/core.h */
1025 printf_hook(i915_error_printf, 2, 3); /* drivers/gpu/drm/i915/i915_drv.h */
1026 printf_hook(i915_handle_error, 3, 4); /* drivers/gpu/drm/i915/i915_drv.h */
1027 printf_hook(nv_printk_, 3, 4); /* drivers/gpu/drm/nouveau/core/include/core/printk.h */
1028 printf_hook(host1x_debug_output, 2, 3); /* drivers/gpu/host1x/debug.h */
1029 printf_hook(callc_debug, 2, 3); /* drivers/isdn/hisax/callc.c */
1030 printf_hook(link_debug, 3, 4); /* drivers/isdn/hisax/callc.c */
1031 printf_hook(HiSax_putstatus, 3, 4); /* drivers/isdn/hisax/hisax.h */
1032 printf_hook(VHiSax_putstatus, 3, 0); /* drivers/isdn/hisax/hisax.h */
1033 printf_hook(debugl1, 2, 3); /* drivers/isdn/hisax/isdnl1.h */
1034 printf_hook(l3m_debug, 2, 3); /* drivers/isdn/hisax/isdnl3.c */
1035 printf_hook(dout_debug, 2, 3); /* drivers/isdn/hisax/st5481_d.c */
1036 printf_hook(l1m_debug, 2, 3); /* drivers/isdn/hisax/st5481_d.c */
1037 printf_hook(bch_cache_set_error, 2, 3); /* drivers/md/bcache/bcache.h */
1038 printf_hook(_tda_printk, 4, 5); /* drivers/media/tuners/tda18271-priv.h */
1039 printf_hook(i40evf_debug_d, 3, 4); /* drivers/net/ethernet/intel/i40evf/i40e_osdep.h */
1040 printf_hook(en_print, 3, 4); /* drivers/net/ethernet/mellanox/mlx4/mlx4_en.h */
1041 printf_hook(_ath_dbg, 3, 4); /* drivers/net/wireless/ath/ath.h */
1042 printf_hook(ath_printk, 3, 4); /* drivers/net/wireless/ath/ath.h */
1043 printf_hook(ath10k_dbg, 3, 4); /* drivers/net/wireless/ath/ath10k/debug.h */
1044 printf_hook(ath10k_err, 2, 3); /* drivers/net/wireless/ath/ath10k/debug.h */
1045 printf_hook(ath10k_info, 2, 3); /* drivers/net/wireless/ath/ath10k/debug.h */
1046 printf_hook(ath10k_warn, 2, 3); /* drivers/net/wireless/ath/ath10k/debug.h */
1047 printf_hook(_ath5k_printk, 3, 4); /* drivers/net/wireless/ath/ath5k/ath5k.h */
1048 printf_hook(ATH5K_DBG, 3, 4); /* drivers/net/wireless/ath/ath5k/debug.h */
1049 printf_hook(ATH5K_DBG_UNLIMIT, 3, 4); /* drivers/net/wireless/ath/ath5k/debug.h */
1050 printf_hook(ath6kl_printk, 2, 3); /* drivers/net/wireless/ath/ath6kl/common.h */
1051 printf_hook(ath6kl_err, 1, 2); /* drivers/net/wireless/ath/ath6kl/debug.h */
1052 printf_hook(ath6kl_info, 1, 2); /* drivers/net/wireless/ath/ath6kl/debug.h */
1053 printf_hook(ath6kl_warn, 1, 2); /* drivers/net/wireless/ath/ath6kl/debug.h */
1054 printf_hook(wil_dbg_trace, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1055 printf_hook(wil_err, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1056 printf_hook(wil_err_ratelimited, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1057 printf_hook(wil_info, 2, 3); /* drivers/net/wireless/ath/wil6210/wil6210.h */
1058 printf_hook(b43dbg, 2, 3); /* drivers/net/wireless/b43/b43.h */
1059 printf_hook(b43err, 2, 3); /* drivers/net/wireless/b43/b43.h */
1060 printf_hook(b43info, 2, 3); /* drivers/net/wireless/b43/b43.h */
1061 printf_hook(b43warn, 2, 3); /* drivers/net/wireless/b43/b43.h */
1062 printf_hook(b43legacydbg, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1063 printf_hook(b43legacyerr, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1064 printf_hook(b43legacyinfo, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1065 printf_hook(b43legacywarn, 2, 3); /* drivers/net/wireless/b43legacy/b43legacy.h */
1066 printf_hook(__brcmf_dbg, 3, 4); /* drivers/net/wireless/brcm80211/brcmfmac/debug.h */
1067 printf_hook(__brcmf_err, 2, 3); /* drivers/net/wireless/brcm80211/brcmfmac/debug.h */
1068 printf_hook(__brcms_crit, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1069 printf_hook(__brcms_dbg, 4, 5); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1070 printf_hook(__brcms_err, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1071 printf_hook(__brcms_info, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1072 printf_hook(__brcms_warn, 2, 3); /* drivers/net/wireless/brcm80211/brcmsmac/debug.h */
1073 printf_hook(brcmu_dbg_hex_dump, 3, 4); /* drivers/net/wireless/brcm80211/include/brcmu_utils.h */
1074 printf_hook(__iwl_crit, 2, 3); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1075 printf_hook(__iwl_dbg, 5, 6); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1076 printf_hook(__iwl_err, 4, 5); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1077 printf_hook(__iwl_info, 2, 3); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1078 printf_hook(__iwl_warn, 2, 3); /* drivers/net/wireless/iwlwifi/iwl-debug.h */
1079 printf_hook(rsi_dbg, 2, 3); /* drivers/net/wireless/rsi/rsi_main.h */
1080 printf_hook(RTPRINT, 4, 5); /* drivers/net/wireless/rtlwifi/debug.h */
1081 printf_hook(RT_ASSERT, 2, 3); /* drivers/net/wireless/rtlwifi/debug.h */
1082 printf_hook(RT_TRACE, 4, 5); /* drivers/net/wireless/rtlwifi/debug.h */
1083 printf_hook(__of_node_dup, 2, 3); /* drivers/of/of_private.h */
1084 printf_hook(BNX2FC_HBA_DBG, 2, 3); /* drivers/scsi/bnx2fc/bnx2fc_debug.h */
1085 printf_hook(BNX2FC_IO_DBG, 2, 3); /* drivers/scsi/bnx2fc/bnx2fc_debug.h */
1086 printf_hook(BNX2FC_TGT_DBG, 2, 3); /* drivers/scsi/bnx2fc/bnx2fc_debug.h */
1087 printf_hook(ql_dbg, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1088 printf_hook(ql_dbg_pci, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1089 printf_hook(ql_log, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1090 printf_hook(ql_log_pci, 4, 5); /* drivers/scsi/qla2xxx/qla_dbg.h */
1091 printf_hook(libcfs_debug_msg, 2, 3); /* drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h */
1092 printf_hook(libcfs_debug_vmsg2, 4, 5); /* drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h */
1093 printf_hook(_ldlm_lock_debug, 3, 4); /* drivers/staging/lustre/lustre/include/lustre_dlm.h */
1094 printf_hook(_debug_req, 3, 4); /* drivers/staging/lustre/lustre/include/lustre_net.h */
1095 printf_hook(iscsi_change_param_sprintf, 2, 3); /* drivers/target/iscsi/iscsi_target_login.c */
1096 printf_hook(dbg, 1, 2); /* drivers/tty/serial/samsung.c */
1097 printf_hook(_usb_stor_dbg, 2, 3); /* drivers/usb/storage/debug.h */
1098 printf_hook(usb_stor_dbg, 2, 3); /* drivers/usb/storage/debug.h */
1099 printf_hook(vringh_bad, 1, 2); /* drivers/vhost/vringh.c */
1100 printf_hook(__adfs_error, 3, 4); /* fs/adfs/adfs.h */
1101 printf_hook(affs_error, 3, 4); /* fs/affs/affs.h */
1102 printf_hook(affs_warning, 3, 4); /* fs/affs/affs.h */
1103 printf_hook(befs_debug, 2, 3); /* fs/befs/befs.h */
1104 printf_hook(befs_error, 2, 3); /* fs/befs/befs.h */
1105 printf_hook(befs_warning, 2, 3); /* fs/befs/befs.h */
1106 printf_hook(__btrfs_panic, 5, 6); /* fs/btrfs/ctree.h */
1107 printf_hook(__btrfs_std_error, 5, 6); /* fs/btrfs/ctree.h */
1108 printf_hook(btrfs_printk, 2, 3); /* fs/btrfs/ctree.h */
1109 printf_hook(cifs_vfs_err, 1, 2); /* fs/cifs/cifs_debug.h */
1110 printf_hook(__ecryptfs_printk, 1, 2); /* fs/ecryptfs/ecryptfs_kernel.h */
1111 printf_hook(ext2_error, 3, 4); /* fs/ext2/ext2.h */
1112 printf_hook(ext2_msg, 3, 4); /* fs/ext2/ext2.h */
1113 printf_hook(ext3_abort, 3, 4); /* fs/ext3/ext3.h */
1114 printf_hook(ext3_error, 3, 4); /* fs/ext3/ext3.h */
1115 printf_hook(ext3_msg, 3, 4); /* fs/ext3/ext3.h */
1116 printf_hook(ext3_warning, 3, 4); /* fs/ext3/ext3.h */
1117 printf_hook(__ext4_abort, 4, 5); /* fs/ext4/ext4.h */
1118 printf_hook(__ext4_error, 4, 5); /* fs/ext4/ext4.h */
1119 printf_hook(__ext4_error_file, 5, 6); /* fs/ext4/ext4.h */
1120 printf_hook(__ext4_error_inode, 5, 6); /* fs/ext4/ext4.h */
1121 printf_hook(__ext4_grp_locked_error, 7, 8); /* fs/ext4/ext4.h */
1122 printf_hook(__ext4_msg, 3, 4); /* fs/ext4/ext4.h */
1123 printf_hook(__ext4_warning, 4, 5); /* fs/ext4/ext4.h */
1124 printf_hook(f2fs_msg, 3, 4); /* fs/f2fs/f2fs.h */
1125 printf_hook(__fat_fs_error, 3, 4); /* fs/fat/fat.h */
1126 printf_hook(fat_msg, 3, 4); /* fs/fat/fat.h */
1127 printf_hook(gfs2_print_dbg, 2, 3); /* fs/gfs2/glock.h */
1128 printf_hook(gfs2_lm_withdraw, 2, 3); /* fs/gfs2/util.h */
1129 printf_hook(hpfs_error, 2, 3); /* fs/hpfs/hpfs_fn.h */
1130 printf_hook(jfs_error, 2, 3); /* fs/jfs/jfs_superblock.h */
1131 printf_hook(nilfs_error, 3, 4); /* fs/nilfs2/nilfs.h */
1132 printf_hook(nilfs_warning, 3, 4); /* fs/nilfs2/nilfs.h */
1133 printf_hook(__ntfs_debug, 4, 5); /* fs/ntfs/debug.h */
1134 printf_hook(__ntfs_error, 3, 4); /* fs/ntfs/debug.h */
1135 printf_hook(__ntfs_warning, 3, 4); /* fs/ntfs/debug.h */
1136 printf_hook(__ocfs2_abort, 3, 4); /* fs/ocfs2/super.h */
1137 printf_hook(__ocfs2_error, 3, 4); /* fs/ocfs2/super.h */
1138 printf_hook(_udf_err, 3, 4); /* fs/udf/udfdecl.h */
1139 printf_hook(_udf_warn, 3, 4); /* fs/udf/udfdecl.h */
1140 printf_hook(ufs_error, 3, 4); /* fs/ufs/ufs.h */
1141 printf_hook(ufs_panic, 3, 4); /* fs/ufs/ufs.h */
1142 printf_hook(ufs_warning, 3, 4); /* fs/ufs/ufs.h */
1143 printf_hook(xfs_alert, 2, 3); /* fs/xfs/xfs_message.h */
1144 printf_hook(xfs_alert_tag, 3, 4); /* fs/xfs/xfs_message.h */
1145 printf_hook(xfs_crit, 2, 3); /* fs/xfs/xfs_message.h */
1146 printf_hook(xfs_debug, 2, 3); /* fs/xfs/xfs_message.h */
1147 printf_hook(xfs_emerg, 2, 3); /* fs/xfs/xfs_message.h */
1148 printf_hook(xfs_err, 2, 3); /* fs/xfs/xfs_message.h */
1149 printf_hook(xfs_info, 2, 3); /* fs/xfs/xfs_message.h */
1150 printf_hook(xfs_notice, 2, 3); /* fs/xfs/xfs_message.h */
1151 printf_hook(xfs_warn, 2, 3); /* fs/xfs/xfs_message.h */
1152 printf_hook(warn_slowpath_fmt, 3, 4); /* include/asm-generic/bug.h */
1153 printf_hook(warn_slowpath_fmt_taint, 4, 5); /* include/asm-generic/bug.h */
1154 printf_hook(drm_err, 1, 2); /* include/drm/drmP.h */
1155 printf_hook(drm_ut_debug_printk, 2, 3); /* include/drm/drmP.h */
1156 printf_hook(__acpi_handle_debug, 3, 4); /* include/linux/acpi.h */
1157 printf_hook(acpi_handle_printk, 3, 4); /* include/linux/acpi.h */
1158 printf_hook(audit_log, 4, 5); /* include/linux/audit.h */
1159 printf_hook(audit_log_format, 2, 3); /* include/linux/audit.h */
1160 printf_hook(bdi_register, 3, 4); /* include/linux/backing-dev.h */
1161 printf_hook(__trace_note_message, 2, 3); /* include/linux/blktrace_api.h */
1162 printf_hook(_dev_info, 2, 3); /* include/linux/device.h */
1163 printf_hook(dev_alert, 2, 3); /* include/linux/device.h */
1164 printf_hook(dev_crit, 2, 3); /* include/linux/device.h */
1165 printf_hook(dev_emerg, 2, 3); /* include/linux/device.h */
1166 printf_hook(dev_err, 2, 3); /* include/linux/device.h */
1167 printf_hook(dev_notice, 2, 3); /* include/linux/device.h */
1168 printf_hook(dev_printk, 3, 4); /* include/linux/device.h */
1169 printf_hook(dev_printk_emit, 3, 4); /* include/linux/device.h */
1170 printf_hook(dev_set_name, 2, 3); /* include/linux/device.h */
1171 printf_hook(dev_vprintk_emit, 3, 0); /* include/linux/device.h */
1172 printf_hook(dev_warn, 2, 3); /* include/linux/device.h */
1173 printf_hook(device_create, 5, 6); /* include/linux/device.h */
1174 printf_hook(device_create_with_groups, 6, 7); /* include/linux/device.h */
1175 printf_hook(devm_kasprintf, 3, 4); /* include/linux/device.h */
1176 printf_hook(__dynamic_dev_dbg, 3, 4); /* include/linux/dynamic_debug.h */
1177 printf_hook(__dynamic_netdev_dbg, 3, 4); /* include/linux/dynamic_debug.h */
1178 printf_hook(__dynamic_pr_debug, 2, 3); /* include/linux/dynamic_debug.h */
1179 printf_hook(__simple_attr_check_format, 1, 2); /* include/linux/fs.h */
1180 printf_hook(fscache_init_cache, 3, 4); /* include/linux/fscache-cache.h */
1181 printf_hook(gameport_set_phys, 2, 3); /* include/linux/gameport.h */
1182 printf_hook(iio_trigger_alloc, 1, 2); /* include/linux/iio/trigger.h */
1183 printf_hook(__check_printsym_format, 1, 2); /* include/linux/kallsyms.h */
1184 printf_hook(kdb_printf, 1, 2); /* include/linux/kdb.h */
1185 printf_hook(vkdb_printf, 1, 0); /* include/linux/kdb.h */
1186 printf_hook(____trace_printk_check_format, 1, 2); /* include/linux/kernel.h */
1187 printf_hook(__trace_bprintk, 2, 3); /* include/linux/kernel.h */
1188 printf_hook(__trace_printk, 2, 3); /* include/linux/kernel.h */
1189 printf_hook(kasprintf, 2, 3); /* include/linux/kernel.h */
1190 printf_hook(panic, 1, 2); /* include/linux/kernel.h */
1191 printf_hook(scnprintf, 3, 4); /* include/linux/kernel.h */
1192 printf_hook(snprintf, 3, 4); /* include/linux/kernel.h */
1193 printf_hook(sprintf, 2, 3); /* include/linux/kernel.h */
1194 printf_hook(trace_printk, 1, 2); /* include/linux/kernel.h */
1195 printf_hook(vscnprintf, 3, 0); /* include/linux/kernel.h */
1196 printf_hook(vsnprintf, 3, 0); /* include/linux/kernel.h */
1197 printf_hook(vsprintf, 2, 0); /* include/linux/kernel.h */
1198 printf_hook(vmcoreinfo_append_str, 1, 2); /* include/linux/kexec.h */
1199 printf_hook(__request_module, 2, 3); /* include/linux/kmod.h */
1200 printf_hook(add_uevent_var, 2, 3); /* include/linux/kobject.h */
1201 printf_hook(kobject_add, 3, 4); /* include/linux/kobject.h */
1202 printf_hook(kobject_init_and_add, 4, 5); /* include/linux/kobject.h */
1203 printf_hook(kobject_set_name, 2, 3); /* include/linux/kobject.h */
1204 printf_hook(kthread_create_on_node, 4, 5); /* include/linux/kthread.h */
1205 printf_hook(__ata_ehi_push_desc, 2, 3); /* include/linux/libata.h */
1206 printf_hook(ata_dev_printk, 3, 4); /* include/linux/libata.h */
1207 printf_hook(ata_ehi_push_desc, 2, 3); /* include/linux/libata.h */
1208 printf_hook(ata_link_printk, 3, 4); /* include/linux/libata.h */
1209 printf_hook(ata_port_desc, 2, 3); /* include/linux/libata.h */
1210 printf_hook(ata_port_printk, 3, 4); /* include/linux/libata.h */
1211 printf_hook(warn_alloc_failed, 3, 4); /* include/linux/mm.h */
1212 printf_hook(mmiotrace_printk, 1, 2); /* include/linux/mmiotrace.h */
1213 printf_hook(netdev_alert, 2, 3); /* include/linux/netdevice.h */
1214 printf_hook(netdev_crit, 2, 3); /* include/linux/netdevice.h */
1215 printf_hook(netdev_emerg, 2, 3); /* include/linux/netdevice.h */
1216 printf_hook(netdev_err, 2, 3); /* include/linux/netdevice.h */
1217 printf_hook(netdev_info, 2, 3); /* include/linux/netdevice.h */
1218 printf_hook(netdev_notice, 2, 3); /* include/linux/netdevice.h */
1219 printf_hook(netdev_printk, 3, 4); /* include/linux/netdevice.h */
1220 printf_hook(netdev_warn, 2, 3); /* include/linux/netdevice.h */
1221 printf_hook(early_printk, 1, 2); /* include/linux/printk.h */
1222 printf_hook(no_printk, 1, 2); /* include/linux/printk.h */
1223 printf_hook(printk, 1, 2); /* include/linux/printk.h */
1224 printf_hook(printk_deferred, 1, 2); /* include/linux/printk.h */
1225 printf_hook(printk_emit, 5, 6); /* include/linux/printk.h */
1226 printf_hook(vprintk, 1, 0); /* include/linux/printk.h */
1227 printf_hook(vprintk_emit, 5, 0); /* include/linux/printk.h */
1228 printf_hook(__quota_error, 3, 4); /* include/linux/quotaops.h */
1229 printf_hook(seq_buf_printf, 2, 3); /* include/linux/seq_buf.h */
1230 printf_hook(seq_buf_vprintf, 2, 0); /* include/linux/seq_buf.h */
1231 printf_hook(seq_printf, 2, 3); /* include/linux/seq_file.h */
1232 printf_hook(seq_vprintf, 2, 0); /* include/linux/seq_file.h */
1233 printf_hook(bprintf, 3, 4); /* include/linux/string.h */
1234 printf_hook(trace_seq_printf, 2, 3); /* include/linux/trace_seq.h */
1235 printf_hook(trace_seq_vprintf, 2, 0); /* include/linux/trace_seq.h */
1236 printf_hook(__alloc_workqueue_key, 1, 6); /* include/linux/workqueue.h */
1237 printf_hook(set_worker_desc, 1, 2); /* include/linux/workqueue.h */
1238 printf_hook(_p9_debug, 3, 4); /* include/net/9p/9p.h */
1239 printf_hook(bt_err, 1, 2); /* include/net/bluetooth/bluetooth.h */
1240 printf_hook(bt_info, 1, 2); /* include/net/bluetooth/bluetooth.h */
1241 printf_hook(nf_ct_helper_log, 3, 4); /* include/net/netfilter/nf_conntrack_helper.h */
1242 printf_hook(nf_log_buf_add, 2, 3); /* include/net/netfilter/nf_log.h */
1243 printf_hook(nf_log_packet, 8, 9); /* include/net/netfilter/nf_log.h */
1244 printf_hook(SOCK_DEBUG, 2, 3); /* include/net/sock.h */
1245 printf_hook(__snd_printk, 4, 5); /* include/sound/core.h */
1246 printf_hook(_snd_printd, 2, 3); /* include/sound/core.h */
1247 printf_hook(snd_printd, 1, 2); /* include/sound/core.h */
1248 printf_hook(snd_printdd, 1, 2); /* include/sound/core.h */
1249 printf_hook(snd_iprintf, 2, 3); /* include/sound/info.h */
1250 printf_hook(snd_seq_create_kernel_client, 3, 4); /* include/sound/seq_kernel.h */
1251 printf_hook(xen_raw_printk, 1, 2); /* include/xen/hvc-console.h */
1252 printf_hook(xenbus_dev_error, 3, 4); /* include/xen/xenbus.h */
1253 printf_hook(xenbus_dev_fatal, 3, 4); /* include/xen/xenbus.h */
1254 printf_hook(xenbus_printf, 4, 5); /* include/xen/xenbus.h */
1255 printf_hook(xenbus_watch_pathfmt, 4, 5); /* include/xen/xenbus.h */
1256 printf_hook(batadv_fdebug_log, 2, 3); /* net/batman-adv/debugfs.c */
1257 printf_hook(_batadv_dbg, 4, 5); /* net/batman-adv/main.h */
1258 printf_hook(batadv_debug_log, 2, 3); /* net/batman-adv/main.h */
1259 printf_hook(__sdata_dbg, 2, 3); /* net/mac80211/debug.h */
1260 printf_hook(__sdata_err, 1, 2); /* net/mac80211/debug.h */
1261 printf_hook(__sdata_info, 1, 2); /* net/mac80211/debug.h */
1262 printf_hook(__wiphy_dbg, 3, 4); /* net/mac80211/debug.h */
1263 printf_hook(mac80211_format_buffer, 4, 5); /* net/mac80211/debugfs.h */
1264 printf_hook(__rds_conn_error, 2, 3); /* net/rds/rds.h */
1265 printf_hook(rdsdebug, 1, 2); /* net/rds/rds.h */
1266 printf_hook(printl, 1, 2); /* net/sctp/probe.c */
1267 printf_hook(svc_printk, 2, 3); /* net/sunrpc/svc.c */
1268 printf_hook(tomoyo_io_printf, 2, 3); /* security/tomoyo/common.c */
1269 printf_hook(tomoyo_supervisor, 2, 3); /* security/tomoyo/common.h */
1270 printf_hook(tomoyo_write_log, 2, 3); /* security/tomoyo/common.h */
1271 printf_hook(cmp_error, 2, 3); /* sound/firewire/cmp.c */