From patchwork Tue Apr 5 03:27:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Nieder X-Patchwork-Id: 686011 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p353S7kB001169 for ; Tue, 5 Apr 2011 03:28:07 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752590Ab1DED2F (ORCPT ); Mon, 4 Apr 2011 23:28:05 -0400 Received: from mail-gw0-f46.google.com ([74.125.83.46]:62148 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752443Ab1DED2F (ORCPT ); Mon, 4 Apr 2011 23:28:05 -0400 Received: by gwaa18 with SMTP id a18so2426587gwa.19 for ; Mon, 04 Apr 2011 20:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=aYf3ECp04dt41ZUwIm2Bu/EQ5GGH5V0K1TBJchRgpYo=; b=xgRuWhbge7KG8DAFrv7evmrzjVoz6blbZeX2lc++84bsYEd3H3AxMEnujE5Tlfq/2s qwhD05MRRn2fbQ42VkwaMhs+lsSydGvYgepuJkufFjQKw/bUj6TXswVW/guXzoqtX0LM QYsvuzPJltG+P6kkEJxeqPI9SLLJG2MeA9PDI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=YkxBAbiVhvH6Iv0hapZy1Ouqf93GUCuAiKZOE7sripmOxFV22SCER2J+4lxDr/xmkQ MlY+A/32TfcJuQp+LqIZuFuN+/UH40OfkeU71A0cvXKnbt5d9vPj1ujg6TuaEz7Tftyh OQamQxrJrM30HToB5FUUSM9dgSnna8QcBA0O8= Received: by 10.91.39.9 with SMTP id r9mr4610agj.84.1301974083569; Mon, 04 Apr 2011 20:28:03 -0700 (PDT) Received: from elie (adsl-69-209-53-77.dsl.chcgil.sbcglobal.net [69.209.53.77]) by mx.google.com with ESMTPS id w4sm6066771anw.16.2011.04.04.20.28.01 (version=SSLv3 cipher=OTHER); Mon, 04 Apr 2011 20:28:02 -0700 (PDT) Date: Mon, 4 Apr 2011 22:27:57 -0500 From: Jonathan Nieder To: linux-media@vger.kernel.org Cc: Huber Andreas , Mauro Carvalho Chehab , Hans Verkuil , linux-kernel@vger.kernel.org, Ben Hutchings , Steven Toth Subject: [PATCH 4/7] [media] cx88: use a mutex to protect cx8802_devlist Message-ID: <20110405032757.GE4498@elie> References: <20110327150610.4029.95961.reportbug@xen.corax.at> <20110327152810.GA32106@elie> <20110402093856.GA17015@elie> <20110405032014.GA4498@elie> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110405032014.GA4498@elie> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 05 Apr 2011 03:28:07 +0000 (UTC) Add and use a mutex to protect the cx88-mpeg device list. Previously the BKL prevented races. Based on a patch by Ben Hutchings . Signed-off-by: Jonathan Nieder --- drivers/media/video/cx88/cx88-mpeg.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c index 497f26f..b18f9fe 100644 --- a/drivers/media/video/cx88/cx88-mpeg.c +++ b/drivers/media/video/cx88/cx88-mpeg.c @@ -78,6 +78,7 @@ static void flush_request_modules(struct cx8802_dev *dev) static LIST_HEAD(cx8802_devlist); +static DEFINE_MUTEX(cx8802_mutex); /* ------------------------------------------------------------------ */ static int cx8802_start_dma(struct cx8802_dev *dev, @@ -689,6 +690,8 @@ int cx8802_register_driver(struct cx8802_driver *drv) return err; } + mutex_lock(&cx8802_mutex); + list_for_each_entry(dev, &cx8802_devlist, devlist) { printk(KERN_INFO "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n", @@ -698,8 +701,10 @@ int cx8802_register_driver(struct cx8802_driver *drv) /* Bring up a new struct for each driver instance */ driver = kzalloc(sizeof(*drv),GFP_KERNEL); - if (driver == NULL) - return -ENOMEM; + if (driver == NULL) { + err = -ENOMEM; + goto out; + } /* Snapshot of the driver registration data */ drv->core = dev->core; @@ -722,7 +727,10 @@ int cx8802_register_driver(struct cx8802_driver *drv) mutex_unlock(&drv->core->lock); } - return i ? 0 : -ENODEV; + err = i ? 0 : -ENODEV; +out: + mutex_unlock(&cx8802_mutex); + return err; } int cx8802_unregister_driver(struct cx8802_driver *drv) @@ -736,6 +744,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv) drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird", drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive"); + mutex_lock(&cx8802_mutex); + list_for_each_entry(dev, &cx8802_devlist, devlist) { printk(KERN_INFO "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n", @@ -762,6 +772,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv) mutex_unlock(&dev->core->lock); } + mutex_unlock(&cx8802_mutex); + return err; } @@ -799,7 +811,9 @@ static int __devinit cx8802_probe(struct pci_dev *pci_dev, goto fail_free; INIT_LIST_HEAD(&dev->drvlist); + mutex_lock(&cx8802_mutex); list_add_tail(&dev->devlist,&cx8802_devlist); + mutex_unlock(&cx8802_mutex); /* now autoload cx88-dvb or cx88-blackbird */ request_modules(dev);