/* * Copyright 2024 Linaro Ltd. * * 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" #include "smatch_extra.h" static int my_id; static unsigned long is_ioctl; static void function_start(struct symbol *sym) { struct string_list *ptrs; char *ptr; ptrs = get_caller_ptrs(sym); FOR_EACH_PTR(ptrs, ptr) { if (strcmp(ptr, "(struct file_operations)->unlocked_ioctl") == 0 || strcmp(ptr, "(struct file_operations)->compat_ioctl") == 0) { is_ioctl = true; return; } } END_FOR_EACH_PTR(ptr); } static void match_return(struct expression *expr) { char *name; if (!is_ioctl) return; if (!is_EPROBE_DEFER(expr)) return; name = expr_to_str(expr); sm_warning("EPROBE_DEFER is only for probe functions '%s'", name); free_string(name); } void check_returning_EPROBE_DEFER(int id) { my_id = id; if (option_project != PROJ_KERNEL) return; add_function_data(&is_ioctl); add_hook(&function_start, FUNC_DEF_HOOK); add_hook(&match_return, RETURN_HOOK); }