2 * Copyright (C) 2022 Oracle.
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
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
26 static void match_platform_get_irq(struct expression
*expr
, const char *name
, struct symbol
*sym
, void *data
)
28 set_state(my_id
, name
, sym
, &get_irq
);
31 static bool assigned_zero(struct expression
*expr
)
33 struct sm_state
*sm
, *tmp
;
34 struct expression
*prev
;
36 sm
= get_assigned_sm(expr
);
39 FOR_EACH_PTR(sm
->possible
, tmp
) {
40 prev
= tmp
->state
->data
;
41 if (expr_is_zero(prev
))
43 } END_FOR_EACH_PTR(tmp
);
48 static bool is_part_of_select(struct expression
*expr
)
50 struct expression
*parent
;
53 /* Code like "return irq ?: -EINVAL;" is wrong but harmless */
55 parent
= expr_get_parent_expr(expr
);
58 if (parent
->type
!= EXPR_CONDITIONAL
&&
59 parent
->type
!= EXPR_SELECT
)
62 if (get_value(parent
->cond_false
, &sval
) &&
63 sval
.value
>= -4095 &&
70 static void match_condition(struct expression
*expr
)
72 struct range_list
*rl
;
74 if (!expr_has_possible_state(my_id
, expr
, &get_irq
))
77 if (get_implied_rl(expr
, &rl
) && rl_min(rl
).value
== 0)
80 if (assigned_zero(expr
))
83 if (is_part_of_select(expr
))
86 sm_msg("warn: platform_get_irq() does not return zero");
89 void check_platform_get_irq_return(int id
)
93 add_function_param_key_hook_late("platform_get_irq", &match_platform_get_irq
, -1, "$", NULL
);
94 add_function_param_key_hook_late("platform_get_irq_optional", &match_platform_get_irq
, -1, "$", NULL
);
95 add_function_param_key_hook_late("platform_get_irq_byname", &match_platform_get_irq
, -1, "$", NULL
);
96 add_function_param_key_hook_late("platform_get_irq_byname_optional", &match_platform_get_irq
, -1, "$", NULL
);
97 add_modification_hook(my_id
, &set_undefined
);
98 add_hook(&match_condition
, CONDITION_HOOK
);