Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3976241ybi; Mon, 29 Jul 2019 16:40:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoCkLwuaAer1kaXa/wrAoJxVE5wyoRKdQUTnKGUeYMUAupaxk+pp3uEv1FOPPz/bEaaJKd X-Received: by 2002:a17:90b:8c8:: with SMTP id ds8mr116549225pjb.89.1564443633743; Mon, 29 Jul 2019 16:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564443633; cv=none; d=google.com; s=arc-20160816; b=lc3r3JcrvZrbUqVFxYFx1xfYbwW7Esl6pmx0zQolRFRVD4wyOTJ/pIDc+1UZcaYBxV /S2bt7jOWyCxd6odOUTjC5QKZOvlf8CqHW3AA6uvsFguTPILDRSQihX/oAI9XUA3E2Rp Ih4Dp8LlaVZHeg6MfcN9NNHwfpHh/nchBknHd6uYweEnFZO7FF3fgmlHpqEcpPHOlLEI AOM2Xsr9CyPNYq19aLH9ibwr4b2lk3MaJaRUYjA7mt95ZI3QtNR++lcQTHkfRvK7iTXa sTLJKFiWS8WCFeYTh2prJh4RJveP3vAQ7v4dNaaAdq+AFUUvuk96Q+QCdIwklxSdWHQx YjNw== 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=0vw9QUoKUzTQx6iRXqfYx2qiO3/STzifh1q6kp4p/Fw=; b=isAnhr2HgThg5sm9RTHVYrJ+kN1viFwTRvB1I6zPqyRvA6IZRhEsKIuhV42os6fZlB e7pIMf9qgIZ20sdaE4KKIm19eQSs5brTvNMZGX6m8Egk52ojNamiwnI8EIEYxuMBNwgM H7Pwo8wELDPPyDzcpuf08MSyAYndO9xsJNITovIpA35YJyMpVNgl5efNxmVBHKGmL+uQ BRr9YDBuzjxlIvrheMQSxJqbz7zcQoflk5p3Ph5nJWfhsw3tM826AdspKjEyiaTBHzfM r+/XVjEt7uA+1NWsCP9hcqHHsWJrPiC4OuF1WXcKQl9PswJcFSQT5OzvzYTe22LfNJTw z/HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DkEBAEfo; 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 f37si20302411pgm.145.2019.07.29.16.40.16; Mon, 29 Jul 2019 16:40:33 -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=DkEBAEfo; 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 S1729205AbfG2T1D (ORCPT + 99 others); Mon, 29 Jul 2019 15:27:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:39486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729863AbfG2T1B (ORCPT ); Mon, 29 Jul 2019 15:27:01 -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 D02D62171F; Mon, 29 Jul 2019 19:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428420; bh=yGyUkXhBisP4yzsrfZQWseGr1b7R+vTsYuJ3VnUsPQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DkEBAEfoC94+JmcvdL9xRxWLpOa0M13Jp/JKcZIp/WK1gShTh9akIA09D2EDvSoAJ dPfWXG+SfX5zOLXKG32Zg7Sk8/5birYH1eE1yxTbq1Sskb+IWWiVxps++EPwvpNnHA dBN2fdVsmvboPf0o31jenQtg/wTuIzNDxMSHEEcs= 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 4.14 071/293] media: hdpvr: fix locking and a missing msleep Date: Mon, 29 Jul 2019 21:19:22 +0200 Message-Id: <20190729190830.107021626@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 7fb036d6a86e..991f820a4530 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