From: Sylwester Nawrocki Date: Thu, 26 Jul 2012 10:59:11 +0000 (-0300) Subject: [media] s5p-fimc: Don't allocate fimc-m2m video device dynamically X-Git-Tag: upstream/snapshot3+hdmi~6521^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e6db30de7f994d388d996d508cf1ca043f2a455;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git [media] s5p-fimc: Don't allocate fimc-m2m video device dynamically There is no need to to dynamically allocate struct video_device for the M2M devices, so embed it instead in driver's private data structure as it is done in case of fimc-capture and fimc-lite, where it solves some bugs on cleanup paths. Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c index 5d3a70f..4092388 100644 --- a/drivers/media/video/s5p-fimc/fimc-capture.c +++ b/drivers/media/video/s5p-fimc/fimc-capture.c @@ -1663,6 +1663,9 @@ static int fimc_capture_subdev_registered(struct v4l2_subdev *sd) struct fimc_dev *fimc = v4l2_get_subdevdata(sd); int ret; + if (fimc == NULL) + return -ENXIO; + ret = fimc_register_m2m_device(fimc, sd->v4l2_dev); if (ret) return ret; diff --git a/drivers/media/video/s5p-fimc/fimc-core.h b/drivers/media/video/s5p-fimc/fimc-core.h index 30f93f2..d3a3a00 100644 --- a/drivers/media/video/s5p-fimc/fimc-core.h +++ b/drivers/media/video/s5p-fimc/fimc-core.h @@ -287,7 +287,7 @@ struct fimc_frame { * @refcnt: the reference counter */ struct fimc_m2m_device { - struct video_device *vfd; + struct video_device vfd; struct v4l2_m2m_dev *m2m_dev; struct fimc_ctx *ctx; int refcnt; diff --git a/drivers/media/video/s5p-fimc/fimc-m2m.c b/drivers/media/video/s5p-fimc/fimc-m2m.c index c587011..293e602 100644 --- a/drivers/media/video/s5p-fimc/fimc-m2m.c +++ b/drivers/media/video/s5p-fimc/fimc-m2m.c @@ -370,7 +370,7 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh, vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); if (vb2_is_busy(vq)) { - v4l2_err(fimc->m2m.vfd, "queue (%d) busy\n", f->type); + v4l2_err(&fimc->m2m.vfd, "queue (%d) busy\n", f->type); return -EBUSY; } @@ -507,7 +507,7 @@ static int fimc_m2m_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr) int i; if (cr->c.top < 0 || cr->c.left < 0) { - v4l2_err(fimc->m2m.vfd, + v4l2_err(&fimc->m2m.vfd, "doesn't support negative values for top & left\n"); return -EINVAL; } @@ -577,7 +577,7 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) cr->c.height, ctx->rotation); } if (ret) { - v4l2_err(fimc->m2m.vfd, "Out of scaler range\n"); + v4l2_err(&fimc->m2m.vfd, "Out of scaler range\n"); return -EINVAL; } } @@ -666,7 +666,7 @@ static int fimc_m2m_open(struct file *file) ret = -ENOMEM; goto unlock; } - v4l2_fh_init(&ctx->fh, fimc->m2m.vfd); + v4l2_fh_init(&ctx->fh, &fimc->m2m.vfd); ctx->fimc_dev = fimc; /* Default color format */ @@ -784,38 +784,26 @@ static struct v4l2_m2m_ops m2m_ops = { int fimc_register_m2m_device(struct fimc_dev *fimc, struct v4l2_device *v4l2_dev) { - struct video_device *vfd; - struct platform_device *pdev; - int ret = 0; - - if (!fimc) - return -ENODEV; + struct video_device *vfd = &fimc->m2m.vfd; + int ret; - pdev = fimc->pdev; fimc->v4l2_dev = v4l2_dev; - vfd = video_device_alloc(); - if (!vfd) { - v4l2_err(v4l2_dev, "Failed to allocate video device\n"); - return -ENOMEM; - } - + memset(vfd, 0, sizeof(*vfd)); vfd->fops = &fimc_m2m_fops; vfd->ioctl_ops = &fimc_m2m_ioctl_ops; vfd->v4l2_dev = v4l2_dev; vfd->minor = -1; - vfd->release = video_device_release; + vfd->release = video_device_release_empty; vfd->lock = &fimc->lock; snprintf(vfd->name, sizeof(vfd->name), "fimc.%d.m2m", fimc->id); video_set_drvdata(vfd, fimc); - fimc->m2m.vfd = vfd; fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops); if (IS_ERR(fimc->m2m.m2m_dev)) { v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n"); - ret = PTR_ERR(fimc->m2m.m2m_dev); - goto err_init; + return PTR_ERR(fimc->m2m.m2m_dev); } ret = media_entity_init(&vfd->entity, 0, NULL, 0); @@ -834,8 +822,6 @@ err_vd: media_entity_cleanup(&vfd->entity); err_me: v4l2_m2m_release(fimc->m2m.m2m_dev); -err_init: - video_device_release(fimc->m2m.vfd); return ret; } @@ -846,9 +832,9 @@ void fimc_unregister_m2m_device(struct fimc_dev *fimc) if (fimc->m2m.m2m_dev) v4l2_m2m_release(fimc->m2m.m2m_dev); - if (fimc->m2m.vfd) { - media_entity_cleanup(&fimc->m2m.vfd->entity); - /* Can also be called if video device wasn't registered */ - video_unregister_device(fimc->m2m.vfd); + + if (video_is_registered(&fimc->m2m.vfd)) { + video_unregister_device(&fimc->m2m.vfd); + media_entity_cleanup(&fimc->m2m.vfd.entity); } }