From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229808AbiEUKHB (ORCPT ); Sat, 21 May 2022 06:07:01 -0400 Received: from smtp.smtpout.orange.fr (smtp02.smtpout.orange.fr [80.12.242.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12DD1237F5 for ; Sat, 21 May 2022 03:06:56 -0700 (PDT) From: Christophe JAILLET Subject: [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions Date: Sat, 21 May 2022 12:06:53 +0200 Message-Id: <7052be5923bd123df3755d71acc262484e46477e.1653127604.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-ID: To: smatch@vger.kernel.org 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 --- 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