nvme: fix sqhd reference when admin queue connect fails
authorJames Smart <jsmart2021@gmail.com>
Thu, 21 Sep 2017 15:13:49 +0000 (08:13 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Sep 2017 18:42:11 +0000 (12:42 -0600)
Fix bug in sqhd patch.

It wasn't the sq that was at risk. In the case where the admin queue
connect command fails, the sq->size field is not set. Therefore, this
becomes a divide by zero error.

Add a quick check to bypass under this failure condition.

Signed-off-by: James Smart <james.smart@broadcom.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/nvme/target/core.c

index c2a768a94235dcbb7bdd6f794ebde833c0d8e755..1b208beeef5097c6e4a2bd38e112543b8818af19 100644 (file)
@@ -390,7 +390,8 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
        if (status)
                nvmet_set_status(req, status);
 
-       req->sq->sqhd = (req->sq->sqhd + 1) % req->sq->size;
+       if (req->sq->size)
+               req->sq->sqhd = (req->sq->sqhd + 1) % req->sq->size;
        req->rsp->sq_head = cpu_to_le16(req->sq->sqhd);
        req->rsp->sq_id = cpu_to_le16(req->sq->qid);
        req->rsp->command_id = req->cmd->common.command_id;