Commit 6b1b56f9 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] dm: Tidy up the error path for alloc_dev()

From: Joe Thornber <thornber@redhat.com>

Tidy up the error path for alloc_dev()
parent 54e37e09
...@@ -560,41 +560,28 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent) ...@@ -560,41 +560,28 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
/* get a minor number for the dev */ /* get a minor number for the dev */
r = persistent ? specific_minor(minor) : next_free_minor(&minor); r = persistent ? specific_minor(minor) : next_free_minor(&minor);
if (r < 0) { if (r < 0)
kfree(md); goto bad1;
return NULL;
}
memset(md, 0, sizeof(*md)); memset(md, 0, sizeof(*md));
init_rwsem(&md->lock); init_rwsem(&md->lock);
atomic_set(&md->holders, 1); atomic_set(&md->holders, 1);
md->queue = blk_alloc_queue(GFP_KERNEL); md->queue = blk_alloc_queue(GFP_KERNEL);
if (!md->queue) { if (!md->queue)
kfree(md); goto bad1;
return NULL;
}
md->queue->queuedata = md; md->queue->queuedata = md;
blk_queue_make_request(md->queue, dm_request); blk_queue_make_request(md->queue, dm_request);
md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab, md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
mempool_free_slab, _io_cache); mempool_free_slab, _io_cache);
if (!md->io_pool) { if (!md->io_pool)
free_minor(minor); goto bad2;
blk_put_queue(md->queue);
kfree(md);
return NULL;
}
md->disk = alloc_disk(1); md->disk = alloc_disk(1);
if (!md->disk) { if (!md->disk)
mempool_destroy(md->io_pool); goto bad3;
free_minor(minor);
blk_put_queue(md->queue);
kfree(md);
return NULL;
}
md->disk->major = _major; md->disk->major = _major;
md->disk->first_minor = minor; md->disk->first_minor = minor;
...@@ -609,6 +596,16 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent) ...@@ -609,6 +596,16 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
init_waitqueue_head(&md->eventq); init_waitqueue_head(&md->eventq);
return md; return md;
bad3:
mempool_destroy(md->io_pool);
bad2:
blk_put_queue(md->queue);
free_minor(minor);
bad1:
kfree(md);
return NULL;
} }
static void free_dev(struct mapped_device *md) static void free_dev(struct mapped_device *md)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment