}
 }
 
-struct request *nvme_alloc_request(struct request_queue *q,
-               struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid)
+static inline unsigned int nvme_req_op(struct nvme_command *cmd)
 {
-       unsigned op = nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
-       struct request *req;
-
-       if (qid == NVME_QID_ANY) {
-               req = blk_mq_alloc_request(q, op, flags);
-       } else {
-               req = blk_mq_alloc_request_hctx(q, op, flags,
-                               qid ? qid - 1 : 0);
-       }
-       if (IS_ERR(req))
-               return req;
+       return nvme_is_write(cmd) ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN;
+}
 
+static inline void nvme_init_request(struct request *req,
+               struct nvme_command *cmd)
+{
        if (req->q->queuedata)
                req->timeout = NVME_IO_TIMEOUT;
        else /* no queuedata implies admin queue */
        req->cmd_flags |= REQ_FAILFAST_DRIVER;
        nvme_clear_nvme_request(req);
        nvme_req(req)->cmd = cmd;
+}
 
+struct request *nvme_alloc_request(struct request_queue *q,
+               struct nvme_command *cmd, blk_mq_req_flags_t flags)
+{
+       struct request *req;
+
+       req = blk_mq_alloc_request(q, nvme_req_op(cmd), flags);
+       if (!IS_ERR(req))
+               nvme_init_request(req, cmd);
        return req;
 }
 EXPORT_SYMBOL_GPL(nvme_alloc_request);
 
+struct request *nvme_alloc_request_qid(struct request_queue *q,
+               struct nvme_command *cmd, blk_mq_req_flags_t flags, int qid)
+{
+       struct request *req;
+
+       req = blk_mq_alloc_request_hctx(q, nvme_req_op(cmd), flags,
+                       qid ? qid - 1 : 0);
+       if (!IS_ERR(req))
+               nvme_init_request(req, cmd);
+       return req;
+}
+EXPORT_SYMBOL_GPL(nvme_alloc_request_qid);
+
 static int nvme_toggle_streams(struct nvme_ctrl *ctrl, bool enable)
 {
        struct nvme_command c;
        struct request *req;
        int ret;
 
-       req = nvme_alloc_request(q, cmd, flags, qid);
+       if (qid == NVME_QID_ANY)
+               req = nvme_alloc_request(q, cmd, flags);
+       else
+               req = nvme_alloc_request_qid(q, cmd, flags, qid);
        if (IS_ERR(req))
                return PTR_ERR(req);
 
        void *meta = NULL;
        int ret;
 
-       req = nvme_alloc_request(q, cmd, 0, NVME_QID_ANY);
+       req = nvme_alloc_request(q, cmd, 0);
        if (IS_ERR(req))
                return PTR_ERR(req);
 
 {
        struct request *rq;
 
-       rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd, BLK_MQ_REQ_RESERVED,
-                       NVME_QID_ANY);
+       rq = nvme_alloc_request(ctrl->admin_q, &ctrl->ka_cmd,
+                       BLK_MQ_REQ_RESERVED);
        if (IS_ERR(rq))
                return PTR_ERR(rq);
 
 
 
        nvme_nvm_rqtocmd(rqd, ns, cmd);
 
-       rq = nvme_alloc_request(q, (struct nvme_command *)cmd, 0, NVME_QID_ANY);
+       rq = nvme_alloc_request(q, (struct nvme_command *)cmd, 0);
        if (IS_ERR(rq))
                return rq;
 
        DECLARE_COMPLETION_ONSTACK(wait);
        int ret = 0;
 
-       rq = nvme_alloc_request(q, (struct nvme_command *)vcmd, 0,
-                       NVME_QID_ANY);
+       rq = nvme_alloc_request(q, (struct nvme_command *)vcmd, 0);
        if (IS_ERR(rq)) {
                ret = -ENOMEM;
                goto err_cmd;
 
                 req->tag, nvmeq->qid);
 
        abort_req = nvme_alloc_request(dev->ctrl.admin_q, &cmd,
-                       BLK_MQ_REQ_NOWAIT, NVME_QID_ANY);
+                       BLK_MQ_REQ_NOWAIT);
        if (IS_ERR(abort_req)) {
                atomic_inc(&dev->ctrl.abort_limit);
                return BLK_EH_RESET_TIMER;
        cmd.delete_queue.opcode = opcode;
        cmd.delete_queue.qid = cpu_to_le16(nvmeq->qid);
 
-       req = nvme_alloc_request(q, &cmd, BLK_MQ_REQ_NOWAIT, NVME_QID_ANY);
+       req = nvme_alloc_request(q, &cmd, BLK_MQ_REQ_NOWAIT);
        if (IS_ERR(req))
                return PTR_ERR(req);