From patchwork Sat Sep 24 15:02:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Rankin X-Patchwork-Id: 7944 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1R7TkZ-0001Ar-3o; Sat, 24 Sep 2011 17:02:43 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-1) with esmtp id 1R7TkY-0005zM-Ju; Sat, 24 Sep 2011 17:02:42 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751715Ab1IXPCi (ORCPT + 5 others); Sat, 24 Sep 2011 11:02:38 -0400 Received: from nm4.bt.bullet.mail.ird.yahoo.com ([212.82.108.235]:43996 "HELO nm4.bt.bullet.mail.ird.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751659Ab1IXPCh (ORCPT ); Sat, 24 Sep 2011 11:02:37 -0400 Received: from [212.82.108.230] by nm4.bt.bullet.mail.ird.yahoo.com with NNFMP; 24 Sep 2011 15:02:36 -0000 Received: from [212.82.108.226] by tm3.bt.bullet.mail.ird.yahoo.com with NNFMP; 24 Sep 2011 15:02:36 -0000 Received: from [127.0.0.1] by omp1003.bt.mail.ird.yahoo.com with NNFMP; 24 Sep 2011 15:02:36 -0000 X-Yahoo-Newman-Id: 18501.1556.bm@omp1003.bt.mail.ird.yahoo.com Received: (qmail 47942 invoked from network); 24 Sep 2011 15:02:35 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type; b=xJtvPvftEwRQlt3wN2L/2RB/5uam7khg1C8HyaxCtfna/J49opZbcafa+1VUewwMzER+eoCZ60SJUlEMmBso6evRxZe2BUzVHRKcrGyh48ORO8Hy8JScey4GW5Fb+pCBGm4H80l7Q5uXGhXY7SMwo0z6aEWDLmJbKuuuwUTsig8= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1316876555; bh=xVKNWkMWPdnUqshs/hMabnAdBVRJhd8Ta0NAWjjMq0s=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type; b=XDDZ8vv6PTSbvoXVeZqlVOTfAtpTMS2WmeWAwNQo6sJAEbeG+GKfJ7DDwoftcpGIk6AOHh/FGnByWswa/+vw6YnKCcGXfiaTHOpI44BhmdVr2+DLmmnR5Lm5ukS5syaq7O+BuCs7N4LBJY28LeQ6npYOo/Sgf/BN6TNdx6el68M= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: mAwtoeIVM1k1D4vBuYaxvBSwF86UUwdbCRqQwj9JFOL6trC owjd1D1u1Uwg1vrGZ3C5b0m1UITfdtAUiloF9wEYNdNnLpxNTaYEFc5TZIQT AjtFuz2IXSSLq_Pd2IHJ6yQE7gz1Ctalw3.DRkpVBzTcKb2JV9aLBH_wcbW3 qX.UayD1cSChdON9VSyskXtL.c_Ja5JYUNpXcpjOLFyzTfFN9V6whgXbw7Gy WWuSzxfhXNIasaUkLh8fxycDVdU4V5k9Szpjo4_o7xk3BngS386FyzO_UcVP y5jru9zuLt_n4ZaW7V0wBFiYxNPpVnDFBC3KuG6iyTBK4httPuagU.bvBspw Z4iJI6eGTMpdaD24y3Y9gKqV8_VgirhfTMgI30h137LwfsfqwregJgXq03LV ZBvoQ X-Yahoo-SMTP: dMK34oyswBBlfKesWTI5ovDjFOUFE6shtILt.ZXnUEjQHhWq Received: from wellhouse.underworld (rankincj@86.178.153.128 with login) by smtp818.mail.ird.yahoo.com with SMTP; 24 Sep 2011 15:02:35 +0000 GMT Received: from volcano.underworld (volcano.underworld [192.168.0.3]) by wellhouse.underworld (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p8OF2WER026961 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 24 Sep 2011 16:02:34 +0100 Message-ID: <4E7DF108.40307@yahoo.com> Date: Sat, 24 Sep 2011 16:02:32 +0100 From: Chris Rankin User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: Mauro Carvalho Chehab CC: linux-media@vger.kernel.org Subject: [PATCH 2/2] EM28xx - fix race on disconnect Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2011.9.24.145414 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' FORGED_FROM_YAHOO 0.1, MIME_TEXT_ONLY_MP_MIXED 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, ECARD_KNOWN_DOMAINS 0, __ANY_URI 0, __BAT_BOUNDARY 0, __CP_URI_IN_BODY 0, __CT 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0, __CTYPE_MULTIPART_MIXED 0, __DOMAINKEYS_YAHOO 0, __FRAUD_BODY_WEBMAIL 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __FROM_YAHOO 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MOZILLA_MSGID 0, __PHISH_SPEAR_STRUCTURE_1 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0' X-LSpam-Score: 1.1 (+) X-LSpam-Report: No, score=1.1 required=5.0 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, KB_DATE_CONTAINS_TAB=2.751, RCVD_IN_DNSWL_MED=-2.3, TAB_IN_FROM=2.494, T_DKIM_INVALID=0.01, T_TVD_MIME_EPI=0.01, UNPARSEABLE_RELAY=0.001 autolearn=no This patch closes the race on the device and extension lists at USB disconnect time. Previously, the device was removed from the device list during em28xx_release_resources(), and then passed to the em28xx_close_extension() function so that all extensions could run their fini() operations. However, this left a (brief, theoretical, highly unlikely ;-)) window between these two calls during which a new module could call em28xx_register_extension(). The result would have been that the em28xx_usb_disconnect() function would also have passed the device to the new extension's fini() function, despite never having called the extension's init() function. This patch also restores em28xx_close_extension()'s symmetry with em28xx_init_extension(), and establishes the property that every device in the device list must have been initialised for every extension in the extension list. Signed-off-by: Chris Rankin --- linux/drivers/media/video/em28xx/em28xx-core.c.orig 2011-09-24 14:56:05.000000000 +0100 +++ linux/drivers/media/video/em28xx/em28xx-core.c 2011-09-24 15:01:23.000000000 +0100 @@ -1184,18 +1184,6 @@ static DEFINE_MUTEX(em28xx_devlist_mutex); /* - * em28xx_realease_resources() - * unregisters the v4l2,i2c and usb devices - * called when the device gets disconected or at module unload -*/ -void em28xx_remove_from_devlist(struct em28xx *dev) -{ - mutex_lock(&em28xx_devlist_mutex); - list_del(&dev->devlist); - mutex_unlock(&em28xx_devlist_mutex); -}; - -/* * Extension interface */ @@ -1245,14 +1233,13 @@ void em28xx_close_extension(struct em28xx *dev) { - struct em28xx_ops *ops = NULL; + const struct em28xx_ops *ops = NULL; mutex_lock(&em28xx_devlist_mutex); - if (!list_empty(&em28xx_extension_devlist)) { - list_for_each_entry(ops, &em28xx_extension_devlist, next) { - if (ops->fini) - ops->fini(dev); - } + list_for_each_entry(ops, &em28xx_extension_devlist, next) { + if (ops->fini) + ops->fini(dev); } + list_del(&dev->devlist); mutex_unlock(&em28xx_devlist_mutex); } --- linux/drivers/media/video/em28xx/em28xx-cards.c.orig 2011-09-24 15:19:28.000000000 +0100 +++ linux/drivers/media/video/em28xx/em28xx-cards.c 2011-09-24 15:19:33.000000000 +0100 @@ -2800,9 +2800,9 @@ #endif /* CONFIG_MODULES */ /* - * em28xx_realease_resources() + * em28xx_release_resources() * unregisters the v4l2,i2c and usb devices - * called when the device gets disconected or at module unload + * called when the device gets disconnected or at module unload */ void em28xx_release_resources(struct em28xx *dev) { @@ -2816,8 +2816,6 @@ em28xx_release_analog_resources(dev); - em28xx_remove_from_devlist(dev); - em28xx_i2c_unregister(dev); v4l2_device_unregister(&dev->v4l2_dev); @@ -3255,7 +3253,7 @@ /* * em28xx_usb_disconnect() - * called when the device gets diconencted + * called when the device gets disconnected * video device will be unregistered on v4l2_close in case it is still open */ static void em28xx_usb_disconnect(struct usb_interface *interface)