Re: [PATCH 1/2] smatch_allocations: Record the function that allocates memory

Dan Carpenter <[email protected]> Tue, 16 Aug 2022 11:10:18 +0300
Newsgroups org.kernel.vger.smatch
Message-ID <20220816081018.GP3438@kadam>
On Mon, Aug 15, 2022 at 06:20:55PM +0200, Christophe JAILLET wrote:
> Keep track of the name of the function that did the memory allocation.
> 
> Signed-off-by: Christophe JAILLET <[email protected]>
> ---
> Not sure if it is the best way to save this information. Maybe it can
> already be retrieved another way (from expr directly?)
> 

You could get it from the expr.  The expr is an assign expr

	foo = kmalloc(sizeof(*foo), GFP_KERNEL);

So you could do:

	while (expr->type == EXPR_ASSIGNMENT)
		expr = strip_expr(expr->right);

	if (expr->type != EXPR_CALL)
		return;

	name = expr_to_str(expr->fn);

At the same time putting it in the allocation_info feels like it might
be the right thing and it's basically no cost so I'm going to apply this.

regards,
dan carpenter