* [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions
@ 2022-05-21 10:06 Christophe JAILLET
2022-05-23 13:00 ` Dan Carpenter
0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2022-05-21 10:06 UTC (permalink / raw)
To: smatch; +Cc: Christophe JAILLET
The fact that the 'size' parameter is the first one when kmalloc is used
is hard coded.
Pass this information via the last argument of add_function_assign_hook()
so that other allocation functions (devm_...) can use the same hook.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
check_kmalloc_wrong_size.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/check_kmalloc_wrong_size.c b/check_kmalloc_wrong_size.c
index 41e1e0e64cc2..99690e8ca2ce 100644
--- a/check_kmalloc_wrong_size.c
+++ b/check_kmalloc_wrong_size.c
@@ -45,8 +45,9 @@ static void check_size_matches(int data_size, struct expression *size_expr)
sm_warning("double check that we're allocating correct size: %d vs %s", data_size, sval_to_str(sval));
}
-static void match_alloc(const char *fn, struct expression *expr, void *unused)
+static void match_alloc(const char *fn, struct expression *expr, void *_arg_nr)
{
+ int arg_nr = PTR_INT(_arg_nr);
struct expression *call = strip_expr(expr->right);
struct expression *arg;
int ptr_size;
@@ -55,7 +56,7 @@ static void match_alloc(const char *fn, struct expression *expr, void *unused)
if (!ptr_size)
return;
- arg = get_argument_from_call_expr(call->args, 0);
+ arg = get_argument_from_call_expr(call->args, arg_nr);
arg = strip_expr(arg);
if (!arg || arg->type != EXPR_BINOP || arg->op != '*')
return;
@@ -90,6 +91,6 @@ void check_kmalloc_wrong_size(int id)
return;
}
- add_function_assign_hook("kmalloc", &match_alloc, NULL);
+ add_function_assign_hook("kmalloc", &match_alloc, INT_PTR(0));
add_function_assign_hook("kcalloc", &match_calloc, INT_PTR(1));
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions
2022-05-21 10:06 [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions Christophe JAILLET
@ 2022-05-23 13:00 ` Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2022-05-23 13:00 UTC (permalink / raw)
To: Christophe JAILLET; +Cc: smatch
On Sat, May 21, 2022 at 12:06:53PM +0200, Christophe JAILLET wrote:
> The fact that the 'size' parameter is the first one when kmalloc is used
> is hard coded.
> Pass this information via the last argument of add_function_assign_hook()
> so that other allocation functions (devm_...) can use the same hook.
>
Applied!
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-23 13:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-21 10:06 [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions Christophe JAILLET
2022-05-23 13:00 ` Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.