From patchwork Wed Nov 3 17:45:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 1550485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zO8F5Jau; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HkvSH0KYfz9sRK for ; Thu, 4 Nov 2021 04:50:23 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ALcpOsC4OeCZkKaiMXMlDDSzVVPrGYhW7rClJawUVrk=; b=zO8F5JauDsIEUx d5htsdn8Gh7Ga6qVMcrP3T9ZcS7lFgpFGLH+A09oXlt24uDMM0tioMbad8eM2UjlPNLW+B+MaC1Y+ iWa2ETyQAXMzQh0bE3VpSPqwvIIRLjXCa40llTi4C5iRuKciP4Uby4P7bIBTnJiVgGWTWg3VasXS8 zZOP9SSlyFX2jZ+sCF2K21yHrOWzPTDip3gsHn+9y6/wYv0yab9K85zP8/C+mx0+MDfLjSM2mbvUg wcMxSWfHuRLsQXW205t3dOkn6s8x/rsKByhwekCPqpBYKQ/7MGFvk7g01Er4XeuPUg3e/chgTL9Yp Mg5NMFnUho7DO5v9pJpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1miKO8-0060yd-EW; Wed, 03 Nov 2021 17:49:28 +0000 Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1miKKA-005z5V-DC; Wed, 03 Nov 2021 17:45:22 +0000 From: Luis Chamberlain To: axboe@kernel.dk, hch@lst.de, penguin-kernel@i-love.sakura.ne.jp, dan.j.williams@intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com, ira.weiny@intel.com, richard@nod.at, miquel.raynal@bootlin.com, vigneshr@ti.com, efremov@linux.com, song@kernel.org, martin.petersen@oracle.com, hare@suse.de, jack@suse.cz, ming.lei@redhat.com, tj@kernel.org, mcgrof@kernel.org Cc: linux-mtd@lists.infradead.org, linux-scsi@vger.kernel.org, linux-raid@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 05/13] nvdimm/blk: add error handling support for add_disk() Date: Wed, 3 Nov 2021 10:45:13 -0700 Message-Id: <20211103174521.1426407-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103174521.1426407-1-mcgrof@kernel.org> References: <20211103174521.1426407-1-mcgrof@kernel.org> MIME-Version: 1.0 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling. Since nvdimm/blk uses devm we just need to move the devm registration towards the end. And in hindsight, that seems to also provide a fix given del_gendisk() should not be called unless the disk was already added via add_disk(). The probably of that issue happening is low though, like OOM while calling devm_add_action(), so the fix is minor. We manually unwind in case of add_disk() failure prior to the devm registration. Reviewed-by: Dan Williams Reviewed-by: Christoph Hellwig Signed-off-by: Luis Chamberlain --- drivers/nvdimm/blk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/blk.c b/drivers/nvdimm/blk.c index 4eef67918a7e..228c33b8d1d6 100644 --- a/drivers/nvdimm/blk.c +++ b/drivers/nvdimm/blk.c @@ -264,7 +264,9 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk) } set_capacity(disk, available_disk_size >> SECTOR_SHIFT); - device_add_disk(dev, disk, NULL); + rc = device_add_disk(dev, disk, NULL); + if (rc) + goto out_before_devm_err; /* nd_blk_release_disk() is called if this fails */ if (devm_add_action_or_reset(dev, nd_blk_release_disk, disk))