Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Caleb Sander Mateos and committed by
Keith Busch
cd683de6 eada7546

+17 -14
+17 -14
drivers/nvme/host/ioctl.c
··· 129 129 if (!nvme_ctrl_sgl_supported(ctrl)) 130 130 dev_warn_once(ctrl->device, "using unchecked data buffer\n"); 131 131 if (has_metadata) { 132 - if (!supports_metadata) { 133 - ret = -EINVAL; 134 - goto out; 135 - } 132 + if (!supports_metadata) 133 + return -EINVAL; 134 + 136 135 if (!nvme_ctrl_meta_sgl_supported(ctrl)) 137 136 dev_warn_once(ctrl->device, 138 137 "using unchecked metadata buffer\n"); ··· 141 142 struct iov_iter iter; 142 143 143 144 /* fixedbufs is only for non-vectored io */ 144 - if (flags & NVME_IOCTL_VEC) { 145 - ret = -EINVAL; 146 - goto out; 147 - } 145 + if (flags & NVME_IOCTL_VEC) 146 + return -EINVAL; 147 + 148 148 ret = io_uring_cmd_import_fixed(ubuffer, bufflen, 149 149 rq_data_dir(req), &iter, ioucmd, 150 150 iou_issue_flags); 151 151 if (ret < 0) 152 - goto out; 152 + return ret; 153 153 ret = blk_rq_map_user_iov(q, req, NULL, &iter, GFP_KERNEL); 154 154 } else { 155 155 ret = blk_rq_map_user_io(req, NULL, nvme_to_user_ptr(ubuffer), ··· 157 159 } 158 160 159 161 if (ret) 160 - goto out; 162 + return ret; 161 163 162 164 bio = req->bio; 163 165 if (bdev) ··· 174 176 out_unmap: 175 177 if (bio) 176 178 blk_rq_unmap_user(bio); 177 - out: 178 - blk_mq_free_request(req); 179 179 return ret; 180 180 } 181 181 ··· 198 202 ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer, 199 203 meta_len, NULL, flags, 0); 200 204 if (ret) 201 - return ret; 205 + goto out_free_req; 202 206 } 203 207 204 208 bio = req->bio; ··· 214 218 215 219 if (effects) 216 220 nvme_passthru_end(ctrl, ns, effects, cmd, ret); 221 + return ret; 217 222 223 + out_free_req: 224 + blk_mq_free_request(req); 218 225 return ret; 219 226 } 220 227 ··· 520 521 d.data_len, nvme_to_user_ptr(d.metadata), 521 522 d.metadata_len, ioucmd, vec, issue_flags); 522 523 if (ret) 523 - return ret; 524 + goto out_free_req; 524 525 } 525 526 526 527 /* to free bio on completion, as req->bio will be null at that time */ ··· 530 531 req->end_io = nvme_uring_cmd_end_io; 531 532 blk_execute_rq_nowait(req, false); 532 533 return -EIOCBQUEUED; 534 + 535 + out_free_req: 536 + blk_mq_free_request(req); 537 + return ret; 533 538 } 534 539 535 540 static bool is_ctrl_ioctl(unsigned int cmd)