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

Commit 7febb418 authored by Minghsiu Tsai's avatar Minghsiu Tsai Committed by Mauro Carvalho Chehab
Browse files

[media] mtk-mdp: allocate video_device dynamically



It can fix known problems with embedded video_device structs.

Signed-off-by: default avatarMinghsiu Tsai <minghsiu.tsai@mediatek.com>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 4c0c596a
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -167,7 +167,7 @@ struct mtk_mdp_dev {
	struct mtk_mdp_comp		*comp[MTK_MDP_COMP_ID_MAX];
	struct mtk_mdp_comp		*comp[MTK_MDP_COMP_ID_MAX];
	struct v4l2_m2m_dev		*m2m_dev;
	struct v4l2_m2m_dev		*m2m_dev;
	struct list_head		ctx_list;
	struct list_head		ctx_list;
	struct video_device		vdev;
	struct video_device		*vdev;
	struct v4l2_device		v4l2_dev;
	struct v4l2_device		v4l2_dev;
	struct workqueue_struct		*job_wq;
	struct workqueue_struct		*job_wq;
	struct platform_device		*vpu_dev;
	struct platform_device		*vpu_dev;
+20 −13
Original line number Original line Diff line number Diff line
@@ -1236,16 +1236,22 @@ int mtk_mdp_register_m2m_device(struct mtk_mdp_dev *mdp)
	int ret;
	int ret;


	mdp->variant = &mtk_mdp_default_variant;
	mdp->variant = &mtk_mdp_default_variant;
	mdp->vdev.device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
	mdp->vdev = video_device_alloc();
	mdp->vdev.fops = &mtk_mdp_m2m_fops;
	if (!mdp->vdev) {
	mdp->vdev.ioctl_ops = &mtk_mdp_m2m_ioctl_ops;
		dev_err(dev, "failed to allocate video device\n");
	mdp->vdev.release = video_device_release_empty;
		ret = -ENOMEM;
	mdp->vdev.lock = &mdp->lock;
		goto err_video_alloc;
	mdp->vdev.vfl_dir = VFL_DIR_M2M;
	}
	mdp->vdev.v4l2_dev = &mdp->v4l2_dev;
	mdp->vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
	snprintf(mdp->vdev.name, sizeof(mdp->vdev.name), "%s:m2m",
	mdp->vdev->fops = &mtk_mdp_m2m_fops;
	mdp->vdev->ioctl_ops = &mtk_mdp_m2m_ioctl_ops;
	mdp->vdev->release = video_device_release;
	mdp->vdev->lock = &mdp->lock;
	mdp->vdev->vfl_dir = VFL_DIR_M2M;
	mdp->vdev->v4l2_dev = &mdp->v4l2_dev;
	snprintf(mdp->vdev->name, sizeof(mdp->vdev->name), "%s:m2m",
		 MTK_MDP_MODULE_NAME);
		 MTK_MDP_MODULE_NAME);
	video_set_drvdata(&mdp->vdev, mdp);
	video_set_drvdata(mdp->vdev, mdp);


	mdp->m2m_dev = v4l2_m2m_init(&mtk_mdp_m2m_ops);
	mdp->m2m_dev = v4l2_m2m_init(&mtk_mdp_m2m_ops);
	if (IS_ERR(mdp->m2m_dev)) {
	if (IS_ERR(mdp->m2m_dev)) {
@@ -1254,26 +1260,27 @@ int mtk_mdp_register_m2m_device(struct mtk_mdp_dev *mdp)
		goto err_m2m_init;
		goto err_m2m_init;
	}
	}


	ret = video_register_device(&mdp->vdev, VFL_TYPE_GRABBER, 2);
	ret = video_register_device(mdp->vdev, VFL_TYPE_GRABBER, 2);
	if (ret) {
	if (ret) {
		dev_err(dev, "failed to register video device\n");
		dev_err(dev, "failed to register video device\n");
		goto err_vdev_register;
		goto err_vdev_register;
	}
	}


	v4l2_info(&mdp->v4l2_dev, "driver registered as /dev/video%d",
	v4l2_info(&mdp->v4l2_dev, "driver registered as /dev/video%d",
		  mdp->vdev.num);
		  mdp->vdev->num);
	return 0;
	return 0;


err_vdev_register:
err_vdev_register:
	v4l2_m2m_release(mdp->m2m_dev);
	v4l2_m2m_release(mdp->m2m_dev);
err_m2m_init:
err_m2m_init:
	video_device_release(&mdp->vdev);
	video_device_release(mdp->vdev);
err_video_alloc:


	return ret;
	return ret;
}
}


void mtk_mdp_unregister_m2m_device(struct mtk_mdp_dev *mdp)
void mtk_mdp_unregister_m2m_device(struct mtk_mdp_dev *mdp)
{
{
	video_device_release(&mdp->vdev);
	video_unregister_device(mdp->vdev);
	v4l2_m2m_release(mdp->m2m_dev);
	v4l2_m2m_release(mdp->m2m_dev);
}
}