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

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

[media] vim2m: embed video_device



Embed the video_device struct to simplify the error handling and in
order to (eventually) get rid of video_device_alloc/release.

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Cc: Kamil Debski <k.debski@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 635d62f0
Loading
Loading
Loading
Loading
+7 −16
Original line number Original line Diff line number Diff line
@@ -142,7 +142,7 @@ static struct vim2m_fmt *find_format(struct v4l2_format *f)


struct vim2m_dev {
struct vim2m_dev {
	struct v4l2_device	v4l2_dev;
	struct v4l2_device	v4l2_dev;
	struct video_device	*vfd;
	struct video_device	vfd;


	atomic_t		num_inst;
	atomic_t		num_inst;
	struct mutex		dev_mutex;
	struct mutex		dev_mutex;
@@ -968,7 +968,7 @@ static struct video_device vim2m_videodev = {
	.fops		= &vim2m_fops,
	.fops		= &vim2m_fops,
	.ioctl_ops	= &vim2m_ioctl_ops,
	.ioctl_ops	= &vim2m_ioctl_ops,
	.minor		= -1,
	.minor		= -1,
	.release	= video_device_release,
	.release	= video_device_release_empty,
};
};


static struct v4l2_m2m_ops m2m_ops = {
static struct v4l2_m2m_ops m2m_ops = {
@@ -996,26 +996,19 @@ static int vim2m_probe(struct platform_device *pdev)
	atomic_set(&dev->num_inst, 0);
	atomic_set(&dev->num_inst, 0);
	mutex_init(&dev->dev_mutex);
	mutex_init(&dev->dev_mutex);


	vfd = video_device_alloc();
	dev->vfd = vim2m_videodev;
	if (!vfd) {
	vfd = &dev->vfd;
		v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n");
		ret = -ENOMEM;
		goto unreg_dev;
	}

	*vfd = vim2m_videodev;
	vfd->lock = &dev->dev_mutex;
	vfd->lock = &dev->dev_mutex;
	vfd->v4l2_dev = &dev->v4l2_dev;
	vfd->v4l2_dev = &dev->v4l2_dev;


	ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
	ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
	if (ret) {
	if (ret) {
		v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
		v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
		goto rel_vdev;
		goto unreg_dev;
	}
	}


	video_set_drvdata(vfd, dev);
	video_set_drvdata(vfd, dev);
	snprintf(vfd->name, sizeof(vfd->name), "%s", vim2m_videodev.name);
	snprintf(vfd->name, sizeof(vfd->name), "%s", vim2m_videodev.name);
	dev->vfd = vfd;
	v4l2_info(&dev->v4l2_dev,
	v4l2_info(&dev->v4l2_dev,
			"Device registered as /dev/video%d\n", vfd->num);
			"Device registered as /dev/video%d\n", vfd->num);


@@ -1033,9 +1026,7 @@ static int vim2m_probe(struct platform_device *pdev)


err_m2m:
err_m2m:
	v4l2_m2m_release(dev->m2m_dev);
	v4l2_m2m_release(dev->m2m_dev);
	video_unregister_device(dev->vfd);
	video_unregister_device(&dev->vfd);
rel_vdev:
	video_device_release(vfd);
unreg_dev:
unreg_dev:
	v4l2_device_unregister(&dev->v4l2_dev);
	v4l2_device_unregister(&dev->v4l2_dev);


@@ -1049,7 +1040,7 @@ static int vim2m_remove(struct platform_device *pdev)
	v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_NAME);
	v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_NAME);
	v4l2_m2m_release(dev->m2m_dev);
	v4l2_m2m_release(dev->m2m_dev);
	del_timer_sync(&dev->timer);
	del_timer_sync(&dev->timer);
	video_unregister_device(dev->vfd);
	video_unregister_device(&dev->vfd);
	v4l2_device_unregister(&dev->v4l2_dev);
	v4l2_device_unregister(&dev->v4l2_dev);


	return 0;
	return 0;