Message ID | 20221129110159.1541522-1-cuigaosheng1@huawei.com |
---|---|
State | Accepted |
Commit | 7acd650a0484d92985a0d6d867d980c6dd019885 |
Headers | show |
Series | media: ti: cal: fix possible memory leak in cal_ctx_create() | expand |
Hi Gaosheng, Thank you for the patch. On Tue, Nov 29, 2022 at 07:01:59PM +0800, Gaosheng Cui wrote: > The memory of ctx is allocated in cal_ctx_create(), but it will > not be freed when cal_ctx_v4l2_init() fails, so add kfree() when > cal_ctx_v4l2_init() fails to fix it. > > Fixes: d68a94e98a89 ("media: ti-vpe: cal: Split video device initialization and registration") > Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > drivers/media/platform/ti/cal/cal.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/platform/ti/cal/cal.c b/drivers/media/platform/ti/cal/cal.c > index 56b61c0583cf..1236215ec70e 100644 > --- a/drivers/media/platform/ti/cal/cal.c > +++ b/drivers/media/platform/ti/cal/cal.c > @@ -1050,8 +1050,10 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst) > ctx->cport = inst; > > ret = cal_ctx_v4l2_init(ctx); > - if (ret) > + if (ret) { > + kfree(ctx); > return NULL; > + } > > return ctx; > }
diff --git a/drivers/media/platform/ti/cal/cal.c b/drivers/media/platform/ti/cal/cal.c index 56b61c0583cf..1236215ec70e 100644 --- a/drivers/media/platform/ti/cal/cal.c +++ b/drivers/media/platform/ti/cal/cal.c @@ -1050,8 +1050,10 @@ static struct cal_ctx *cal_ctx_create(struct cal_dev *cal, int inst) ctx->cport = inst; ret = cal_ctx_v4l2_init(ctx); - if (ret) + if (ret) { + kfree(ctx); return NULL; + } return ctx; }
The memory of ctx is allocated in cal_ctx_create(), but it will not be freed when cal_ctx_v4l2_init() fails, so add kfree() when cal_ctx_v4l2_init() fails to fix it. Fixes: d68a94e98a89 ("media: ti-vpe: cal: Split video device initialization and registration") Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com> --- drivers/media/platform/ti/cal/cal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)