Commit bbc5296f authored by Sylwester Nawrocki's avatar Sylwester Nawrocki Committed by Mauro Carvalho Chehab

[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: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 31d34d9b
...@@ -1663,6 +1663,9 @@ static int fimc_capture_subdev_registered(struct v4l2_subdev *sd) ...@@ -1663,6 +1663,9 @@ static int fimc_capture_subdev_registered(struct v4l2_subdev *sd)
struct fimc_dev *fimc = v4l2_get_subdevdata(sd); struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
int ret; int ret;
if (fimc == NULL)
return -ENXIO;
ret = fimc_register_m2m_device(fimc, sd->v4l2_dev); ret = fimc_register_m2m_device(fimc, sd->v4l2_dev);
if (ret) if (ret)
return ret; return ret;
......
...@@ -287,7 +287,7 @@ struct fimc_frame { ...@@ -287,7 +287,7 @@ struct fimc_frame {
* @refcnt: the reference counter * @refcnt: the reference counter
*/ */
struct fimc_m2m_device { struct fimc_m2m_device {
struct video_device *vfd; struct video_device vfd;
struct v4l2_m2m_dev *m2m_dev; struct v4l2_m2m_dev *m2m_dev;
struct fimc_ctx *ctx; struct fimc_ctx *ctx;
int refcnt; int refcnt;
......
...@@ -370,7 +370,7 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh, ...@@ -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); vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
if (vb2_is_busy(vq)) { 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; return -EBUSY;
} }
...@@ -507,7 +507,7 @@ static int fimc_m2m_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr) ...@@ -507,7 +507,7 @@ static int fimc_m2m_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr)
int i; int i;
if (cr->c.top < 0 || cr->c.left < 0) { 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"); "doesn't support negative values for top & left\n");
return -EINVAL; return -EINVAL;
} }
...@@ -577,7 +577,7 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, const struct v4l2_crop * ...@@ -577,7 +577,7 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, const struct v4l2_crop *
cr->c.height, ctx->rotation); cr->c.height, ctx->rotation);
} }
if (ret) { if (ret) {
v4l2_err(fimc->m2m.vfd, "Out of scaler range\n"); v4l2_err(&fimc->m2m.vfd, "Out of scaler range\n");
return -EINVAL; return -EINVAL;
} }
} }
...@@ -664,7 +664,7 @@ static int fimc_m2m_open(struct file *file) ...@@ -664,7 +664,7 @@ static int fimc_m2m_open(struct file *file)
ret = -ENOMEM; ret = -ENOMEM;
goto unlock; goto unlock;
} }
v4l2_fh_init(&ctx->fh, fimc->m2m.vfd); v4l2_fh_init(&ctx->fh, &fimc->m2m.vfd);
ctx->fimc_dev = fimc; ctx->fimc_dev = fimc;
/* Default color format */ /* Default color format */
...@@ -782,39 +782,27 @@ static struct v4l2_m2m_ops m2m_ops = { ...@@ -782,39 +782,27 @@ static struct v4l2_m2m_ops m2m_ops = {
int fimc_register_m2m_device(struct fimc_dev *fimc, int fimc_register_m2m_device(struct fimc_dev *fimc,
struct v4l2_device *v4l2_dev) struct v4l2_device *v4l2_dev)
{ {
struct video_device *vfd; struct video_device *vfd = &fimc->m2m.vfd;
struct platform_device *pdev; int ret;
int ret = 0;
if (!fimc)
return -ENODEV;
pdev = fimc->pdev;
fimc->v4l2_dev = v4l2_dev; fimc->v4l2_dev = v4l2_dev;
vfd = video_device_alloc(); memset(vfd, 0, sizeof(*vfd));
if (!vfd) {
v4l2_err(v4l2_dev, "Failed to allocate video device\n");
return -ENOMEM;
}
vfd->fops = &fimc_m2m_fops; vfd->fops = &fimc_m2m_fops;
vfd->ioctl_ops = &fimc_m2m_ioctl_ops; vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
vfd->v4l2_dev = v4l2_dev; vfd->v4l2_dev = v4l2_dev;
vfd->minor = -1; vfd->minor = -1;
vfd->release = video_device_release; vfd->release = video_device_release_empty;
vfd->lock = &fimc->lock; vfd->lock = &fimc->lock;
vfd->vfl_dir = VFL_DIR_M2M; vfd->vfl_dir = VFL_DIR_M2M;
snprintf(vfd->name, sizeof(vfd->name), "fimc.%d.m2m", fimc->id); snprintf(vfd->name, sizeof(vfd->name), "fimc.%d.m2m", fimc->id);
video_set_drvdata(vfd, fimc); video_set_drvdata(vfd, fimc);
fimc->m2m.vfd = vfd;
fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops); fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
if (IS_ERR(fimc->m2m.m2m_dev)) { if (IS_ERR(fimc->m2m.m2m_dev)) {
v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n"); v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
ret = PTR_ERR(fimc->m2m.m2m_dev); return PTR_ERR(fimc->m2m.m2m_dev);
goto err_init;
} }
ret = media_entity_init(&vfd->entity, 0, NULL, 0); ret = media_entity_init(&vfd->entity, 0, NULL, 0);
...@@ -833,8 +821,6 @@ int fimc_register_m2m_device(struct fimc_dev *fimc, ...@@ -833,8 +821,6 @@ int fimc_register_m2m_device(struct fimc_dev *fimc,
media_entity_cleanup(&vfd->entity); media_entity_cleanup(&vfd->entity);
err_me: err_me:
v4l2_m2m_release(fimc->m2m.m2m_dev); v4l2_m2m_release(fimc->m2m.m2m_dev);
err_init:
video_device_release(fimc->m2m.vfd);
return ret; return ret;
} }
...@@ -845,9 +831,9 @@ void fimc_unregister_m2m_device(struct fimc_dev *fimc) ...@@ -845,9 +831,9 @@ void fimc_unregister_m2m_device(struct fimc_dev *fimc)
if (fimc->m2m.m2m_dev) if (fimc->m2m.m2m_dev)
v4l2_m2m_release(fimc->m2m.m2m_dev); v4l2_m2m_release(fimc->m2m.m2m_dev);
if (fimc->m2m.vfd) {
media_entity_cleanup(&fimc->m2m.vfd->entity); if (video_is_registered(&fimc->m2m.vfd)) {
/* Can also be called if video device wasn't registered */ video_unregister_device(&fimc->m2m.vfd);
video_unregister_device(fimc->m2m.vfd); media_entity_cleanup(&fimc->m2m.vfd.entity);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment