blk-mq: use bio->bi_opf after bio is checked
authorMing Lei <ming.lei@redhat.com>
Fri, 26 Nov 2021 16:19:43 +0000 (00:19 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 29 Nov 2021 13:41:23 +0000 (06:41 -0700)
bio->bi_opf isn't finalized before checking the bio, so use it after
submit_bio_checks() returns.

Fixes: 5b13bc8a3fd5 ("blk-mq: cleanup request allocation")
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq.c

index a89a624dd1df4cae0e8b77373df1808f5bde8b93..143a8edf6300b08fa76af0d59b0e14a0f672f374 100644 (file)
@@ -2713,7 +2713,6 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
        struct blk_mq_alloc_data data = {
                .q              = q,
                .nr_tags        = 1,
-               .cmd_flags      = bio->bi_opf,
        };
        struct request *rq;
 
@@ -2726,6 +2725,8 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
 
        rq_qos_throttle(q, bio);
 
+       /* ->bi_opf is finalized after submit_bio_checks() returns */
+       data.cmd_flags  = bio->bi_opf;
        if (plug) {
                data.nr_tags = plug->nr_ios;
                plug->nr_ios = 1;