block: cleanup bio_alloc_bioset()
authorIngo Molnar <mingo@elte.hu>
Sat, 21 Feb 2009 10:16:36 +0000 (11:16 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 24 Mar 2009 11:35:16 +0000 (12:35 +0100)
this warning (which got fixed by commit b2bf968):

  fs/bio.c: In function ‘bio_alloc_bioset’:
  fs/bio.c:305: warning: ‘p’ may be used uninitialized in this function

Triggered because the code flow in bio_alloc_bioset() is correct
but a bit complex for the compiler to see through.

Streamline it a bit - this also makes the code a tiny bit more compact:

   text    data     bss     dec     hex filename
   7540     256      40    7836    1e9c bio.o.before
   7539     256      40    7835    1e9b bio.o.after

Also remove an older compiler-warnings annotation from this function,
it's not needed.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fs/bio.c

index d4f0632..cef6258 100644 (file)
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -301,48 +301,51 @@ void bio_init(struct bio *bio)
  **/
 struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
 {
+       struct bio_vec *bvl = NULL;
        struct bio *bio = NULL;
-       void *uninitialized_var(p);
+       unsigned long idx = 0;
+       void *p = NULL;
 
        if (bs) {
                p = mempool_alloc(bs->bio_pool, gfp_mask);
-
-               if (p)
-                       bio = p + bs->front_pad;
-       } else
+               if (!p)
+                       goto err;
+               bio = p + bs->front_pad;
+       } else {
                bio = kmalloc(sizeof(*bio), gfp_mask);
+               if (!bio)
+                       goto err;
+       }
 
-       if (likely(bio)) {
-               struct bio_vec *bvl = NULL;
-
-               bio_init(bio);
-               if (likely(nr_iovecs)) {
-                       unsigned long uninitialized_var(idx);
-
-                       if (nr_iovecs <= BIO_INLINE_VECS) {
-                               idx = 0;
-                               bvl = bio->bi_inline_vecs;
-                               nr_iovecs = BIO_INLINE_VECS;
-                       } else {
-                               bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx,
-                                                       bs);
-                               nr_iovecs = bvec_nr_vecs(idx);
-                       }
-                       if (unlikely(!bvl)) {
-                               if (bs)
-                                       mempool_free(p, bs->bio_pool);
-                               else
-                                       kfree(bio);
-                               bio = NULL;
-                               goto out;
-                       }
-                       bio->bi_flags |= idx << BIO_POOL_OFFSET;
-                       bio->bi_max_vecs = nr_iovecs;
-               }
-               bio->bi_io_vec = bvl;
+       bio_init(bio);
+
+       if (unlikely(!nr_iovecs))
+               goto out_set;
+
+       if (nr_iovecs <= BIO_INLINE_VECS) {
+               bvl = bio->bi_inline_vecs;
+               nr_iovecs = BIO_INLINE_VECS;
+       } else {
+               bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs);
+               if (unlikely(!bvl))
+                       goto err_free;
+
+               nr_iovecs = bvec_nr_vecs(idx);
        }
-out:
+       bio->bi_flags |= idx << BIO_POOL_OFFSET;
+       bio->bi_max_vecs = nr_iovecs;
+out_set:
+       bio->bi_io_vec = bvl;
+
        return bio;
+
+err_free:
+       if (bs)
+               mempool_free(p, bs->bio_pool);
+       else
+               kfree(bio);
+err:
+       return NULL;
 }
 
 struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)