media: imx: capture: Initialize video_device programmatically
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 15 Feb 2021 04:26:38 +0000 (05:26 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 11 Mar 2021 10:59:47 +0000 (11:59 +0100)
Overwriting the whole video_device isn't future-proof as it would
overwrite any field initialized by video_device_alloc(). Furthermore,
the current implementation modifies the global template video_device as
if it were a per-instance structure, which is bad practice. To fix all
this, initialize the video device programmatically in
imx_media_capture_device_init().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/imx/imx-media-capture.c

index 88de2eef74d2093fe79099d8a05c5d047677184c..78b6e592692f698386db0c1f32ecca9f9d6d4670 100644 (file)
@@ -672,16 +672,6 @@ static const struct v4l2_file_operations capture_fops = {
        .mmap           = vb2_fop_mmap,
 };
 
-static struct video_device capture_videodev = {
-       .fops           = &capture_fops,
-       .ioctl_ops      = &capture_ioctl_ops,
-       .minor          = -1,
-       .release        = video_device_release,
-       .vfl_dir        = VFL_DIR_RX,
-       .tvnorms        = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
-       .device_caps    = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING,
-};
-
 struct imx_media_buffer *
 imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
 {
@@ -809,17 +799,22 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
        spin_lock_init(&priv->q_lock);
 
        /* Allocate and initialize the video device. */
-       snprintf(capture_videodev.name, sizeof(capture_videodev.name),
-                "%s capture", src_sd->name);
-
        vfd = video_device_alloc();
        if (!vfd)
                return ERR_PTR(-ENOMEM);
 
-       *vfd = capture_videodev;
+       vfd->fops = &capture_fops;
+       vfd->ioctl_ops = &capture_ioctl_ops;
+       vfd->minor = -1;
+       vfd->release = video_device_release;
+       vfd->vfl_dir = VFL_DIR_RX;
+       vfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
+       vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
        vfd->lock = &priv->mutex;
        vfd->queue = &priv->q;
 
+       snprintf(vfd->name, sizeof(vfd->name), "%s capture", src_sd->name);
+
        video_set_drvdata(vfd, priv);
        priv->vdev.vfd = vfd;
        INIT_LIST_HEAD(&priv->vdev.list);