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

[PATCH] bio_alloc() cleanup

de-spaghettify this function.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent eb3b83ad
...@@ -137,33 +137,29 @@ inline void bio_init(struct bio *bio) ...@@ -137,33 +137,29 @@ inline void bio_init(struct bio *bio)
**/ **/
struct bio *bio_alloc(int gfp_mask, int nr_iovecs) struct bio *bio_alloc(int gfp_mask, int nr_iovecs)
{ {
struct bio_vec *bvl = NULL; struct bio *bio = mempool_alloc(bio_pool, gfp_mask);
unsigned long idx;
struct bio *bio;
bio = mempool_alloc(bio_pool, gfp_mask);
if (unlikely(!bio))
goto out;
bio_init(bio); if (likely(bio)) {
struct bio_vec *bvl = NULL;
if (unlikely(!nr_iovecs)) bio_init(bio);
goto noiovec; if (likely(nr_iovecs)) {
unsigned long idx;
bvl = bvec_alloc(gfp_mask, nr_iovecs, &idx); bvl = bvec_alloc(gfp_mask, nr_iovecs, &idx);
if (bvl) { if (unlikely(!bvl)) {
bio->bi_flags |= idx << BIO_POOL_OFFSET; mempool_free(bio, bio_pool);
bio->bi_max_vecs = bvec_array[idx].nr_vecs; bio = NULL;
noiovec: goto out;
}
bio->bi_flags |= idx << BIO_POOL_OFFSET;
bio->bi_max_vecs = bvec_array[idx].nr_vecs;
}
bio->bi_io_vec = bvl; bio->bi_io_vec = bvl;
bio->bi_destructor = bio_destructor; bio->bi_destructor = bio_destructor;
out:
return bio;
} }
out:
mempool_free(bio, bio_pool); return bio;
bio = NULL;
goto out;
} }
/** /**
......
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