db: fixup_kernel.sh: ignore timer_list functions
[smatch.git] / check_platform_device_put.c
blob7b81b32cb0f854c215c8f762e342606d88a60566
1 /*
2 * smatch/check_platform_device_put.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_extra.h"
12 #include "smatch_slist.h"
14 static int my_id;
16 #define MAX_ERRNO 4095
18 STATE(added);
19 STATE(not_added);
21 static void match_added(const char *fn, struct expression *call_expr,
22 struct expression *assign_expr, void *unused)
24 struct expression *arg_expr;
26 arg_expr = get_argument_from_call_expr(call_expr->args, 0);
27 set_state_expr(my_id, arg_expr, &added);
30 static void match_not_added(const char *fn, struct expression *call_expr,
31 struct expression *assign_expr, void *unused)
33 struct expression *arg_expr;
35 arg_expr = get_argument_from_call_expr(call_expr->args, 0);
36 set_state_expr(my_id, arg_expr, &not_added);
39 static void match_platform_device_del(const char *fn, struct expression *expr, void *unused)
41 struct expression *arg_expr;
42 struct sm_state *sm;
44 arg_expr = get_argument_from_call_expr(expr->args, 0);
45 sm = get_sm_state_expr(my_id, arg_expr);
46 if (!sm)
47 return;
48 if (!slist_has_state(sm->possible, &not_added))
49 return;
50 sm_msg("warn: perhaps platform_device_put() was intended here?");
53 void check_platform_device_put(int id)
55 if (option_project != PROJ_KERNEL)
56 return;
57 my_id = id;
59 return_implies_state("platform_device_add", 0, 0, &match_added, NULL);
60 return_implies_state("platform_device_add", -MAX_ERRNO, -1, &match_not_added, NULL);
61 add_function_hook("platform_device_del", &match_platform_device_del, NULL);