Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1589681pxb; Fri, 27 Aug 2021 12:19:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzU6RKvvekfgv8k4OownRh/l+Ev7tYNl1hrtz7XGSGquix5B5PHU1gSknFmVmaNJskdbteh X-Received: by 2002:a6b:fc1a:: with SMTP id r26mr8680103ioh.30.1630091992663; Fri, 27 Aug 2021 12:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630091992; cv=none; d=google.com; s=arc-20160816; b=Uc8nCsYGOhBA8FyhU4jfrfzjIb2JICiihT1obKzTufBqxadqtq2asdNfLYr7DREL36 P3tVkqzJxjOSnjKffR+mcucTpDY/Ze6nmPh8zlLXznbmxAyYhiTsG2kGI2FUFcSWTPTp cFKy6m29a+MBXlwGkrPw329WXNZgE3SLXK1znGqkzM7ZNOua75NxIbqkCUz9m7FElcK5 rCWcpgjamNUWNz9xEGQf/jDIRmWq1Aqcb7gr7XV+CsDwNXw3EIKD/wjccKja3iS2aeyP yO75XqpzNCgJowuoX9yNnVYOldOq7T9pXtizG5/nC2YFNMrNaDKxS0k87M70rjI2yxwI IUtg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vLYLL0oFZhxGylgSJPWXsGjPK2psQoUWyxkb9au47Xw=; b=TImNYQZ7zJjUjKEKY6eCmGLLh/S+dO5i01/7EX8mQ5XFzndmvUNbY6zupEjW6+oUvH xRgWxpRnkGmcsi/RoqM5CfSc7Q+8odXcRJh+uG2tvZ61zN50bWtn/a7TDOUmHfJkSWX2 ysScFXI34OpTuLlGpPPzz0US0bQSosraYRNvgcozpSG3ugvZEQYTsf++CmZ9T+tER/E1 AjQczLUsFlm1feZZhGedoSeadcwfBEIRqjkZKUCXPS1ZsVWR4uyZXR8GKvQoaX33w4PP vRIyhiVmNS94krC8x2jU4abslF4aYqR5qX5HnzjgyX5REDXPb7d+6aOgg2ZQFPgmnUl7 hBYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=O3AoZlZn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q15si4093073ilc.138.2021.08.27.12.19.41; Fri, 27 Aug 2021 12:19:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=O3AoZlZn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231360AbhH0TTZ (ORCPT + 99 others); Fri, 27 Aug 2021 15:19:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbhH0TTP (ORCPT ); Fri, 27 Aug 2021 15:19:15 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2BBCC061757; Fri, 27 Aug 2021 12:18:25 -0700 (PDT) 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=vLYLL0oFZhxGylgSJPWXsGjPK2psQoUWyxkb9au47Xw=; b=O3AoZlZnbbHQwfvGAtYvirog88 EON0OdRqJ6ZNzUhguT3+31CMn99Dygty5KuFC7VLotkku9ilfuOy06Oc7/54lv5yP7YxlxivOMJuF hD2YhvsrCtHG51gDcXamrBh68I6Ogwu0ifCKgUDsQBoyWwXuMLFKxdlQcc+TFIr84VKkggf/t61i6 e5dMcioA6KN+rhWZTtIsd8fu8k/YXGPA6Qfjktzpj0VLdY+6m1toijsuQeqiSXIcBBQSLwvDBDi+v lgKdIIRbsqr8QoIXbG3zrVctqdrqvShN+LA602q9Y7/vv5WNzB+RE7I1AQx/cTOh147AgEQchMFg2 vWX3qxJg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mJhMh-00D5B9-Dv; Fri, 27 Aug 2021 19:18:11 +0000 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 08/10] nvdimm/blk: add error handling support for add_disk() Date: Fri, 27 Aug 2021 12:18:07 -0700 Message-Id: <20210827191809.3118103-9-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210827191809.3118103-1-mcgrof@kernel.org> References: <20210827191809.3118103-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. 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 591fa1f86f1e..9f1eb41404ac 100644 --- a/drivers/nvdimm/blk.c +++ b/drivers/nvdimm/blk.c @@ -265,7 +265,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)) -- 2.30.2