Skip to content

Commit c0f71bb

Browse files
ArvindYadavCsmchehab
authored andcommitted
media: hdpvr: Fix an error handling path in hdpvr_probe()
Here, hdpvr_register_videodev() is responsible for setup and register a video device. Also defining and initializing a worker. hdpvr_register_videodev() is calling by hdpvr_probe at last. So no need to flush any work here. Unregister v4l2, free buffers and memory. If hdpvr_probe() will fail. Signed-off-by: Arvind Yadav <[email protected]> Reported-by: Andrey Konovalov <[email protected]> Tested-by: Andrey Konovalov <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent cee32ed commit c0f71bb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

drivers/media/usb/hdpvr/hdpvr-core.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ static int hdpvr_probe(struct usb_interface *interface,
292292
/* register v4l2_device early so it can be used for printks */
293293
if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) {
294294
dev_err(&interface->dev, "v4l2_device_register failed\n");
295-
goto error;
295+
goto error_free_dev;
296296
}
297297

298298
mutex_init(&dev->io_mutex);
@@ -301,7 +301,7 @@ static int hdpvr_probe(struct usb_interface *interface,
301301
dev->usbc_buf = kmalloc(64, GFP_KERNEL);
302302
if (!dev->usbc_buf) {
303303
v4l2_err(&dev->v4l2_dev, "Out of memory\n");
304-
goto error;
304+
goto error_v4l2_unregister;
305305
}
306306

307307
init_waitqueue_head(&dev->wait_buffer);
@@ -339,29 +339,29 @@ static int hdpvr_probe(struct usb_interface *interface,
339339
}
340340
if (!dev->bulk_in_endpointAddr) {
341341
v4l2_err(&dev->v4l2_dev, "Could not find bulk-in endpoint\n");
342-
goto error;
342+
goto error_put_usb;
343343
}
344344

345345
/* init the device */
346346
if (hdpvr_device_init(dev)) {
347347
v4l2_err(&dev->v4l2_dev, "device init failed\n");
348-
goto error;
348+
goto error_put_usb;
349349
}
350350

351351
mutex_lock(&dev->io_mutex);
352352
if (hdpvr_alloc_buffers(dev, NUM_BUFFERS)) {
353353
mutex_unlock(&dev->io_mutex);
354354
v4l2_err(&dev->v4l2_dev,
355355
"allocating transfer buffers failed\n");
356-
goto error;
356+
goto error_put_usb;
357357
}
358358
mutex_unlock(&dev->io_mutex);
359359

360360
#if IS_ENABLED(CONFIG_I2C)
361361
retval = hdpvr_register_i2c_adapter(dev);
362362
if (retval < 0) {
363363
v4l2_err(&dev->v4l2_dev, "i2c adapter register failed\n");
364-
goto error;
364+
goto error_free_buffers;
365365
}
366366

367367
client = hdpvr_register_ir_rx_i2c(dev);
@@ -394,13 +394,17 @@ static int hdpvr_probe(struct usb_interface *interface,
394394
reg_fail:
395395
#if IS_ENABLED(CONFIG_I2C)
396396
i2c_del_adapter(&dev->i2c_adapter);
397+
error_free_buffers:
397398
#endif
399+
hdpvr_free_buffers(dev);
400+
error_put_usb:
401+
usb_put_dev(dev->udev);
402+
kfree(dev->usbc_buf);
403+
error_v4l2_unregister:
404+
v4l2_device_unregister(&dev->v4l2_dev);
405+
error_free_dev:
406+
kfree(dev);
398407
error:
399-
if (dev) {
400-
flush_work(&dev->worker);
401-
/* this frees allocated memory */
402-
hdpvr_delete(dev);
403-
}
404408
return retval;
405409
}
406410

0 commit comments

Comments
 (0)