Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chuhong Yuan and committed by
Mauro Carvalho Chehab
cc62c747 6b212c0c

+20 -4
+20 -4
drivers/staging/media/allegro-dvt/allegro-core.c
··· 2270 2270 struct allegro_channel *channel = NULL; 2271 2271 struct v4l2_ctrl_handler *handler; 2272 2272 u64 mask; 2273 + int ret; 2273 2274 2274 2275 channel = kzalloc(sizeof(*channel), GFP_KERNEL); 2275 2276 if (!channel) 2276 2277 return -ENOMEM; 2277 - 2278 - v4l2_fh_init(&channel->fh, vdev); 2279 - file->private_data = &channel->fh; 2280 - v4l2_fh_add(&channel->fh); 2281 2278 2282 2279 init_completion(&channel->completion); 2283 2280 ··· 2325 2328 V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, 2326 2329 1, 32, 2327 2330 1, 1); 2331 + if (handler->error != 0) { 2332 + ret = handler->error; 2333 + goto error; 2334 + } 2335 + 2328 2336 channel->fh.ctrl_handler = handler; 2329 2337 2330 2338 channel->mcu_channel_id = -1; ··· 2343 2341 channel->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, channel, 2344 2342 allegro_queue_init); 2345 2343 2344 + if (IS_ERR(channel->fh.m2m_ctx)) { 2345 + ret = PTR_ERR(channel->fh.m2m_ctx); 2346 + goto error; 2347 + } 2348 + 2349 + v4l2_fh_init(&channel->fh, vdev); 2350 + file->private_data = &channel->fh; 2351 + v4l2_fh_add(&channel->fh); 2352 + 2346 2353 return 0; 2354 + 2355 + error: 2356 + v4l2_ctrl_handler_free(handler); 2357 + kfree(channel); 2358 + return ret; 2347 2359 } 2348 2360 2349 2361 static int allegro_release(struct file *file)