nvme/ioctl: move blk_mq_free_request() out of nvme_map_user_request()
The callers of nvme_map_user_request() (nvme_submit_user_cmd() and nvme_uring_cmd_io()) allocate the request, so have them free it if nvme_map_user_request() fails. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Jens Axboe <axboe@kernel.dk> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
This commit is contained in:
committed by
Keith Busch
parent
eada75467f
commit
cd683de63e
+17
-14
@@ -129,10 +129,9 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
|
||||
if (!nvme_ctrl_sgl_supported(ctrl))
|
||||
dev_warn_once(ctrl->device, "using unchecked data buffer\n");
|
||||
if (has_metadata) {
|
||||
if (!supports_metadata) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (!supports_metadata)
|
||||
return -EINVAL;
|
||||
|
||||
if (!nvme_ctrl_meta_sgl_supported(ctrl))
|
||||
dev_warn_once(ctrl->device,
|
||||
"using unchecked metadata buffer\n");
|
||||
@@ -142,15 +141,14 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
|
||||
struct iov_iter iter;
|
||||
|
||||
/* fixedbufs is only for non-vectored io */
|
||||
if (flags & NVME_IOCTL_VEC) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (flags & NVME_IOCTL_VEC)
|
||||
return -EINVAL;
|
||||
|
||||
ret = io_uring_cmd_import_fixed(ubuffer, bufflen,
|
||||
rq_data_dir(req), &iter, ioucmd,
|
||||
iou_issue_flags);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
return ret;
|
||||
ret = blk_rq_map_user_iov(q, req, NULL, &iter, GFP_KERNEL);
|
||||
} else {
|
||||
ret = blk_rq_map_user_io(req, NULL, nvme_to_user_ptr(ubuffer),
|
||||
@@ -159,7 +157,7 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
|
||||
}
|
||||
|
||||
if (ret)
|
||||
goto out;
|
||||
return ret;
|
||||
|
||||
bio = req->bio;
|
||||
if (bdev)
|
||||
@@ -176,8 +174,6 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
|
||||
out_unmap:
|
||||
if (bio)
|
||||
blk_rq_unmap_user(bio);
|
||||
out:
|
||||
blk_mq_free_request(req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -202,7 +198,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
|
||||
ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer,
|
||||
meta_len, NULL, flags, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out_free_req;
|
||||
}
|
||||
|
||||
bio = req->bio;
|
||||
@@ -218,7 +214,10 @@ static int nvme_submit_user_cmd(struct request_queue *q,
|
||||
|
||||
if (effects)
|
||||
nvme_passthru_end(ctrl, ns, effects, cmd, ret);
|
||||
return ret;
|
||||
|
||||
out_free_req:
|
||||
blk_mq_free_request(req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -521,7 +520,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
|
||||
d.data_len, nvme_to_user_ptr(d.metadata),
|
||||
d.metadata_len, ioucmd, vec, issue_flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out_free_req;
|
||||
}
|
||||
|
||||
/* to free bio on completion, as req->bio will be null at that time */
|
||||
@@ -531,6 +530,10 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
|
||||
req->end_io = nvme_uring_cmd_end_io;
|
||||
blk_execute_rq_nowait(req, false);
|
||||
return -EIOCBQUEUED;
|
||||
|
||||
out_free_req:
|
||||
blk_mq_free_request(req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool is_ctrl_ioctl(unsigned int cmd)
|
||||
|
||||
Reference in New Issue
Block a user