All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: smatch@vger.kernel.org
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions
Date: Sat, 21 May 2022 12:06:53 +0200	[thread overview]
Message-ID: <7052be5923bd123df3755d71acc262484e46477e.1653127604.git.christophe.jaillet@wanadoo.fr> (raw)

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

             reply	other threads:[~2022-05-21 10:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-21 10:06 Christophe JAILLET [this message]
2022-05-23 13:00 ` [PATCH] kmalloc_wrong_size: Preparation work in order to add more functions Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7052be5923bd123df3755d71acc262484e46477e.1653127604.git.christophe.jaillet@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=smatch@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.