From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Ezequiel Garcia , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH AUTOSEL 4.18 040/136] media: sta2x11: Add video_device and vb2_queue locks Date: Mon, 17 Sep 2018 03:00:37 +0000 Message-ID: <20180917030006.245495-40-alexander.levin@microsoft.com> References: <20180917030006.245495-1-alexander.levin@microsoft.com> In-Reply-To: <20180917030006.245495-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: From: Ezequiel Garcia [ 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 Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- 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/st= a2x11/sta2x11_vip.c index 069c4a853346..da2b2a2292d0 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; =20 /* Interrupt counters */ int tcount, bcount; @@ -385,6 +386,8 @@ static const struct vb2_ops vip_video_qops =3D { .buf_queue =3D buffer_queue, .start_streaming =3D start_streaming, .stop_streaming =3D stop_streaming, + .wait_prepare =3D vb2_ops_wait_prepare, + .wait_finish =3D vb2_ops_wait_finish, }; =20 =20 @@ -870,6 +873,7 @@ static int sta2x11_vip_init_buffer(struct sta2x11_vip *= vip) vip->vb_vidq.mem_ops =3D &vb2_dma_contig_memops; vip->vb_vidq.timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; vip->vb_vidq.dev =3D &vip->pdev->dev; + vip->vb_vidq.lock =3D &vip->v4l_lock; err =3D vb2_queue_init(&vip->vb_vidq); if (err) return err; @@ -1034,6 +1038,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev, vip->std =3D V4L2_STD_PAL; vip->format =3D formats_50[0]; vip->config =3D config; + mutex_init(&vip->v4l_lock); =20 ret =3D sta2x11_vip_init_controls(vip); if (ret) @@ -1080,6 +1085,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev, vip->video_dev =3D video_dev_template; vip->video_dev.v4l2_dev =3D &vip->v4l2_dev; vip->video_dev.queue =3D &vip->vb_vidq; + vip->video_dev.lock =3D &vip->v4l_lock; video_set_drvdata(&vip->video_dev, vip); =20 ret =3D video_register_device(&vip->video_dev, VFL_TYPE_GRABBER, -1); --=20 2.17.1