Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9984730ybi; Wed, 24 Jul 2019 13:33:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYov3F4yD5e3W/UvwirUKEhxJePwQzuBNWz9JChA792vmYhbSjBSHG2jaFsGoMCWLg7dRr X-Received: by 2002:a17:902:2868:: with SMTP id e95mr81877336plb.319.1564000393726; Wed, 24 Jul 2019 13:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000393; cv=none; d=google.com; s=arc-20160816; b=rr2ZMg8zwlaPD9GtYm8lHkhnRJcOh3cb+JFSucGi9G6WmPG43JFppYHGnmHBK6rG8f Wgl0Rv/9lukoPQM+BkATBYedsmafx+ECcuO4E+Dq53YXFnFs0jZxnm1QII5ULT7+0Jra TgcQKSWCmj1JvTOqQt7rXcipubV/YSKR6IteplZIQOPXb/0NYLH/8v0t+vlMNRD3Zcua qoo5jrFIy2BgL1BXG+2uMhgMoAL9DvuSm7Ttlec0WqVFudPCrrq3yaUpK2GzU6lFiRdF QWDhsz3FimASQ8hOtwbukj4VDXdy9N01COMlaISbTWAfxVagLMh+6d8OtAZf8Rnx1qcy 5oOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oQxgxqlrtaRwgPhmYZAzamOQGbiyK6y8tRewdcNSltg=; b=oUGzdk4UYZZZoKhkYTqU3URuDG44JUvwzgrrV2Ky5hgzO0t9fV9JiCro4B+eld6R38 YH9RefaTRYelf3CywErEcCji3c0PWAA047HrwtJWU5G9snL4wch4XO0uMYYGs/Y/nhpK wf8uQZT1AbJzqzJ/CzdfDbseMdOc/Q3rCjzhQzhjMtA2lE99vU2CK/iWUxkM/mYfsvfE pODU4jQny1RFIpJlY2giviLFlYk9WGOQqdI9LF0Y4hQ2l6TuICgCm7OAoz7WcT4rzpEW nF2RI+8UKHOvgXtZcFd5gqBzcv7C48cpcpg21t0NfzUM+hN3YInJtvecuc1qhIOInA1E 7oqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x6U5fTiw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 12si21134495pgu.469.2019.07.24.13.32.58; Wed, 24 Jul 2019 13:33:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x6U5fTiw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388263AbfGXTaE (ORCPT + 99 others); Wed, 24 Jul 2019 15:30:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388256AbfGXTaC (ORCPT ); Wed, 24 Jul 2019 15:30:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE06E20659; Wed, 24 Jul 2019 19:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996601; bh=2hx8cUTZuWP+77yvfyByCSbaY1wI1oEe9aok1bEUhzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x6U5fTiwZ0a5NK7UnOEFm0Znb02RUJyXEiVP4FmZt4ZlzL6OGX5pYAjrdKizM9ydo YV1IXOvwTxlE5k/598s7wvJ0ZVYCGRU4bV4fC8EdrA3en1iJfb9qX+yUoTPiFRlGmW HUaOIBTQdQjeXq30G9Y+TZn85WNrxPLQ6X+kSQqI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Keith Pyle , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.2 152/413] media: hdpvr: fix locking and a missing msleep Date: Wed, 24 Jul 2019 21:17:23 +0200 Message-Id: <20190724191745.870999790@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 Suggested-by: Keith Pyle Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- 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 7580fc5f2f12..6a6405b80797 100644 --- a/drivers/media/usb/hdpvr/hdpvr-video.c +++ b/drivers/media/usb/hdpvr/hdpvr-video.c @@ -435,7 +435,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; } @@ -461,10 +461,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; @@ -1127,9 +1134,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