]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.1/nvme-fix-srcu-locking-on-error-return-in-nvme_get_ns.patch
Fix up backported ptrace patch
[thirdparty/kernel/stable-queue.git] / queue-5.1 / nvme-fix-srcu-locking-on-error-return-in-nvme_get_ns.patch
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
5
6 [ Upstream commit 100c815cbd56480b3e31518475b04719c363614a ]
7
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.
11
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>
16 ---
17 drivers/nvme/host/core.c | 13 +++++++++----
18 1 file changed, 9 insertions(+), 4 deletions(-)
19
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,
25 {
26 #ifdef CONFIG_NVME_MULTIPATH
27 if (disk->fops == &nvme_ns_head_ops) {
28 + struct nvme_ns *ns;
29 +
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);
34 + if (!ns)
35 + srcu_read_unlock(&(*head)->srcu, *srcu_idx);
36 + return ns;
37 }
38 #endif
39 *head = NULL;
40 @@ -1411,9 +1416,9 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
41
42 ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx);
43 if (unlikely(!ns))
44 - ret = -EWOULDBLOCK;
45 - else
46 - ret = nvme_ns_ioctl(ns, cmd, arg);
47 + return -EWOULDBLOCK;
48 +
49 + ret = nvme_ns_ioctl(ns, cmd, arg);
50 nvme_put_ns_from_disk(head, srcu_idx);
51 return ret;
52 }
53 --
54 2.20.1
55