helper: cache get_member_name()
[smatch.git] / smatch_kernel_netdev_priv.c
blob48cac62afcb8dae01fb2508878c1e2ab25a901f3
1 /*
2 * Copyright 2023 Linaro Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include "smatch.h"
19 #include "smatch_extra.h"
21 static int my_id;
23 static void match_netdev_priv(const char *fn, struct expression *expr, void *unused)
26 struct expression *right, *arg;
28 right = strip_expr(expr->right);
29 if (right->type != EXPR_CALL)
30 return;
32 arg = get_argument_from_call_expr(right->args, 0);
33 arg = strip_expr(arg);
34 if (!arg || arg->type != EXPR_SYMBOL)
35 return;
37 set_state_expr(my_id, arg, alloc_state_expr(expr->left));
40 struct expression *get_netdev_priv(struct expression *dev)
42 struct smatch_state *state;
44 state = get_state_expr(my_id, dev);
45 if (!state)
46 return NULL;
47 return state->data;
50 void register_kernel_netdev_priv(int id)
52 if (option_project != PROJ_KERNEL)
53 return;
55 my_id = id;
56 set_dynamic_states(my_id);
57 add_function_assign_hook("netdev_priv", &match_netdev_priv, NULL);