mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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>
This commit is contained in:
parent
8930c8aa74
commit
d8256d4878
2 changed files with 16 additions and 10 deletions
|
@ -511,14 +511,18 @@ int memstick_add_host(struct memstick_host *host)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL))
|
while (1) {
|
||||||
return -ENOMEM;
|
if (!idr_pre_get(&memstick_host_idr, GFP_KERNEL))
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
spin_lock(&memstick_host_lock);
|
spin_lock(&memstick_host_lock);
|
||||||
rc = idr_get_new(&memstick_host_idr, host, &host->id);
|
rc = idr_get_new(&memstick_host_idr, host, &host->id);
|
||||||
spin_unlock(&memstick_host_lock);
|
spin_unlock(&memstick_host_lock);
|
||||||
if (rc)
|
if (!rc)
|
||||||
return rc;
|
break;
|
||||||
|
else if (rc != -EAGAIN)
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
dev_set_name(&host->dev, "memstick%u", host->id);
|
dev_set_name(&host->dev, "memstick%u", host->id);
|
||||||
|
|
||||||
|
|
|
@ -1206,10 +1206,12 @@ static int mspro_block_init_disk(struct memstick_dev *card)
|
||||||
|
|
||||||
msb->page_size = be16_to_cpu(sys_info->unit_size);
|
msb->page_size = be16_to_cpu(sys_info->unit_size);
|
||||||
|
|
||||||
if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
mutex_lock(&mspro_block_disk_lock);
|
mutex_lock(&mspro_block_disk_lock);
|
||||||
|
if (!idr_pre_get(&mspro_block_disk_idr, GFP_KERNEL)) {
|
||||||
|
mutex_unlock(&mspro_block_disk_lock);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
rc = idr_get_new(&mspro_block_disk_idr, card, &disk_id);
|
rc = idr_get_new(&mspro_block_disk_idr, card, &disk_id);
|
||||||
mutex_unlock(&mspro_block_disk_lock);
|
mutex_unlock(&mspro_block_disk_lock);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue