]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
nvmet: cleanup nvmet_passthru_map_sg()
authorLogan Gunthorpe <logang@deltatee.com>
Fri, 16 Oct 2020 22:19:05 +0000 (16:19 -0600)
committerChristoph Hellwig <hch@lst.de>
Thu, 22 Oct 2020 13:28:02 +0000 (15:28 +0200)
Clean up some confusing elements of nvmet_passthru_map_sg() by returning
early if the request is greater than the maximum bio size. This allows
us to drop the sg_cnt variable.

This should not result in any functional change but makes the code
clearer and more understandable. The original code allocated a truncated
bio then would return EINVAL when bio_add_pc_page() filled that bio. The
new code just returns EINVAL early if this would happen.

Fixes: c1fef73f793b ("nvmet: add passthru code to process commands")
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Suggested-by: Douglas Gilbert <dgilbert@interlog.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/passthru.c

index 323046e1d67f2f75f938cc259757cec16d04237c..0814cba8298a7ef86337dfa65e910730ea738336 100644 (file)
@@ -187,18 +187,20 @@ static void nvmet_passthru_req_done(struct request *rq,
 
 static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
 {
-       int sg_cnt = req->sg_cnt;
        struct scatterlist *sg;
        int op_flags = 0;
        struct bio *bio;
        int i, ret;
 
+       if (req->sg_cnt > BIO_MAX_PAGES)
+               return -EINVAL;
+
        if (req->cmd->common.opcode == nvme_cmd_flush)
                op_flags = REQ_FUA;
        else if (nvme_is_write(req->cmd))
                op_flags = REQ_SYNC | REQ_IDLE;
 
-       bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
+       bio = bio_alloc(GFP_KERNEL, req->sg_cnt);
        bio->bi_end_io = bio_put;
        bio->bi_opf = req_op(rq) | op_flags;
 
@@ -208,7 +210,6 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
                        bio_put(bio);
                        return -EINVAL;
                }
-               sg_cnt--;
        }
 
        ret = blk_rq_append_bio(rq, &bio);