From patchwork Sat Jan 4 10:55:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 3433491 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A5376C02DC for ; Sat, 4 Jan 2014 13:59:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CDD2A20138 for ; Sat, 4 Jan 2014 13:59:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0739620136 for ; Sat, 4 Jan 2014 13:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754265AbaADN7r (ORCPT ); Sat, 4 Jan 2014 08:59:47 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:43693 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753270AbaADN7R (ORCPT ); Sat, 4 Jan 2014 08:59:17 -0500 Received: from [177.143.150.208] (helo=smtp.w2.samsung.com) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1VzRkw-00013n-KU; Sat, 04 Jan 2014 13:59:15 +0000 Received: from mchehab by smtp.w2.samsung.com with local (Exim 4.80.1) (envelope-from ) id 1VzOtV-0003kd-Mi; Sat, 04 Jan 2014 08:55:53 -0200 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab Subject: [PATCH v4 15/22] [media] em28xx: Fix em28xx deplock Date: Sat, 4 Jan 2014 08:55:44 -0200 Message-Id: <1388832951-11195-16-git-send-email-m.chehab@samsung.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1388832951-11195-1-git-send-email-m.chehab@samsung.com> References: <1388832951-11195-1-git-send-email-m.chehab@samsung.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 When em28xx extensions are loaded/removed, there are two locks: a single static em28xx_devlist_mutex that registers each extension and the struct em28xx dev->lock. When extensions are registered, em28xx_devlist_mutex is taken first, and then dev->lock. Be sure that, when extensions are being removed, the same order will be used. Signed-off-by: Mauro Carvalho Chehab Reviewed-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-cards.c | 5 +++-- drivers/media/usb/em28xx/em28xx-core.c | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c index 4fe742429f2c..36aec50e5c3b 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -3334,9 +3334,7 @@ static void em28xx_usb_disconnect(struct usb_interface *interface) dev->disconnected = 1; if (dev->is_audio_only) { - mutex_lock(&dev->lock); em28xx_close_extension(dev); - mutex_unlock(&dev->lock); return; } @@ -3355,10 +3353,13 @@ static void em28xx_usb_disconnect(struct usb_interface *interface) em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE); em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE); } + mutex_unlock(&dev->lock); em28xx_close_extension(dev); + /* NOTE: must be called BEFORE the resources are released */ + mutex_lock(&dev->lock); if (!dev->users) em28xx_release_resources(dev); diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c index 2ad84ff1fc4f..97cc83c3c287 100644 --- a/drivers/media/usb/em28xx/em28xx-core.c +++ b/drivers/media/usb/em28xx/em28xx-core.c @@ -1097,10 +1097,12 @@ void em28xx_close_extension(struct em28xx *dev) const struct em28xx_ops *ops = NULL; mutex_lock(&em28xx_devlist_mutex); + mutex_lock(&dev->lock); list_for_each_entry(ops, &em28xx_extension_devlist, next) { if (ops->fini) ops->fini(dev); } + mutex_unlock(&dev->lock); list_del(&dev->devlist); mutex_unlock(&em28xx_devlist_mutex); }