aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2017-11-16 15:36:49 -0500
committerChristoph Hellwig <hch@lst.de>2017-11-20 02:38:11 -0500
commitb0d61d586f09fd814a45a5d778fe0d6123f67c2a (patch)
tree475f348d8742332afb1cee36185892ec17ac97f6
parent89c4aff6d4f71726f22e567f046dc1dd73c35de1 (diff)
nvme: Fix NULL dereference on reservation request
This fixes using the NULL 'head' before getting the reference. It is however possible the head will always be NULL, so this patch uses the struct nvme_ns to get the ns_id field. Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--drivers/nvme/host/core.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 25da74d310d1..a2ab4e440bea 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1449,19 +1449,19 @@ static int nvme_pr_command(struct block_device *bdev, u32 cdw10,
1449 int srcu_idx, ret; 1449 int srcu_idx, ret;
1450 u8 data[16] = { 0, }; 1450 u8 data[16] = { 0, };
1451 1451
1452 ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
1453 if (unlikely(!ns))
1454 return -EWOULDBLOCK;
1455
1452 put_unaligned_le64(key, &data[0]); 1456 put_unaligned_le64(key, &data[0]);
1453 put_unaligned_le64(sa_key, &data[8]); 1457 put_unaligned_le64(sa_key, &data[8]);
1454 1458
1455 memset(&c, 0, sizeof(c)); 1459 memset(&c, 0, sizeof(c));
1456 c.common.opcode = op; 1460 c.common.opcode = op;
1457 c.common.nsid = cpu_to_le32(head->ns_id); 1461 c.common.nsid = cpu_to_le32(ns->head->ns_id);
1458 c.common.cdw10[0] = cpu_to_le32(cdw10); 1462 c.common.cdw10[0] = cpu_to_le32(cdw10);
1459 1463
1460 ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx); 1464 ret = nvme_submit_sync_cmd(ns->queue, &c, data, 16);
1461 if (unlikely(!ns))
1462 ret = -EWOULDBLOCK;
1463 else
1464 ret = nvme_submit_sync_cmd(ns->queue, &c, data, 16);
1465 nvme_put_ns_from_disk(head, srcu_idx); 1465 nvme_put_ns_from_disk(head, srcu_idx);
1466 return ret; 1466 return ret;
1467} 1467}