aboutsummaryrefslogtreecommitdiff
path: root/drivers/memstick/core/mspro_block.c
diff options
context:
space:
mode:
authorAlex Dubov <oakad@yahoo.com>2011-01-12 17:01:04 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 08:03:22 -0800
commitd8256d487840f9c2c372f8fc615a5d378bc133f1 (patch)
treec9b17bcf583e047ecb55bf775b55053c85b21935 /drivers/memstick/core/mspro_block.c
parent8930c8aa740b12ad69f44a35137bcc39bfa3dc41 (diff)
memstick: avert possible race condition between idr_pre_get and idr_get_new
Implement the usual pattern around idr_pre_get() and idr_get_new() to handlethe situation where another thread concurrently steals this thread's idr_pre_get() preallocation. Signed-off-by: Alex Dubov <oakad@yahoo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/memstick/core/mspro_block.c')
-rw-r--r--drivers/memstick/core/mspro_block.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 02362eccc58..a167938d451 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);