From: Alexander Sverdlin <alexander.sverdlin@nokia.com>
To: ext Brian Norris <computersforpeace@gmail.com>,
Giuseppe Cantavenera <giuseppe.cantavenera.ext@nokia.com>
Cc: linux-mtd@lists.infradead.org, lorenzo.restelli.ext@nokia.com,
dwmw2@infradead.org, stable@vger.kernel.org,
zhangxingcai <zhangxingcai@huawei.com>,
fengfuqiu@huawei.com, tanhaijun@huawei.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: fix: avoid race condition when accessing mtd->usecount
Date: Tue, 12 May 2015 18:37:04 +0200 [thread overview]
Message-ID: <55522C30.3060002@nokia.com> (raw)
In-Reply-To: <20150508002649.GX32500@ld-irv-0074>
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 <computersforpeace@gmail.com>
Acked-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> ---
>
> 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);
> }
prev parent reply other threads:[~2015-05-12 16:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1429611622-2652-1-git-send-email-giuseppe.cantavenera.ext@nokia.com>
2015-05-08 0:10 ` [PATCH] mtd: fix: avoid race condition when accessing mtd->usecount Brian Norris
2015-05-08 0:17 ` Brian Norris
2015-05-08 0:26 ` Brian Norris
2015-05-11 7:44 ` Cantavenera, Giuseppe (EXT-Other - DE/Ulm)
2015-05-11 22:25 ` Brian Norris
2015-05-12 6:38 ` Cantavenera, Giuseppe (EXT-Other - DE/Ulm)
2015-05-12 18:04 ` Brian Norris
2015-05-12 16:37 ` Alexander Sverdlin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55522C30.3060002@nokia.com \
--to=alexander.sverdlin@nokia.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=fengfuqiu@huawei.com \
--cc=giuseppe.cantavenera.ext@nokia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=lorenzo.restelli.ext@nokia.com \
--cc=stable@vger.kernel.org \
--cc=tanhaijun@huawei.com \
--cc=zhangxingcai@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).