From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: smatch@vger.kernel.org
Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Subject: [PATCH 2/2] check_freeing_devm: Take advantage of the new add_allocation hook.
Date: Mon, 15 Aug 2022 18:21:01 +0200 [thread overview]
Message-ID: <ab17865f24f3bdf14eff39789509d6e246bcc713.1660580395.git.christophe.jaillet@wanadoo.fr> (raw)
In-Reply-To: <226fb08b3a13fd24f0739ab63bff369718003119.1660580395.git.christophe.jaillet@wanadoo.fr>
add_allocation_hook() already register many memory allocators. Use this
list and filter function that starts with devm_ to avoid duplicating part
of the list.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Not sure it is a really elegant solution or an improvement.
---
check_freeing_devm.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/check_freeing_devm.c b/check_freeing_devm.c
index 51fa990f1b4a..b77cdd25769f 100644
--- a/check_freeing_devm.c
+++ b/check_freeing_devm.c
@@ -26,6 +26,17 @@ static void match_assign(const char *fn, struct expression *expr, void *unused)
set_state_expr(my_id, expr->left, &devm);
}
+static void match_allocation(struct expression *expr,
+ const char *name, struct symbol *sym,
+ struct allocation_info *info)
+{
+ /*
+ * Only handle devm_ memory allocator
+ */
+ if (strncmp(info->fn_name, "devm_", 5) == 0)
+ match_assign(name, expr, NULL);
+}
+
/*
* This hook deals with things like:
* ptr = devm_kmalloc(...);
@@ -96,12 +107,12 @@ void check_freeing_devm(int id)
my_id = id;
- add_function_assign_hook("devm_kmalloc", &match_assign, NULL);
- add_function_assign_hook("devm_kzalloc", &match_assign, NULL);
- add_function_assign_hook("devm_kcalloc", &match_assign, NULL);
- add_function_assign_hook("devm_kmalloc_array", &match_assign, NULL);
+ /*
+ * We register all allocation functions, but only devm_ will be handled
+ * in match_allocation()
+ */
+ add_allocation_hook(&match_allocation);
- add_function_assign_hook("devm_kmemdup", &match_assign, NULL);
add_function_assign_hook("devm_kstrdup", &match_assign, NULL);
add_function_assign_hook("devm_kasprintf", &match_assign, NULL);
add_function_assign_hook("devm_kvasprintf", &match_assign, NULL);
--
2.34.1
next prev parent reply other threads:[~2022-08-15 16:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 16:20 [PATCH 1/2] smatch_allocations: Record the function that allocates memory Christophe JAILLET
2022-08-15 16:21 ` Christophe JAILLET [this message]
2022-08-16 8:12 ` [PATCH 2/2] check_freeing_devm: Take advantage of the new add_allocation hook Dan Carpenter
2022-08-16 8:10 ` [PATCH 1/2] smatch_allocations: Record the function that allocates memory 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=ab17865f24f3bdf14eff39789509d6e246bcc713.1660580395.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).