Skip to content

Commit 5e06310

Browse files
lsgunthChristoph Hellwig
authored andcommitted
nvmet: cleanup nvmet_passthru_map_sg()
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: c1fef73 ("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>
1 parent df06047 commit 5e06310

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/nvme/target/passthru.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,20 @@ static void nvmet_passthru_req_done(struct request *rq,
187187

188188
static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
189189
{
190-
int sg_cnt = req->sg_cnt;
191190
struct scatterlist *sg;
192191
int op_flags = 0;
193192
struct bio *bio;
194193
int i, ret;
195194

195+
if (req->sg_cnt > BIO_MAX_PAGES)
196+
return -EINVAL;
197+
196198
if (req->cmd->common.opcode == nvme_cmd_flush)
197199
op_flags = REQ_FUA;
198200
else if (nvme_is_write(req->cmd))
199201
op_flags = REQ_SYNC | REQ_IDLE;
200202

201-
bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
203+
bio = bio_alloc(GFP_KERNEL, req->sg_cnt);
202204
bio->bi_end_io = bio_put;
203205
bio->bi_opf = req_op(rq) | op_flags;
204206

@@ -208,7 +210,6 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
208210
bio_put(bio);
209211
return -EINVAL;
210212
}
211-
sg_cnt--;
212213
}
213214

214215
ret = blk_rq_append_bio(rq, &bio);

0 commit comments

Comments
 (0)