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
19 #include "smatch_extra.h"
20 #include "smatch_slist.h"
24 #define MAX_ERRNO 4095
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
, ¬_added
);
47 static void match_platform_device_del(const char *fn
, struct expression
*expr
, void *unused
)
49 struct expression
*arg_expr
;
52 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
53 sm
= get_sm_state_expr(my_id
, arg_expr
);
56 if (!slist_has_state(sm
->possible
, ¬_added
))
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
)
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
);