From: "Alex Dubov" <oakad@yahoo.com>
To: "LKML" <linux-kernel@vger.kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"Maxim Levitsky" <maximlevitsky@gmail.com>,
Alex Dubov <oakad@yahoo.com>
Subject: [PATCH 1/4] memstick: avert possible race condition between idr_pre_get and idr_get_new
Date: Wed, 27 Oct 2010 04:41:08 +1100 [thread overview]
Message-ID: <1288114871-805-2-git-send-email-oakad@yahoo.com> (raw)
In-Reply-To: <1288114871-805-1-git-send-email-oakad@yahoo.com>
From: Alex Dubov <oakad@yahoo.com>
Signed-off-by: Alex Dubov <oakad@yahoo.com>
---
drivers/memstick/core/memstick.c | 18 +++++++++++-------
drivers/memstick/core/mspro_block.c | 6 ++++--
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index c00fe82..17c556c 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -510,14 +510,18 @@ int memstick_add_host(struct memstick_host *host)
{
int rc;
- if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL))
- return -ENOMEM;
+ while (1) {
+ if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL))
+ return -ENOMEM;
- spin_lock(&memstick_host_lock);
- rc = idr_get_new(&memstick_host_idr, host, &host->id);
- spin_unlock(&memstick_host_lock);
- if (rc)
- return rc;
+ spin_lock(&memstick_host_lock);
+ rc = idr_get_new(&memstick_host_idr, host, &host->id);
+ spin_unlock(&memstick_host_lock);
+ if (!rc)
+ break;
+ else if (rc != -EAGAIN)
+ return rc;
+ }
dev_set_name(&host->dev, "memstick%u", host->id);
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 02362ec..a167938 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -1206,10 +1206,12 @@ static int mspro_block_init_disk(struct memstick_dev *card)
msb->page_size = be16_to_cpu(sys_info->unit_size);
- if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL))
+ mutex_lock(&mspro_block_disk_lock);
+ if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL)) {
+ mutex_unlock(&mspro_block_disk_lock);
return -ENOMEM;
+ }
- mutex_lock(&mspro_block_disk_lock);
rc = idr_get_new(&mspro_block_disk_idr, card, &disk_id);
mutex_unlock(&mspro_block_disk_lock);
--
1.6.5.1
next prev parent reply other threads:[~2010-10-26 18:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-26 17:41 memstick: Alternative approach to proposed fixes Alex Dubov
2010-10-26 17:41 ` Alex Dubov [this message]
2010-10-26 17:41 ` [PATCH 2/4] memstick: remove mspro_block_mutex Alex Dubov
2010-10-26 17:41 ` [PATCH 3/4] memstick: factor out transfer initiating functionality in mspro_block.c Alex Dubov
2010-10-26 17:41 ` [PATCH 4/4] memstick: add support for MSPro specific data transfer method Alex Dubov
2010-10-26 22:55 ` memstick: Alternative approach to proposed fixes Maxim Levitsky
2010-10-26 23:07 ` Maxim Levitsky
2010-10-26 23:08 ` Maxim Levitsky
2010-10-27 6:20 ` Alex Dubov
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=1288114871-805-2-git-send-email-oakad@yahoo.com \
--to=oakad@yahoo.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maximlevitsky@gmail.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
Powered by JetHome