2 * smatch/check_return.c
4 * Copyright (C) 2011 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 #include "smatch_slist.h"
14 extern int check_assigned_expr_id
;
16 static struct expression
*get_assigned_expr(struct expression
*expr
)
18 struct smatch_state
*state
;
20 state
= get_state_expr(check_assigned_expr_id
, expr
);
23 /* fixme: handle merged states as well */
24 return (struct expression
*)state
->data
;
27 static void match_return(struct expression
*ret_value
)
29 struct expression
*expr
;
35 if (ret_value
->type
!= EXPR_PREOP
|| ret_value
->op
!= '-')
38 macro
= get_macro_name(expr
->unop
->pos
);
39 if (macro
&& !strcmp(macro
, "PTR_ERR")) {
40 sm_msg("warn: returning -%s()", macro
);
47 expr
= get_assigned_expr(ret_value
->unop
);
50 if (expr
->type
!= EXPR_CALL
)
53 sm_msg("warn: should this return really be negated?");
56 void check_return_negative_var(int id
)
58 if (option_project
!= PROJ_KERNEL
)
62 add_hook(&match_return
, RETURN_HOOK
);