From patchwork Tue Apr 5 03:25:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Nieder X-Patchwork-Id: 685981 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 p353Q8Dk032262 for ; Tue, 5 Apr 2011 03:26:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752506Ab1DED0G (ORCPT ); Mon, 4 Apr 2011 23:26:06 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:55760 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752443Ab1DED0F (ORCPT ); Mon, 4 Apr 2011 23:26:05 -0400 Received: by yxs7 with SMTP id 7so2431380yxs.19 for ; Mon, 04 Apr 2011 20:26:04 -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=eAYiNhd1WRiHrfwC1dzPPs163vH0P4HxH5xOfPFTE0w=; b=vggZ5BRHVkXeb3J4awm0Yvfm8MTkqavPTFh53NBOlbM7XGirwXW/H3fSFC/5867uYc eAt1OIPnoIPUP8Rp3gWVajSK3ICJvDg0E9YPh6wuMDGWGCZu0ffM4cnKSmFwXMTbNhuN crjQOGrLJtB6wV51G/El1wtBuiz0Wg4+U1VmI= 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=WPkKt1Kd/iM1NQDT3xrXm00AMh8y7Xjs5ThFrnvNiuD7tOC/pumyzAh0hTAJWWJZav 2FkoK0Mw6wd1SVtKFJFJ7eVo24y+gRvP6LFOQhBuovXW6ABTd0i2dXneuF6tXVlsQK07 a9W8yyl2eBObaHlXO0c6VonYacbcwtXSQxIUE= Received: by 10.147.114.11 with SMTP id r11mr7732611yam.7.1301973964009; Mon, 04 Apr 2011 20:26:04 -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 k16sm2618514anb.11.2011.04.04.20.26.02 (version=SSLv3 cipher=OTHER); Mon, 04 Apr 2011 20:26:03 -0700 (PDT) Date: Mon, 4 Apr 2011 22:25:58 -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 2/7] [media] cx88: fix locking of sub-driver operations Message-ID: <20110405032558.GC4498@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:26:08 +0000 (UTC) The BKL conversion of this driver seems to have gone wrong. Loading the cx88-blackbird driver deadlocks. The cause: mpeg_ops::open in the cx2388x blackbird driver acquires the device lock and calls the sub-driver's request_acquire, which tries to acquire the lock again. Fix it by clarifying the semantics of request_acquire, request_release, advise_acquire, and advise_release: all will require the caller to hold the device lock. Based on a patch by Ben Hutchings . Reported-by: Andi Huber Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=31962 Signed-off-by: Jonathan Nieder Cc: stable@kernel.org --- drivers/media/video/cx88/cx88-blackbird.c | 4 ++-- drivers/media/video/cx88/cx88-dvb.c | 3 +-- drivers/media/video/cx88/cx88-mpeg.c | 4 ---- drivers/media/video/cx88/cx88.h | 3 ++- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c index b93fbd3..a6f7d53 100644 --- a/drivers/media/video/cx88/cx88-blackbird.c +++ b/drivers/media/video/cx88/cx88-blackbird.c @@ -1125,13 +1125,13 @@ static int mpeg_release(struct file *file) /* Make sure we release the hardware */ drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); - mutex_unlock(&dev->core->lock); - if (drv) drv->request_release(drv); atomic_dec(&dev->core->mpeg_users); + mutex_unlock(&dev->core->lock); + return 0; } diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c index 84002bc..c69df7e 100644 --- a/drivers/media/video/cx88/cx88-dvb.c +++ b/drivers/media/video/cx88/cx88-dvb.c @@ -135,8 +135,6 @@ static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire) mutex_lock(&dev->core->lock); drv = cx8802_get_driver(dev, CX88_MPEG_DVB); - mutex_unlock(&dev->core->lock); - if (drv) { if (acquire){ dev->frontends.active_fe_id = fe_id; @@ -146,6 +144,7 @@ static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire) dev->frontends.active_fe_id = 0; } } + mutex_unlock(&dev->core->lock); return ret; } diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c index 918172b..9147c16 100644 --- a/drivers/media/video/cx88/cx88-mpeg.c +++ b/drivers/media/video/cx88/cx88-mpeg.c @@ -624,13 +624,11 @@ static int cx8802_request_acquire(struct cx8802_driver *drv) if (drv->advise_acquire) { - mutex_lock(&drv->core->lock); core->active_ref++; if (core->active_type_id == CX88_BOARD_NONE) { core->active_type_id = drv->type_id; drv->advise_acquire(drv); } - mutex_unlock(&drv->core->lock); mpeg_dbg(1,"%s() Post acquire GPIO=%x\n", __func__, cx_read(MO_GP0_IO)); } @@ -643,14 +641,12 @@ static int cx8802_request_release(struct cx8802_driver *drv) { struct cx88_core *core = drv->core; - mutex_lock(&drv->core->lock); if (drv->advise_release && --core->active_ref == 0) { drv->advise_release(drv); core->active_type_id = CX88_BOARD_NONE; mpeg_dbg(1,"%s() Post release GPIO=%x\n", __func__, cx_read(MO_GP0_IO)); } - mutex_unlock(&drv->core->lock); return 0; } diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h index e3d56c2..9731daa 100644 --- a/drivers/media/video/cx88/cx88.h +++ b/drivers/media/video/cx88/cx88.h @@ -510,7 +510,8 @@ struct cx8802_driver { /* Caller must _not_ hold core->lock */ int (*probe)(struct cx8802_driver *drv); - /* Caller must hold core->lock */ + /* Callers to the following functions must hold core->lock */ + int (*remove)(struct cx8802_driver *drv); /* MPEG 8802 -> mini driver - Access for hardware control */