2 * smatch/check_platform_device_put.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_extra.h"
12 #include "smatch_slist.h"
16 #define MAX_ERRNO 4095
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
, ¬_added
);
39 static void match_platform_device_del(const char *fn
, struct expression
*expr
, void *unused
)
41 struct expression
*arg_expr
;
44 arg_expr
= get_argument_from_call_expr(expr
->args
, 0);
45 sm
= get_sm_state_expr(my_id
, arg_expr
);
48 if (!slist_has_state(sm
->possible
, ¬_added
))
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
)
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
);