Skip to contentSkip to conversation

kmalloc_wrong_size: Preparation work in order to add more functions

PATCH Applied Christophe JAILLET 2 participants 2 messages May 21, 2022 – May 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmalloc_wrong_size: Preparation work in order to add more functions

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.

---
 check_kmalloc_wrong_size.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
check_kmalloc_wrong_size.c +4 -3
index 41e1e0e64cc2..99690e8ca2ce 100644
@@ -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));
 }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · 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.

Applied!

regards,
dan carpenter