stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "stable@vger.kernel.org" <stable@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Ezequiel Garcia <ezequiel@collabora.com>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL 4.9 20/57] media: sta2x11: Add video_device and vb2_queue locks
Date: Mon, 17 Sep 2018 03:03:55 +0000	[thread overview]
Message-ID: <20180917030340.378-20-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180917030340.378-1-alexander.levin@microsoft.com>

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

  parent reply	other threads:[~2018-09-17  8:31 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-17  3:03 [PATCH AUTOSEL 4.9 01/57] crypto: skcipher - Fix -Wstringop-truncation warnings Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 03/57] vmci: type promotion bug in qp_host_get_user_memory() Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 02/57] tsl2550: fix lux1_input error in low light Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 04/57] x86/numa_emulation: Fix emulated-to-physical node mapping Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 06/57] uwb: hwa-rc: fix memory leak at probe Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 05/57] staging: rts5208: fix missing error check on call to rtsx_write_register Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 08/57] iommu/amd: make sure TLB to be flushed before IOVA freed Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 07/57] power: vexpress: fix corruption in notifier registration Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 10/57] USB: serial: kobil_sct: fix modem-status error handling Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 09/57] Bluetooth: Add a new Realtek 8723DE ID 0bda:b009 Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 12/57] s390/mm: correct allocate_pgste proc_handler callback Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 11/57] 6lowpan: iphc: reset mac_header after decompress to fix panic Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 13/57] power: remove possible deadlock when unregistering power_supply Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 14/57] md-cluster: clear another node's suspend_area after the copy is finished Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 15/57] arm64: fix infinite stacktrace Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 17/57] media: exynos4-is: Prevent NULL pointer dereference in __isp_video_try_fmt() Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 16/57] IB/core: type promotion bug in rdma_rw_init_one_mr() Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 18/57] powerpc/kdump: Handle crashkernel memory reservation failure Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 19/57] media: fsl-viu: fix error handling in viu_of_probe() Sasha Levin
2018-09-17  3:03 ` Sasha Levin [this message]
2018-09-17 11:50   ` [PATCH AUTOSEL 4.9 20/57] media: sta2x11: Add video_device and vb2_queue locks Ezequiel Garcia
2018-09-27 19:52     ` Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 22/57] ARM: hwmod: RTC: Don't assume lock/unlock will be called with irq enabled Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 21/57] x86/tsc: Add missing header to tsc_msr.c Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 23/57] x86/entry/64: Add two more instruction suffixes Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 24/57] scsi: target/iscsi: Make iscsit_ta_authentication() respect the output buffer size Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 25/57] scsi: klist: Make it safe to use klists in atomic context Sasha Levin
2018-09-17  3:03 ` [PATCH AUTOSEL 4.9 26/57] scsi: ibmvscsi: Improve strings handling Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 27/57] usb: wusbcore: security: cast sizeof to int for comparison Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 28/57] powerpc/powernv/ioda2: Reduce upper limit for DMA window size Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 30/57] s390/extmem: fix gcc 8 stringop-overflow warning Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 29/57] alarmtimer: Prevent overflow for relative nanosleep Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 31/57] ALSA: snd-aoa: add of_node_put() in error path Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 32/57] media: s3c-camif: ignore -ENOIOCTLCMD from v4l2_subdev_call for s_power Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 33/57] media: soc_camera: ov772x: correct setting of banding filter Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 35/57] staging: android: ashmem: Fix mmap size validation Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 34/57] media: omap3isp: zero-initialize the isp cam_xclk{a,b} initial data Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 36/57] drivers/tty: add error handling for pcmcia_loop_config Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 38/57] ALSA: hda: Add AZX_DCAPS_PM_RUNTIME for AMD Raven Ridge Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 37/57] media: tm6000: add error handling for dvb_register_adapter Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 40/57] ath10k: protect ath10k_htt_rx_ring_free with rx_ring.lock Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 39/57] net: phy: xgmiitorgmii: Check read_status results Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 41/57] net: phy: xgmiitorgmii: Check phy_driver ready before accessing Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 42/57] drm/sun4i: Fix releasing node when enumerating enpoints Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 43/57] rndis_wlan: potential buffer overflow in rndis_wlan_auth_indication() Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 45/57] ARM: mvebu: declare asm symbols as character arrays in pmsu.c Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 44/57] wlcore: Add missing PM call for wlcore_cmd_wait_for_event_or_timeout() Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 46/57] HID: hid-ntrig: add error handling for sysfs_create_group Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 48/57] scsi: bnx2i: add error handling for ioremap_nocache Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 47/57] perf/x86/intel/lbr: Fix incomplete LBR call stack Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 49/57] audit: Fix extended comparison of GID/EGID Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 50/57] scsi: megaraid_sas: Update controller info during resume Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 52/57] ASoC: dapm: Fix potential DAI widget pointer deref when linking DAIs Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 51/57] EDAC, i7core: Fix memleaks and use-after-free on probe and remove Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 53/57] module: exclude SHN_UNDEF symbols from kallsyms api Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 55/57] nfsd: fix corrupted reply to badly ordered compound Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 54/57] gpio: Fix wrong rounding in gpio-menz127 Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 56/57] EDAC: Fix memleak in module init error path Sasha Levin
2018-09-17  3:04 ` [PATCH AUTOSEL 4.9 57/57] ARM: dts: dra7: fix DCAN node addresses Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180917030340.378-20-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=ezequiel@collabora.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab+samsung@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).