Skip to content

Commit cc62c74

Browse files
WillLestermchehab
authored andcommitted
media: allegro: add missed checks in allegro_open()
allegro_open() misses checks for v4l2_m2m_ctx_init() and results of v4l2_ctrl_new* calls. Add checks and error handlers to fix the problems. Signed-off-by: Chuhong Yuan <hslester96@gmail.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 6b212c0 commit cc62c74

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎drivers/staging/media/allegro-dvt/allegro-core.c‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,15 +2270,12 @@ static int allegro_open(struct file *file)
22702270
struct allegro_channel *channel = NULL;
22712271
struct v4l2_ctrl_handler *handler;
22722272
u64 mask;
2273+
int ret;
22732274

22742275
channel = kzalloc(sizeof(*channel), GFP_KERNEL);
22752276
if (!channel)
22762277
return -ENOMEM;
22772278

2278-
v4l2_fh_init(&channel->fh, vdev);
2279-
file->private_data = &channel->fh;
2280-
v4l2_fh_add(&channel->fh);
2281-
22822279
init_completion(&channel->completion);
22832280

22842281
channel->dev = dev;
@@ -2328,6 +2325,11 @@ static int allegro_open(struct file *file)
23282325
V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
23292326
1, 32,
23302327
1, 1);
2328+
if (handler->error != 0) {
2329+
ret = handler->error;
2330+
goto error;
2331+
}
2332+
23312333
channel->fh.ctrl_handler = handler;
23322334

23332335
channel->mcu_channel_id = -1;
@@ -2341,7 +2343,21 @@ static int allegro_open(struct file *file)
23412343
channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel,
23422344
allegro_queue_init);
23432345

2346+
if (IS_ERR(channel->fh.m2m_ctx)) {
2347+
ret = PTR_ERR(channel->fh.m2m_ctx);
2348+
goto error;
2349+
}
2350+
2351+
v4l2_fh_init(&channel->fh, vdev);
2352+
file->private_data = &channel->fh;
2353+
v4l2_fh_add(&channel->fh);
2354+
23442355
return 0;
2356+
2357+
error:
2358+
v4l2_ctrl_handler_free(handler);
2359+
kfree(channel);
2360+
return ret;
23452361
}
23462362

23472363
static int allegro_release(struct file *file)

0 commit comments

Comments
 (0)