flow: fix some parent transition fallout
[smatch.git] / check_platform_device_put.c
blob01a69b0d6d9982b1b5cd9c4b9dd9df45f4b1b810
1 /*
2 * Copyright (C) 2010 Dan Carpenter.
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 "smatch.h"
19 #include "smatch_extra.h"
20 #include "smatch_slist.h"
22 static int my_id;
24 #define MAX_ERRNO 4095
26 STATE(added);
27 STATE(not_added);
29 static void match_added(const char *fn, struct expression *call_expr,
30 struct expression *assign_expr, void *unused)
32 struct expression *arg_expr;
34 arg_expr = get_argument_from_call_expr(call_expr->args, 0);
35 set_state_expr(my_id, arg_expr, &added);
38 static void match_not_added(const char *fn, struct expression *call_expr,
39 struct expression *assign_expr, void *unused)
41 struct expression *arg_expr;
43 arg_expr = get_argument_from_call_expr(call_expr->args, 0);
44 set_state_expr(my_id, arg_expr, &not_added);
47 static void match_platform_device_del(const char *fn, struct expression *expr, void *unused)
49 struct expression *arg_expr;
50 struct sm_state *sm;
52 arg_expr = get_argument_from_call_expr(expr->args, 0);
53 sm = get_sm_state_expr(my_id, arg_expr);
54 if (!sm)
55 return;
56 if (!slist_has_state(sm->possible, &not_added))
57 return;
58 sm_msg("warn: perhaps platform_device_put() was intended here?");
61 void check_platform_device_put(int id)
63 if (option_project != PROJ_KERNEL)
64 return;
65 my_id = id;
67 return_implies_state("platform_device_add", 0, 0, &match_added, NULL);
68 return_implies_state("platform_device_add", -MAX_ERRNO, -1, &match_not_added, NULL);
69 add_function_hook("platform_device_del", &match_platform_device_del, NULL);