1*1f5207b7SJohn Levon /* 2*1f5207b7SJohn Levon * Copyright (C) 2011 Dan Carpenter. 3*1f5207b7SJohn Levon * 4*1f5207b7SJohn Levon * This program is free software; you can redistribute it and/or 5*1f5207b7SJohn Levon * modify it under the terms of the GNU General Public License 6*1f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2 7*1f5207b7SJohn Levon * of the License, or (at your option) any later version. 8*1f5207b7SJohn Levon * 9*1f5207b7SJohn Levon * This program is distributed in the hope that it will be useful, 10*1f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*1f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*1f5207b7SJohn Levon * GNU General Public License for more details. 13*1f5207b7SJohn Levon * 14*1f5207b7SJohn Levon * You should have received a copy of the GNU General Public License 15*1f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt 16*1f5207b7SJohn Levon */ 17*1f5207b7SJohn Levon 18*1f5207b7SJohn Levon #include "smatch.h" 19*1f5207b7SJohn Levon #include "smatch_slist.h" 20*1f5207b7SJohn Levon 21*1f5207b7SJohn Levon static int my_id; 22*1f5207b7SJohn Levon match_return(struct expression * ret_value)23*1f5207b7SJohn Levonstatic void match_return(struct expression *ret_value) 24*1f5207b7SJohn Levon { 25*1f5207b7SJohn Levon struct expression *expr; 26*1f5207b7SJohn Levon char *macro; 27*1f5207b7SJohn Levon 28*1f5207b7SJohn Levon if (!ret_value) 29*1f5207b7SJohn Levon return; 30*1f5207b7SJohn Levon expr = ret_value; 31*1f5207b7SJohn Levon if (ret_value->type != EXPR_PREOP || ret_value->op != '-') 32*1f5207b7SJohn Levon return; 33*1f5207b7SJohn Levon 34*1f5207b7SJohn Levon macro = get_macro_name(expr->unop->pos); 35*1f5207b7SJohn Levon if (macro && !strcmp(macro, "PTR_ERR")) { 36*1f5207b7SJohn Levon sm_warning("returning -%s()", macro); 37*1f5207b7SJohn Levon return; 38*1f5207b7SJohn Levon } 39*1f5207b7SJohn Levon 40*1f5207b7SJohn Levon if (!option_spammy) 41*1f5207b7SJohn Levon return; 42*1f5207b7SJohn Levon 43*1f5207b7SJohn Levon expr = get_assigned_expr(ret_value->unop); 44*1f5207b7SJohn Levon if (!expr) 45*1f5207b7SJohn Levon return; 46*1f5207b7SJohn Levon if (expr->type != EXPR_CALL) 47*1f5207b7SJohn Levon return; 48*1f5207b7SJohn Levon 49*1f5207b7SJohn Levon sm_warning("should this return really be negated?"); 50*1f5207b7SJohn Levon } 51*1f5207b7SJohn Levon check_return_negative_var(int id)52*1f5207b7SJohn Levonvoid check_return_negative_var(int id) 53*1f5207b7SJohn Levon { 54*1f5207b7SJohn Levon if (option_project != PROJ_KERNEL) 55*1f5207b7SJohn Levon return; 56*1f5207b7SJohn Levon 57*1f5207b7SJohn Levon my_id = id; 58*1f5207b7SJohn Levon add_hook(&match_return, RETURN_HOOK); 59*1f5207b7SJohn Levon } 60