From nobody Fri Nov 29 19:52:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1632780083; cv=none; d=zohomail.com; s=zohoarc; b=hoWnFha7gb3AFqbYe4wEOd1Y2aGSJ6ve+tg7WucGKHZl5v3RTDwOt5XgmgdCvuZUCyIge8XVXmPrtJiro/xO/LZeXKxF0TyuFNN0DwpCxZul3ZSPSnojtne0v/yykBI2S+uFJyG+JpTma7kvmvSzqebIOiviWYJqZ0FLhmcVY/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632780083; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hsYRy5mW2eSZFEqOw8JTWcpX/S1jq2Dljgzx3k3VBB0=; b=FISGX7gM7sGe5owOLLRUP0ia+lNudaree/NZfUCikR4vk06pWx0yVdtIST0/TdVYtARaKFeruPiRBWeW8OE0+3mEXgAN0f5CDOABjDn2cRGO6RI9JvI1BM88gKqMEqKAhbd4LRu4s5jMCMURu8M7fCLhU2cD8uQBEcFAYJ9BhCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1632780083297688.2936777862776; Mon, 27 Sep 2021 15:01:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.197200.350197 (Exim 4.92) (envelope-from ) id 1mUygN-0001ge-Lf; Mon, 27 Sep 2021 22:01:07 +0000 Received: by outflank-mailman (output) from mailman id 197200.350197; Mon, 27 Sep 2021 22:01:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mUygN-0001gS-Hz; Mon, 27 Sep 2021 22:01:07 +0000 Received: by outflank-mailman (input) for mailman id 197200; Mon, 27 Sep 2021 22:01:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mUygM-0000mS-EQ for xen-devel@lists.xenproject.org; Mon, 27 Sep 2021 22:01:06 +0000 Received: from bombadil.infradead.org (unknown [2607:7c80:54:e::133]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 44ecce16-2260-4fbf-be97-3488afd89593; Mon, 27 Sep 2021 22:00:49 +0000 (UTC) Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfw-004SvG-Ll; Mon, 27 Sep 2021 22:00:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: 44ecce16-2260-4fbf-be97-3488afd89593 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=hsYRy5mW2eSZFEqOw8JTWcpX/S1jq2Dljgzx3k3VBB0=; b=VUhrw8hzQFU5q/FEnWuCu9vNeC DCvMINggtEXTZJxRA2FK/rIecWzokE3v00zXQby0C8xhCkSHSknRiHDJShGvvg5/WB7yFgDIDckZK PpnRl/rPKh332VtV3wML8z1zrXFA3i55GxnQCfAaEYw70wUGbzTEjF/468zPMAbP4jhENcEZMIqJm 2Mu0n0pLv7IctMpH2UsQFSSaGesroZ0HRe1tGdCY1b4Bk06qhpX4Xv9n9tTQWerqKdilNkIIQwwUJ 1JFfO38L6zcxmIzVXP2nckVh/bimkBRtBsjOqfHtqRjhaQH2lAQbVW3sNXoQ6wYWq6VFluDHCOtLw Cug+py4Q==; From: Luis Chamberlain To: axboe@kernel.dk, colyli@suse.de, kent.overstreet@gmail.com, kbusch@kernel.org, sagi@grimberg.me, vishal.l.verma@intel.com, dan.j.williams@intel.com, dave.jiang@intel.com, ira.weiny@intel.com, konrad.wilk@oracle.com, roger.pau@citrix.com, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, minchan@kernel.org, ngupta@vflare.org, senozhatsky@chromium.org Cc: xen-devel@lists.xenproject.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH v2 07/10] nvdimm/blk: avoid calling del_gendisk() on early failures Date: Mon, 27 Sep 2021 15:00:36 -0700 Message-Id: <20210927220039.1064193-8-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927220039.1064193-1-mcgrof@kernel.org> References: <20210927220039.1064193-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Luis Chamberlain X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1632780084523100003 Content-Type: text/plain; charset="utf-8" If nd_integrity_init() fails we'd get del_gendisk() called, but that's not correct as we should only call that if we're done with device_add_disk(). Fix this by providing unwinding prior to the devm call being registered and moving the devm registration to the very end. This should fix calling del_gendisk() if nd_integrity_init() fails. I only spotted this issue through code inspection. It does not fix any real world bug. Signed-off-by: Luis Chamberlain --- drivers/nvdimm/blk.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/blk.c b/drivers/nvdimm/blk.c index 088d3dd6f6fa..591fa1f86f1e 100644 --- a/drivers/nvdimm/blk.c +++ b/drivers/nvdimm/blk.c @@ -240,6 +240,7 @@ static int nsblk_attach_disk(struct nd_namespace_blk *n= sblk) resource_size_t available_disk_size; struct gendisk *disk; u64 internal_nlba; + int rc; =20 internal_nlba =3D div_u64(nsblk->size, nsblk_internal_lbasize(nsblk)); available_disk_size =3D internal_nlba * nsblk_sector_size(nsblk); @@ -256,20 +257,26 @@ static int nsblk_attach_disk(struct nd_namespace_blk = *nsblk) blk_queue_logical_block_size(disk->queue, nsblk_sector_size(nsblk)); blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); =20 - if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk)) - return -ENOMEM; - if (nsblk_meta_size(nsblk)) { - int rc =3D nd_integrity_init(disk, nsblk_meta_size(nsblk)); + rc =3D nd_integrity_init(disk, nsblk_meta_size(nsblk)); =20 if (rc) - return rc; + goto out_before_devm_err; } =20 set_capacity(disk, available_disk_size >> SECTOR_SHIFT); device_add_disk(dev, disk, NULL); + + /* nd_blk_release_disk() is called if this fails */ + if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk)) + return -ENOMEM; + nvdimm_check_and_set_ro(disk); return 0; + +out_before_devm_err: + blk_cleanup_disk(disk); + return rc; } =20 static int nd_blk_probe(struct device *dev) --=20 2.30.2