/* * Copyright (C) 2021 Oracle. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt */ #include "smatch.h" #include "smatch_slist.h" static int my_id; static void check_for_EPROBE_DEFER(struct expression *expr) { sval_t sval; char *macro; if (!expr || expr->type != EXPR_PREOP || expr->op != '-') return; expr = expr->unop; if (!get_value(expr, &sval) || sval.value != 517) return; macro = get_macro_name(expr->pos); if (!macro || strcmp(macro, "EPROBE_DEFER") != 0) return; sm_warning("returning EPROBE_DEFER from non probe() function"); } static void match_assign(struct expression *expr) { /* "ret = ERR_PTR(-EPROBE_DEFER)" generates a fake assignment so * that is covered here. */ check_for_EPROBE_DEFER(expr->right); } static void match_return(struct expression *expr) { check_for_EPROBE_DEFER(expr); } void check_EPROBE_DEFER(int id) { my_id = id; if (option_project != PROJ_KERNEL) return; add_hook(&match_assign, ASSIGNMENT_HOOK); add_hook(&match_return, RETURN_HOOK); }