lkml.org 
[lkml]   [2018]   [Sep]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 4.9 20/57] media: sta2x11: Add video_device and vb2_queue locks
    Date
    From: Ezequiel Garcia <ezequiel@collabora.com>

    [ Upstream commit cd63c0288fd760ce7de247fba618e2bbcfc0c35c ]

    Currently, this driver does not serialize its video4linux
    ioctls, which is a bug, as race conditions might appear.

    In addition, video_device and vb2_queue locks are now both
    mandatory. Add them, and implement wait_prepare and
    wait_finish.

    To stay on the safe side, this commit uses a single mutex
    for both locks. Better latency can be obtained by separating
    these if needed.

    Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
    Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
    Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
    Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
    ---
    drivers/media/pci/sta2x11/sta2x11_vip.c | 6 ++++++
    1 file changed, 6 insertions(+)

    diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
    index aeb2b4e2db35..521a6f84359d 100644
    --- a/drivers/media/pci/sta2x11/sta2x11_vip.c
    +++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
    @@ -145,6 +145,7 @@ struct sta2x11_vip {
    unsigned int sequence;
    struct vip_buffer *active; /* current active buffer */
    spinlock_t lock; /* Used in videobuf2 callback */
    + struct mutex v4l_lock;

    /* Interrupt counters */
    int tcount, bcount;
    @@ -385,6 +386,8 @@ static struct vb2_ops vip_video_qops = {
    .buf_queue = buffer_queue,
    .start_streaming = start_streaming,
    .stop_streaming = stop_streaming,
    + .wait_prepare = vb2_ops_wait_prepare,
    + .wait_finish = vb2_ops_wait_finish,
    };


    @@ -859,6 +862,7 @@ static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
    vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
    vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
    vip->vb_vidq.dev = &vip->pdev->dev;
    + vip->vb_vidq.lock = &vip->v4l_lock;
    err = vb2_queue_init(&vip->vb_vidq);
    if (err)
    return err;
    @@ -1024,6 +1028,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
    vip->std = V4L2_STD_PAL;
    vip->format = formats_50[0];
    vip->config = config;
    + mutex_init(&vip->v4l_lock);

    ret = sta2x11_vip_init_controls(vip);
    if (ret)
    @@ -1070,6 +1075,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
    vip->video_dev = video_dev_template;
    vip->video_dev.v4l2_dev = &vip->v4l2_dev;
    vip->video_dev.queue = &vip->vb_vidq;
    + vip->video_dev.lock = &vip->v4l_lock;
    video_set_drvdata(&vip->video_dev, vip);

    ret = video_register_device(&vip->video_dev, VFL_TYPE_GRABBER, -1);
    --
    2.17.1
    \
     
     \ /
      Last update: 2018-09-17 05:16    [W:2.224 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site