1 From 5058ab089148342cfcee79ed39f01707e9747b32 Mon Sep 17 00:00:00 2001
2 From: Christoph Hellwig <hch@lst.de>
3 Date: Fri, 17 May 2019 02:47:33 -0700
4 Subject: nvme: fix srcu locking on error return in nvme_get_ns_from_disk
6 [ Upstream commit 100c815cbd56480b3e31518475b04719c363614a ]
8 If we can't get a namespace don't leak the SRCU lock. nvme_ioctl was
9 working around this, but nvme_pr_command wasn't handling this properly.
10 Just do what callers would usually expect.
12 Signed-off-by: Christoph Hellwig <hch@lst.de>
13 Reviewed-by: Keith Busch <keith.busch@intel.com>
14 Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
15 Signed-off-by: Sasha Levin <sashal@kernel.org>
17 drivers/nvme/host/core.c | 13 +++++++++----
18 1 file changed, 9 insertions(+), 4 deletions(-)
20 diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
21 index 8782d86a8ca3..e29c395f44d2 100644
22 --- a/drivers/nvme/host/core.c
23 +++ b/drivers/nvme/host/core.c
24 @@ -1362,9 +1362,14 @@ static struct nvme_ns *nvme_get_ns_from_disk(struct gendisk *disk,
26 #ifdef CONFIG_NVME_MULTIPATH
27 if (disk->fops == &nvme_ns_head_ops) {
30 *head = disk->private_data;
31 *srcu_idx = srcu_read_lock(&(*head)->srcu);
32 - return nvme_find_path(*head);
33 + ns = nvme_find_path(*head);
35 + srcu_read_unlock(&(*head)->srcu, *srcu_idx);
40 @@ -1411,9 +1416,9 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
42 ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
46 - ret = nvme_ns_ioctl(ns, cmd, arg);
47 + return -EWOULDBLOCK;
49 + ret = nvme_ns_ioctl(ns, cmd, arg);
50 nvme_put_ns_from_disk(head, srcu_idx);