From patchwork Wed May 11 07:11:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 9065581 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6F15ABF29F for ; Wed, 11 May 2016 07:11:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CEFD20154 for ; Wed, 11 May 2016 07:11:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E6D2120155 for ; Wed, 11 May 2016 07:11:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 371546E6F0; Wed, 11 May 2016 07:11:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lb3-smtp-cloud6.xs4all.net (lb3-smtp-cloud6.xs4all.net [194.109.24.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 720836E6ED for ; Wed, 11 May 2016 07:11:41 +0000 (UTC) Received: from tschai.lan ([90.149.38.145]) by smtp-cloud6.xs4all.net with ESMTP id svBZ1s00T37uBN201vBhmK; Wed, 11 May 2016 09:11:41 +0200 Received: from tschai.fritz.box (localhost [127.0.0.1]) by tschai.lan (Postfix) with ESMTPSA id EB9A9180D41; Wed, 11 May 2016 09:11:28 +0200 (CEST) From: Hans Verkuil To: linux-media@vger.kernel.org Subject: [PATCH 3/3] cec: correctly cancel delayed work when the CEC adapter is disabled Date: Wed, 11 May 2016 09:11:28 +0200 Message-Id: <1462950688-23290-4-git-send-email-hverkuil@xs4all.nl> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1462950688-23290-1-git-send-email-hverkuil@xs4all.nl> References: <1462950688-23290-1-git-send-email-hverkuil@xs4all.nl> Cc: Hans Verkuil , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil When cleaning up pending work from the wait_queue list, make sure to cancel the delayed work. Otherwise nasty kernel oopses will occur when the timer goes off and the cec_data struct has disappeared. Signed-off-by: Hans Verkuil --- drivers/staging/media/cec/cec.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/cec/cec.c b/drivers/staging/media/cec/cec.c index 9a62aa2..c2a876e 100644 --- a/drivers/staging/media/cec/cec.c +++ b/drivers/staging/media/cec/cec.c @@ -393,13 +393,28 @@ static int cec_thread_func(void *_adap) struct cec_data, list); cec_data_cancel(data); } + if (adap->transmitting) + cec_data_cancel(adap->transmitting); + + /* + * Cancel the pending timeout work. We have to unlock + * the mutex when flushing the work since + * cec_wait_timeout() will take it. This is OK since + * no new entries can be added to wait_queue as long + * as adap->transmitting is NULL, which it is due to + * the cec_data_cancel() above. + */ while (!list_empty(&adap->wait_queue)) { data = list_first_entry(&adap->wait_queue, struct cec_data, list); + + if (!cancel_delayed_work(&data->work)) { + mutex_unlock(&adap->lock); + flush_scheduled_work(); + mutex_lock(&adap->lock); + } cec_data_cancel(data); } - if (adap->transmitting) - cec_data_cancel(adap->transmitting); goto unlock; }