Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fac3639d authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (8414): videodev/cx18: fix get_index bug and error-handling lock-ups



Fix a bug in get_index that was introduced earlier.
Also fix two error handling lock-ups in videodev and cx18 that
where found thanks to that bug.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent f19ad390
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -311,8 +311,10 @@ void cx18_streams_cleanup(struct cx18 *cx, int unregister)


	/* Teardown all streams */
	/* Teardown all streams */
	for (type = 0; type < CX18_MAX_STREAMS; type++) {
	for (type = 0; type < CX18_MAX_STREAMS; type++) {
		if (cx->streams[type].dvb.enabled)
		if (cx->streams[type].dvb.enabled) {
			cx18_dvb_unregister(&cx->streams[type]);
			cx18_dvb_unregister(&cx->streams[type]);
			cx->streams[type].dvb.enabled = false;
		}


		vdev = cx->streams[type].v4l2dev;
		vdev = cx->streams[type].v4l2dev;


+5 −4
Original line number Original line Diff line number Diff line
@@ -2023,7 +2023,7 @@ EXPORT_SYMBOL(video_ioctl2);
static int get_index(struct video_device *vdev, int num)
static int get_index(struct video_device *vdev, int num)
{
{
	u32 used = 0;
	u32 used = 0;
	const unsigned max_index = sizeof(used) * 8 - 1;
	const int max_index = sizeof(used) * 8 - 1;
	int i;
	int i;


	/* Currently a single v4l driver instance cannot create more than
	/* Currently a single v4l driver instance cannot create more than
@@ -2145,14 +2145,15 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
	vfd->minor=i;
	vfd->minor=i;


	ret = get_index(vfd, index);
	ret = get_index(vfd, index);
	vfd->index = ret;

	mutex_unlock(&videodev_lock);

	if (ret < 0) {
	if (ret < 0) {
		printk(KERN_ERR "%s: get_index failed\n", __func__);
		printk(KERN_ERR "%s: get_index failed\n", __func__);
		goto fail_minor;
		goto fail_minor;
	}
	}


	vfd->index = ret;

	mutex_unlock(&videodev_lock);
	mutex_init(&vfd->lock);
	mutex_init(&vfd->lock);


	/* sysfs class */
	/* sysfs class */