Re: [PATCH 03/30] v4l: vxd-dec: Create vxd_dec Mem Manager helper library

From: Dan Carpenter
Date: Tue Aug 24 2021 - 09:35:29 EST


On Wed, Aug 18, 2021 at 07:40:10PM +0530, sidraya.bj@xxxxxxxxxxxxxxxxxxx wrote:
> +int img_mem_create_ctx(struct mem_ctx **new_ctx)
> +{
> + struct mem_man *mem_man = &mem_man_data;
> + struct mem_ctx *ctx;
> +
> + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
> + if (!ctx)
> + return -ENOMEM;
> +
> + ctx->buffers = kzalloc(sizeof(*ctx->buffers), GFP_KERNEL);
> + if (!ctx->buffers)
> + return -ENOMEM;

Smatch would have caught that this needs a kfree(ctx); before returning.

It wouldn't hurt to run Smatch over this code.

git clone https://repo.or.cz/w/smatch.git
cd smatch
yum install gcc make sqlite3 sqlite-devel sqlite perl-DBD-SQLite openssl-devel perl-Try-Tiny
make
cd ~/kernel/
~/smatch/smatch_scripts/kchecker drivers/staging/media/vxd/common/img_mem_man.c

(I am the author of Smatch #BlowYourOwnTrumpet).

regards,
dan carpenter