Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3010893ybi; Mon, 17 Jun 2019 14:37:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWwH75XgKEnakPl++aW76c9dWRf9Vn0CIe48yOKQ6GK0qhhdKnQ6kf0lxtkgiI4M/uCHrK X-Received: by 2002:a17:902:704c:: with SMTP id h12mr17361014plt.343.1560807479228; Mon, 17 Jun 2019 14:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807479; cv=none; d=google.com; s=arc-20160816; b=ma2Pc8P1Q0fXjjJ9XfJgGMPB2Du9r9o9dkuKJRh//IefestdCiuTsuMKRF9CCVTfid UFbhD/NagRMyZjWIUJI9jrYPq3qdHPOyqiZODejX6LYj2dH1qYGb+/53Bb09/CWmScgj rJkksg+IPFy77o8fxAEx1jE8jVFXX93MFe4AJvC6u0yWlCZA+mGl8mvJuxJ9WuuSZjZa wfYo5e80XsZ7UbbUiQd3833zTrmUM3RPmM2KhmgOia2CTezjMntd96ZNk6vzZ8SQYGLL 3Hu6jiO7z8s5mH0aqDl8pPEY+qBR/ha6EY7Kyxy0tZYspSwe9YuMwTIfFQ8Ym6oDJTNP 6Dpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VF//QSqxqUg5cEm2sdctntwlVQNUBztit+guLDBau4E=; b=eb9qP8drCmo4oObP8uyHA6HX/n8MBGveJ0wKMvBVkZJ9YzhPut0QRHCpSfZmv6o8YX 68BzVoRAVKOUPsVfY2/894POFxDlMQzq/oWscMPC6Ri1RL/T5SK2g1CEidG3d/q4t8df sARr5FX87ca909LbP0nEemmP0l7ySvpsL2sbwCQ93Ac4Ie3HI9sOcDbERXC2/Aaz7EBd ZhTiX1Wc6b2FmPCsGEcbBIO7ZaeleSAsXH/ceAYBxiZvy9gU9sAzYURWsaW1McRkNQM2 8LdBBMXLVWS0z+4cpdbIPwG9zAz6ZAxk/BObske8YGUbVb9iEzY177U6DeraK9m+IAew V4/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T3D+ZUIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o4si10717860pls.391.2019.06.17.14.37.44; Mon, 17 Jun 2019 14:37:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T3D+ZUIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729334AbfFQVVV (ORCPT + 99 others); Mon, 17 Jun 2019 17:21:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:45854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726427AbfFQVVU (ORCPT ); Mon, 17 Jun 2019 17:21:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB63821655; Mon, 17 Jun 2019 21:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806479; bh=Cq2LmbZqcnKDEIkkBXHPoqwlToVHfkXB0LMTankAEzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T3D+ZUIJP/+SvYeecuSSI49MJRTML1d7lBB7nVY1JHC+b7MkrsM2vkvMb8T9I43L9 fX75jN4d9EFM8UOkBafAB/a9gsBS4lavHatJC2tXFlaQ3Ulc6m4Jmpv+8rxjnrFT2x qqKQEgoR4h702b7TkTYfT+jnz4T0XY6RnNxt0/B8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni , Sasha Levin Subject: [PATCH 5.1 066/115] nvme: fix srcu locking on error return in nvme_get_ns_from_disk Date: Mon, 17 Jun 2019 23:09:26 +0200 Message-Id: <20190617210803.524641727@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 100c815cbd56480b3e31518475b04719c363614a ] If we can't get a namespace don't leak the SRCU lock. nvme_ioctl was working around this, but nvme_pr_command wasn't handling this properly. Just do what callers would usually expect. Signed-off-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Chaitanya Kulkarni Signed-off-by: Sasha Levin --- drivers/nvme/host/core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8782d86a8ca3..e29c395f44d2 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1362,9 +1362,14 @@ static struct nvme_ns *nvme_get_ns_from_disk(struct gendisk *disk, { #ifdef CONFIG_NVME_MULTIPATH if (disk->fops == &nvme_ns_head_ops) { + struct nvme_ns *ns; + *head = disk->private_data; *srcu_idx = srcu_read_lock(&(*head)->srcu); - return nvme_find_path(*head); + ns = nvme_find_path(*head); + if (!ns) + srcu_read_unlock(&(*head)->srcu, *srcu_idx); + return ns; } #endif *head = NULL; @@ -1411,9 +1416,9 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode, ns = nvme_get_ns_from_disk(bdev->bd_disk, &head, &srcu_idx); if (unlikely(!ns)) - ret = -EWOULDBLOCK; - else - ret = nvme_ns_ioctl(ns, cmd, arg); + return -EWOULDBLOCK; + + ret = nvme_ns_ioctl(ns, cmd, arg); nvme_put_ns_from_disk(head, srcu_idx); return ret; } -- 2.20.1