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 clear_state(struct sm_state
*sm
, struct expression
*mod_expr
)
28 set_state(my_id
, sm
->name
, sm
->sym
, &undefined
);
31 static void match_platform_get_irq(struct expression
*expr
, const char *name
, struct symbol
*sym
, void *data
)
33 set_state(my_id
, name
, sym
, &get_irq
);
36 static bool assigned_zero(struct expression
*expr
)
38 struct sm_state
*sm
, *tmp
;
39 struct expression
*prev
;
41 sm
= get_assigned_sm(expr
);
44 FOR_EACH_PTR(sm
->possible
, tmp
) {
45 prev
= tmp
->state
->data
;
46 if (expr_is_zero(prev
))
48 } END_FOR_EACH_PTR(tmp
);
53 static bool is_part_of_select(struct expression
*expr
)
55 struct expression
*parent
;
58 /* Code like "return irq ?: -EINVAL;" is wrong but harmless */
60 parent
= expr_get_parent_expr(expr
);
63 if (parent
->type
!= EXPR_CONDITIONAL
&&
64 parent
->type
!= EXPR_SELECT
)
67 if (get_value(parent
->cond_false
, &sval
) &&
68 sval
.value
>= -4095 &&
75 static void match_condition(struct expression
*expr
)
77 struct range_list
*rl
;
79 if (!expr_has_possible_state(my_id
, expr
, &get_irq
))
82 if (get_implied_rl(expr
, &rl
) && rl_min(rl
).value
== 0)
85 if (assigned_zero(expr
))
88 if (is_part_of_select(expr
))
91 sm_msg("warn: platform_get_irq() does not return zero");
94 void check_platform_get_irq_return(int id
)
98 add_function_param_key_hook_late("platform_get_irq", &match_platform_get_irq
, -1, "$", NULL
);
99 add_function_param_key_hook_late("platform_get_irq_optional", &match_platform_get_irq
, -1, "$", NULL
);
100 add_function_param_key_hook_late("platform_get_irq_byname", &match_platform_get_irq
, -1, "$", NULL
);
101 add_function_param_key_hook_late("platform_get_irq_byname_optional", &match_platform_get_irq
, -1, "$", NULL
);
102 add_modification_hook(my_id
, &clear_state
);
103 add_hook(&match_condition
, CONDITION_HOOK
);