Commit cc62c747 authored by Chuhong Yuan's avatar Chuhong Yuan Committed by Mauro Carvalho Chehab

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: default avatarChuhong Yuan <hslester96@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 6b212c0c
...@@ -2270,15 +2270,12 @@ static int allegro_open(struct file *file) ...@@ -2270,15 +2270,12 @@ static int allegro_open(struct file *file)
struct allegro_channel *channel = NULL; struct allegro_channel *channel = NULL;
struct v4l2_ctrl_handler *handler; struct v4l2_ctrl_handler *handler;
u64 mask; u64 mask;
int ret;
channel = kzalloc(sizeof(*channel), GFP_KERNEL); channel = kzalloc(sizeof(*channel), GFP_KERNEL);
if (!channel) if (!channel)
return -ENOMEM; return -ENOMEM;
v4l2_fh_init(&channel->fh, vdev);
file->private_data = &channel->fh;
v4l2_fh_add(&channel->fh);
init_completion(&channel->completion); init_completion(&channel->completion);
channel->dev = dev; channel->dev = dev;
...@@ -2328,6 +2325,11 @@ static int allegro_open(struct file *file) ...@@ -2328,6 +2325,11 @@ static int allegro_open(struct file *file)
V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
1, 32, 1, 32,
1, 1); 1, 1);
if (handler->error != 0) {
ret = handler->error;
goto error;
}
channel->fh.ctrl_handler = handler; channel->fh.ctrl_handler = handler;
channel->mcu_channel_id = -1; channel->mcu_channel_id = -1;
...@@ -2341,7 +2343,21 @@ static int allegro_open(struct file *file) ...@@ -2341,7 +2343,21 @@ static int allegro_open(struct file *file)
channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel, channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel,
allegro_queue_init); allegro_queue_init);
if (IS_ERR(channel->fh.m2m_ctx)) {
ret = PTR_ERR(channel->fh.m2m_ctx);
goto error;
}
v4l2_fh_init(&channel->fh, vdev);
file->private_data = &channel->fh;
v4l2_fh_add(&channel->fh);
return 0; return 0;
error:
v4l2_ctrl_handler_free(handler);
kfree(channel);
return ret;
} }
static int allegro_release(struct file *file) static int allegro_release(struct file *file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment