public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Subject: Re: [PATCH] block: fix build warning in __blk_bios_map_sg()
Date: Tue, 2 Apr 2019 10:10:40 +0800	[thread overview]
Message-ID: <20190402021039.GA26316@ming.t460p> (raw)
In-Reply-To: <20190402014638.25633-1-ming.lei@redhat.com>

On Tue, Apr 02, 2019 at 09:46:38AM +0800, Ming Lei wrote:
> Commit f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can
> be mergeable") changes bvec merge by only considering two bvecs from
> different bios. However, if the former bio doesn't inlcude any io bvec,
> then the following warning may be triggered:
> 
>  warning: ‘bvec.bv_offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> In practice, it shouldn't be triggered.
> 
> Fixes it by adding check on former bio, the check shouldn't add any cost
> given 'bio->bi_iter' can be hit in cache.
> 
> Reported-by: Jens Axboe <axboe@kernel.dk>
> Fixes: f6970f83ef79 ("block: don't check if adjacent bvecs in one bio can be mergeable")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  block/blk-merge.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/block/blk-merge.c b/block/blk-merge.c
> index 8f96d683b577..1fc66d03893f 100644
> --- a/block/blk-merge.c
> +++ b/block/blk-merge.c
> @@ -527,7 +527,7 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
>  			     struct scatterlist *sglist,
>  			     struct scatterlist **sg)
>  {
> -	struct bio_vec bvec, bvprv = { NULL };
> +	struct bio_vec uninitialized_var(bvec), bvprv = { NULL };
>  	struct bvec_iter iter;
>  	int nsegs = 0;
>  	bool new_bio = false;
> @@ -550,8 +550,10 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio,
>   next_bvec:
>  			new_bio = false;
>  		}
> -		bvprv = bvec;
> -		new_bio = true;
> +		if (likely(bio->bi_iter.bi_size)) {
> +			bvprv = bvec;
> +			new_bio = true;
> +		}
>  	}

Looks __blk_recalc_rq_segments() needs the similar fix too, so please
ignore this one, and I will handle them all in one patch.

Thanks,
Ming

      reply	other threads:[~2019-04-02  2:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02  1:46 [PATCH] block: fix build warning in __blk_bios_map_sg() Ming Lei
2019-04-02  2:10 ` Ming Lei [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190402021039.GA26316@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox