linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Hans Verkuil <hverkuil@xs4all.nl>,
	Keith Pyle <kpyle@austin.rr.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 5.1 137/219] media: hdpvr: fix locking and a missing msleep
Date: Mon, 15 Jul 2019 10:02:18 -0400	[thread overview]
Message-ID: <20190715140341.6443-137-sashal@kernel.org> (raw)
In-Reply-To: <20190715140341.6443-1-sashal@kernel.org>

From: Hans Verkuil <hverkuil@xs4all.nl>

[ Upstream commit 6bc5a4a1927556ff9adce1aa95ea408c95453225 ]

This driver has three locking issues:

- The wait_event_interruptible() condition calls hdpvr_get_next_buffer(dev)
  which uses a mutex, which is not allowed. Rewrite with list_empty_careful()
  that doesn't need locking.

- In hdpvr_read() the call to hdpvr_stop_streaming() didn't lock io_mutex,
  but it should have since stop_streaming expects that.

- In hdpvr_device_release() io_mutex was locked when calling flush_work(),
  but there it shouldn't take that mutex since the work done by flush_work()
  also wants to lock that mutex.

There are also two other changes (suggested by Keith):

- msecs_to_jiffies(4000); (a NOP) should have been msleep(4000).
- Change v4l2_dbg to v4l2_info to always log if streaming had to be restarted.

Reported-by: Keith Pyle <kpyle@austin.rr.com>
Suggested-by: Keith Pyle <kpyle@austin.rr.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/media/usb/hdpvr/hdpvr-video.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c
index e082086428a4..ae6609716347 100644
--- a/drivers/media/usb/hdpvr/hdpvr-video.c
+++ b/drivers/media/usb/hdpvr/hdpvr-video.c
@@ -439,7 +439,7 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
 	/* wait for the first buffer */
 	if (!(file->f_flags & O_NONBLOCK)) {
 		if (wait_event_interruptible(dev->wait_data,
-					     hdpvr_get_next_buffer(dev)))
+					     !list_empty_careful(&dev->rec_buff_list)))
 			return -ERESTARTSYS;
 	}
 
@@ -465,10 +465,17 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
 				goto err;
 			}
 			if (!err) {
-				v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
-					"timeout: restart streaming\n");
+				v4l2_info(&dev->v4l2_dev,
+					  "timeout: restart streaming\n");
+				mutex_lock(&dev->io_mutex);
 				hdpvr_stop_streaming(dev);
-				msecs_to_jiffies(4000);
+				mutex_unlock(&dev->io_mutex);
+				/*
+				 * The FW needs about 4 seconds after streaming
+				 * stopped before it is ready to restart
+				 * streaming.
+				 */
+				msleep(4000);
 				err = hdpvr_start_streaming(dev);
 				if (err) {
 					ret = err;
@@ -1133,9 +1140,7 @@ static void hdpvr_device_release(struct video_device *vdev)
 	struct hdpvr_device *dev = video_get_drvdata(vdev);
 
 	hdpvr_delete(dev);
-	mutex_lock(&dev->io_mutex);
 	flush_work(&dev->worker);
-	mutex_unlock(&dev->io_mutex);
 
 	v4l2_device_unregister(&dev->v4l2_dev);
 	v4l2_ctrl_handler_free(&dev->hdl);
-- 
2.20.1


      parent reply	other threads:[~2019-07-15 15:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190715140341.6443-1-sashal@kernel.org>
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 019/219] media: dvb: usb: fix use after free in dvb_usb_device_exit Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 020/219] media: spi: IR LED: add missing of table registration Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 022/219] media: ov7740: avoid invalid framesize setting Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 023/219] media: marvell-ccic: fix DMA s/g desc number calculation Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 024/219] media: vpss: fix a potential NULL pointer dereference Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 025/219] media: media_device_enum_links32: clean a reserved field Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 026/219] media: venus: firmware: fix leaked of_node references Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 037/219] media: vim2m: fix two double-free issues Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 038/219] media: v4l2-core: fix use-after-free error Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 040/219] media: usb:zr364xx:Fix KASAN:null-ptr-deref Read in zr364xx_vidioc_querycap Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 044/219] media: mc-device.c: don't memset __user pointer contents Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 045/219] media: saa7164: fix remove_proc_entry warning Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 046/219] media: staging: media: davinci_vpfe: - Fix for memory leak if decoder initialization fails Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 050/219] tua6100: Avoid build warnings Sasha Levin
2019-07-15 14:00 ` [PATCH AUTOSEL 5.1 054/219] media: wl128x: Fix some error handling in fm_v4l2_init_video_device() Sasha Levin
2019-07-15 14:01 ` [PATCH AUTOSEL 5.1 059/219] media: imx7-mipi-csis: Propagate the error if clock enabling fails Sasha Levin
2019-07-15 14:01 ` [PATCH AUTOSEL 5.1 061/219] media: aspeed: change irq to threaded irq Sasha Levin
2019-07-15 14:01 ` [PATCH AUTOSEL 5.1 075/219] media: uvcvideo: Fix access to uninitialized fields on probe error Sasha Levin
2019-07-15 14:01 ` [PATCH AUTOSEL 5.1 076/219] media: fdp1: Support M3N and E3 platforms Sasha Levin
2019-07-15 14:01 ` [PATCH AUTOSEL 5.1 082/219] media: davinci: vpif_capture: fix memory leak in vpif_probe() Sasha Levin
2019-07-15 14:01 ` [PATCH AUTOSEL 5.1 084/219] media: s5p-mfc: fix reading min scratch buffer size on MFC v6/v7 Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 126/219] media: s5p-mfc: Make additional clocks optional Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 127/219] media: i2c: fix warning same module names Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 130/219] media: mt9m111: fix fw-node refactoring Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 133/219] media: coda: fix mpeg2 sequence number handling Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 134/219] media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 135/219] media: coda: increment sequence offset for the last returned frame Sasha Levin
2019-07-15 14:02 ` [PATCH AUTOSEL 5.1 136/219] media: vimc: cap: check v4l2_fill_pixfmt return value Sasha Levin
2019-07-15 14:02 ` Sasha Levin [this message]

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=20190715140341.6443-137-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=hverkuil@xs4all.nl \
    --cc=kpyle@austin.rr.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@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).