]> www.infradead.org Git - nvme.git/commitdiff
nvme/ioctl: move blk_mq_free_request() out of nvme_map_user_request()
authorCaleb Sander Mateos <csander@purestorage.com>
Fri, 28 Mar 2025 15:46:46 +0000 (09:46 -0600)
committerKeith Busch <kbusch@kernel.org>
Mon, 31 Mar 2025 15:48:25 +0000 (08:48 -0700)
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>
drivers/nvme/host/ioctl.c

index f8174809684165887b7b517d8cf27e7ba5a56a5e..809910da8c6eb46e2a91c60cd3448e8fb130d2bd 100644 (file)
@@ -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)