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

[media] mtk-mdp: allocate video_device dynamically

It can fix known problems with embedded video_device structs.

Signed-off-by: Minghsiu Tsai <minghsiu.tsai@mediatek.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Minghsiu Tsai and committed by
Mauro Carvalho Chehab
7febb418 4c0c596a

+21 -14
+1 -1
drivers/media/platform/mtk-mdp/mtk_mdp_core.h
··· 167 167 struct mtk_mdp_comp *comp[MTK_MDP_COMP_ID_MAX]; 168 168 struct v4l2_m2m_dev *m2m_dev; 169 169 struct list_head ctx_list; 170 - struct video_device vdev; 170 + struct video_device *vdev; 171 171 struct v4l2_device v4l2_dev; 172 172 struct workqueue_struct *job_wq; 173 173 struct platform_device *vpu_dev;
+20 -13
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
··· 1236 1236 int ret; 1237 1237 1238 1238 mdp->variant = &mtk_mdp_default_variant; 1239 - mdp->vdev.device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; 1240 - mdp->vdev.fops = &mtk_mdp_m2m_fops; 1241 - mdp->vdev.ioctl_ops = &mtk_mdp_m2m_ioctl_ops; 1242 - mdp->vdev.release = video_device_release_empty; 1243 - mdp->vdev.lock = &mdp->lock; 1244 - mdp->vdev.vfl_dir = VFL_DIR_M2M; 1245 - mdp->vdev.v4l2_dev = &mdp->v4l2_dev; 1246 - snprintf(mdp->vdev.name, sizeof(mdp->vdev.name), "%s:m2m", 1239 + mdp->vdev = video_device_alloc(); 1240 + if (!mdp->vdev) { 1241 + dev_err(dev, "failed to allocate video device\n"); 1242 + ret = -ENOMEM; 1243 + goto err_video_alloc; 1244 + } 1245 + mdp->vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; 1246 + mdp->vdev->fops = &mtk_mdp_m2m_fops; 1247 + mdp->vdev->ioctl_ops = &mtk_mdp_m2m_ioctl_ops; 1248 + mdp->vdev->release = video_device_release; 1249 + mdp->vdev->lock = &mdp->lock; 1250 + mdp->vdev->vfl_dir = VFL_DIR_M2M; 1251 + mdp->vdev->v4l2_dev = &mdp->v4l2_dev; 1252 + snprintf(mdp->vdev->name, sizeof(mdp->vdev->name), "%s:m2m", 1247 1253 MTK_MDP_MODULE_NAME); 1248 - video_set_drvdata(&mdp->vdev, mdp); 1254 + video_set_drvdata(mdp->vdev, mdp); 1249 1255 1250 1256 mdp->m2m_dev = v4l2_m2m_init(&mtk_mdp_m2m_ops); 1251 1257 if (IS_ERR(mdp->m2m_dev)) { ··· 1260 1254 goto err_m2m_init; 1261 1255 } 1262 1256 1263 - ret = video_register_device(&mdp->vdev, VFL_TYPE_GRABBER, 2); 1257 + ret = video_register_device(mdp->vdev, VFL_TYPE_GRABBER, 2); 1264 1258 if (ret) { 1265 1259 dev_err(dev, "failed to register video device\n"); 1266 1260 goto err_vdev_register; 1267 1261 } 1268 1262 1269 1263 v4l2_info(&mdp->v4l2_dev, "driver registered as /dev/video%d", 1270 - mdp->vdev.num); 1264 + mdp->vdev->num); 1271 1265 return 0; 1272 1266 1273 1267 err_vdev_register: 1274 1268 v4l2_m2m_release(mdp->m2m_dev); 1275 1269 err_m2m_init: 1276 - video_device_release(&mdp->vdev); 1270 + video_device_release(mdp->vdev); 1271 + err_video_alloc: 1277 1272 1278 1273 return ret; 1279 1274 } 1280 1275 1281 1276 void mtk_mdp_unregister_m2m_device(struct mtk_mdp_dev *mdp) 1282 1277 { 1283 - video_device_release(&mdp->vdev); 1278 + video_unregister_device(mdp->vdev); 1284 1279 v4l2_m2m_release(mdp->m2m_dev); 1285 1280 }