提交 34053979 编写于 作者: I Ingo Molnar 提交者: Jens Axboe

block: cleanup bio_alloc_bioset()

this warning (which got fixed by commit b2bf9683):

  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: NIngo Molnar <mingo@elte.hu>
Signed-off-by: NJens Axboe <jens.axboe@oracle.com>
上级 8e0ee43b
...@@ -301,48 +301,51 @@ void bio_init(struct bio *bio) ...@@ -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 *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
{ {
struct bio_vec *bvl = NULL;
struct bio *bio = NULL; struct bio *bio = NULL;
void *uninitialized_var(p); unsigned long idx = 0;
void *p = NULL;
if (bs) { if (bs) {
p = mempool_alloc(bs->bio_pool, gfp_mask); p = mempool_alloc(bs->bio_pool, gfp_mask);
if (!p)
if (p) goto err;
bio = p + bs->front_pad; bio = p + bs->front_pad;
} else } else {
bio = kmalloc(sizeof(*bio), gfp_mask); bio = kmalloc(sizeof(*bio), gfp_mask);
if (!bio)
goto err;
}
if (likely(bio)) { bio_init(bio);
struct bio_vec *bvl = NULL;
if (unlikely(!nr_iovecs))
bio_init(bio); goto out_set;
if (likely(nr_iovecs)) {
unsigned long uninitialized_var(idx); if (nr_iovecs <= BIO_INLINE_VECS) {
bvl = bio->bi_inline_vecs;
if (nr_iovecs <= BIO_INLINE_VECS) { nr_iovecs = BIO_INLINE_VECS;
idx = 0; } else {
bvl = bio->bi_inline_vecs; bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs);
nr_iovecs = BIO_INLINE_VECS; if (unlikely(!bvl))
} else { goto err_free;
bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx,
bs); nr_iovecs = bvec_nr_vecs(idx);
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;
} }
out: bio->bi_flags |= idx << BIO_POOL_OFFSET;
bio->bi_max_vecs = nr_iovecs;
out_set:
bio->bi_io_vec = bvl;
return bio; 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) struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册