Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932983AbbELQh5 (ORCPT ); Tue, 12 May 2015 12:37:57 -0400 Received: from demumfd002.nsn-inter.net ([93.183.12.31]:48455 "EHLO demumfd002.nsn-inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751488AbbELQhx (ORCPT ); Tue, 12 May 2015 12:37:53 -0400 Message-ID: <55522C30.3060002@nokia.com> Date: Tue, 12 May 2015 18:37:04 +0200 From: Alexander Sverdlin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: ext Brian Norris , Giuseppe Cantavenera CC: linux-mtd@lists.infradead.org, lorenzo.restelli.ext@nokia.com, dwmw2@infradead.org, stable@vger.kernel.org, zhangxingcai , fengfuqiu@huawei.com, tanhaijun@huawei.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mtd: fix: avoid race condition when accessing mtd->usecount References: <1429611622-2652-1-git-send-email-giuseppe.cantavenera.ext@nokia.com> <20150508001012.GV32500@ld-irv-0074> <20150508001745.GW32500@ld-irv-0074> <20150508002649.GX32500@ld-irv-0074> In-Reply-To: <20150508002649.GX32500@ld-irv-0074> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 1818 X-purgate-ID: 151667::1431448629-000011EF-BC4F7A27/0/0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2006 Lines: 62 On 08/05/15 02:26, ext Brian Norris wrote: > As an alternative to your patch, how about the following? > > BTW, this does still leave a usecount race in > drivers/mtd/maps/vmu-flash.c. But that driver should really be using > mtd->_get_device(), if it actually wants its own refcount. > > Signed-off-by: Brian Norris Acked-by: Alexander Sverdlin > --- > > diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c > index 2b0c52870999..df7c6c70757a 100644 > --- a/drivers/mtd/mtd_blkdevs.c > +++ b/drivers/mtd/mtd_blkdevs.c > @@ -197,6 +197,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) > return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ > > mutex_lock(&dev->lock); > + mutex_lock(&mtd_table_mutex); > > if (dev->open) > goto unlock; > @@ -220,6 +221,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) > > unlock: > dev->open++; > + mutex_unlock(&mtd_table_mutex); > mutex_unlock(&dev->lock); > blktrans_dev_put(dev); > return ret; > @@ -230,6 +232,7 @@ error_release: > error_put: > module_put(dev->tr->owner); > kref_put(&dev->ref, blktrans_dev_release); > + mutex_unlock(&mtd_table_mutex); > mutex_unlock(&dev->lock); > blktrans_dev_put(dev); > return ret; > @@ -243,6 +246,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) > return; > > mutex_lock(&dev->lock); > + mutex_lock(&mtd_table_mutex); > > if (--dev->open) > goto unlock; > @@ -256,6 +260,7 @@ static void blktrans_release(struct gendisk *disk, fmode_t mode) > __put_mtd_device(dev->mtd); > } > unlock: > + mutex_unlock(&mtd_table_mutex); > mutex_unlock(&dev->lock); > blktrans_dev_put(dev); > } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/