kref_put() and kobject_put() are basically like a free()
[smatch.git] / smatch.c
blobd0e74648c4c88551fd1b98daa549447ced2cb967
1 /*
2 * sparse/smatch.c
4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include <stdio.h>
11 #include <libgen.h>
12 #include "smatch.h"
14 char *bin_dir;
16 typedef void (*reg_func) (int id);
17 void register_smatch_extra(int id);
18 void register_smatch_ignore(int id);
19 void register_implications(int id);
20 void register_function_hooks(int id);
21 void check_null_deref(int id);
22 void check_overflow(int id);
23 void check_locking(int id);
24 void check_memory(int id);
25 void check_frees_argument(int id);
26 void check_leaks(int id);
27 void check_allocation_funcs(int id);
28 /* <- your test goes here */
29 /* void register_template(int id); */
31 static const reg_func reg_funcs[] = {
32 &register_smatch_extra, /* smatch_extra always has to be first */
33 &register_smatch_ignore,
34 &check_null_deref,
35 &check_overflow,
36 &check_locking,
37 &check_memory,
38 // &check_allocation_funcs,
39 // &check_leaks,
40 // &check_frees_argument,
42 /* <- your test goes here */
43 /* &register_template, */
45 &register_implications, /* implications always has to be last */
46 NULL
49 static void help(void)
51 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
52 printf("--debug: print lots of debug output.\n");
53 printf("--debug-implied: print debug output about implications.\n");
54 printf("--assume-loops: assume loops always go through at least once.\n");
55 printf("--known-conditions: don't branch for known conditions.");
56 exit(1);
59 int main(int argc, char **argv)
61 int i;
62 reg_func func;
64 bin_dir = dirname(alloc_string(argv[0]));
66 /* The script IDs start at 1.
67 0 is used for internal stuff. */
68 create_function_hash();
69 for(i = 0; (func = reg_funcs[i]); i++){
70 func(i + 1);
72 register_function_hooks(-1);
74 while(argc >= 2) {
75 if (!strcmp(argv[1], "--debug")) {
76 debug_states = 1;
77 } else if (!strcmp(argv[1], "--debug-implied")) {
78 debug_implied_states = 1;
79 } else if (!strcmp(argv[1], "--no-implied")) {
80 option_no_implied = 1;
81 } else if (!strcmp(argv[1], "--assume-loops")) {
82 option_assume_loops = 1;
83 } else if (!strcmp(argv[1], "--known-conditions")) {
84 option_known_conditions = 1;
85 } else if (!strcmp(argv[1], "--help")) {
86 help();
87 } else {
88 break;
90 argc--;
91 argv++;
94 smatch(argc, argv);
95 return 0;