From patchwork Sun May 1 09:30:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Nieder X-Patchwork-Id: 745002 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p419Ub3t013878 for ; Sun, 1 May 2011 09:30:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753262Ab1EAJaW (ORCPT ); Sun, 1 May 2011 05:30:22 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:41482 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752822Ab1EAJaS (ORCPT ); Sun, 1 May 2011 05:30:18 -0400 Received: by mail-iy0-f174.google.com with SMTP id 14so4005835iyb.19 for ; Sun, 01 May 2011 02:30:18 -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=dcm+5egvXPLQQV/2elHg8hj69+Sc9XVCjcnDXCJnZ8g=; b=k2lzkfsh+tcgpI+z2xYgwTearAkv7dqeyrRjE8FcWLfLuQLDPxSUxdbVgP2pbyc9QU XTavGE3kaMpksjYAwrcFfGc9jpaRIGa/B562S9HDdnhiKf56o5gYLCWsp+rNOUYDMVfU t4HcwkO/qNqjIfTJD0C05A1ly9ibdJldUW9Pk= 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=rw6Qij3JqtgbP5oPp0kFj53LOangRLAnmAQl1T29tcXX1ibHbF114laEPsA3p8PvaQ JGVw920IYvAgT5/bRyP8lXn6AwAqUVJ1+2SncPKnMUt0brdijQ+9S34eoVmR8yDXJVgH FswGZayOCgrtDFt3/gSBRCxAcG/RwprgxYO7g= Received: by 10.231.128.199 with SMTP id l7mr5231255ibs.150.1304242218500; Sun, 01 May 2011 02:30:18 -0700 (PDT) Received: from elie (adsl-69-209-62-211.dsl.chcgil.ameritech.net [69.209.62.211]) by mx.google.com with ESMTPS id g16sm1874269ibb.20.2011.05.01.02.30.16 (version=SSLv3 cipher=OTHER); Sun, 01 May 2011 02:30:17 -0700 (PDT) Date: Sun, 1 May 2011 04:30:14 -0500 From: Jonathan Nieder To: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Dan Carpenter , Hans Verkuil , Andi Huber , Marlon de Boer , Damien Churchill Subject: [PATCH 4/7] [media] cx88: protect cx8802_devlist with a mutex Message-ID: <20110501093014.GD18380@elie> References: <20110501091710.GA18263@elie> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110501091710.GA18263@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 (demeter2.kernel.org [140.211.167.43]); Sun, 01 May 2011 09:30:37 +0000 (UTC) Add and use a mutex to protect the cx88-mpeg device list. Previously the BKL prevented races. Based on work by Ben Hutchings . Tested-by: Andi Huber Tested-by: Marlon de Boer 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);