Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3937327pxb; Mon, 30 Aug 2021 14:29:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPVREQ95Vmzcj/fmq0LLKbBwmj9SLT+DMo9hGAWYceSiPJF68z9fibWFi1AYP1a/mUNiaM X-Received: by 2002:a17:907:923:: with SMTP id au3mr25053440ejc.482.1630358981700; Mon, 30 Aug 2021 14:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630358981; cv=none; d=google.com; s=arc-20160816; b=q+TjW/2SWez9HxC1FO8WkSNWv5KYvQzWEVr7y/OGp5pxka+xJBAnAGD3oh4EK7Q+NO keSHSZVVadtAOEusgz4AF+nyBcY/UNjRL9QOUDPs39x9D4qS+QTJBul6SUKfnQ1qUpgW Xwnzg0q4Oxv9/H1rznPKRkeCCwaevWHwUueiA6MRJAOpdg+PSVSgnVbcz7TxD611uNj0 6V61SWTM1eHRkVM9Uafo7UK6JF+eOVOpSWk80fJnkxk7A+74xKSoOKQCXrugTMXUl0J1 gkskfKFiUpkLmec4pCzTov63pctV2qCk42vYr1FLdalgF8fObicweFa8KZLKQdeG/7OQ a90g== 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=5zQ5zmFlRLt8Vc/PBo5Ci+3uvu0k1+9yu+E5gjjsKZw=; b=A7E1377mpTEBhrP5L56lqo239P69ZMsRNkLEAFmrdHRuIxdvedf+5frDAMp++IJ/Q8 FOSOJNjGhB79mI30jvOOWkOxwuwCaiSgQvt/4XtkWHFO7oZXfIlXteBYh0eMOi4j9XkH uTbzgNhSCM5lH56JS3xuZ0nHl/lScqTf3ouibixAAOFzaj990X1OAeGOin5owvUEKloa 0YPKbGWWpdXHg8qUAJvgusRAHTlxDLjIN0iaFAHaLA9iwF1gC+Ilqh32Ujhi2v9tPDI6 6cz9tfOJ/t22stKqUkKExWctZ6V5zBLStEup2i4dIabkwjDUy9Qyo4W+ZTIac//ICLG9 t1kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="snJ/8Ec5"; 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 bl2si16351461ejb.55.2021.08.30.14.29.18; Mon, 30 Aug 2021 14:29:41 -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="snJ/8Ec5"; 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 S238821AbhH3V2G (ORCPT + 99 others); Mon, 30 Aug 2021 17:28:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbhH3V1I (ORCPT ); Mon, 30 Aug 2021 17:27:08 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 742B3C06179A; Mon, 30 Aug 2021 14:26:13 -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=5zQ5zmFlRLt8Vc/PBo5Ci+3uvu0k1+9yu+E5gjjsKZw=; b=snJ/8Ec5mA4+GvreJ9eOfHQHzS wwp7fOpqa2AuI5CcB6OggAYTtUBOnXYaI0utVKbQfaKOdnEVcxczLsqFPvH643E+K7cnFT4Db2iFt HczBtfHcnKchZX2zk+U4n2kRx75BZj2xgPWkPdtIHGF4BoAktogQ/4aKRlCJ8Pvm3hVCL1Q93bqDc dAFyb9sMlodHKmN9YBqTAoeNsACiEEKwKKpeNACGZf6j/U/ng+AKstQBzksDKVxKthlywnSwqd36m TgD+TeXgEuuyFtgB/BPIRHMTShX3bs6/UqxjA/BTIN8gOA3M5xPw3a8wjqC9SpboHJDtW2bisXiOV 021KAy+A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mKomk-000ciF-OG; Mon, 30 Aug 2021 21:25:42 +0000 From: Luis Chamberlain To: axboe@kernel.dk, martin.petersen@oracle.com, jejb@linux.ibm.com, kbusch@kernel.org, sagi@grimberg.me, adrian.hunter@intel.com, beanhuo@micron.com, ulf.hansson@linaro.org, avri.altman@wdc.com, swboyd@chromium.org, agk@redhat.com, snitzer@redhat.com, josef@toxicpanda.com Cc: hch@infradead.org, hare@suse.de, bvanassche@acm.org, ming.lei@redhat.com, linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org, linux-mmc@vger.kernel.org, dm-devel@redhat.com, nbd@other.debian.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain , Christoph Hellwig Subject: [PATCH v3 5/8] md: add error handling support for add_disk() Date: Mon, 30 Aug 2021 14:25:35 -0700 Message-Id: <20210830212538.148729-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210830212538.148729-1-mcgrof@kernel.org> References: <20210830212538.148729-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. We just do the unwinding of what was not done before, and are sure to unlock prior to bailing. Reviewed-by: Christoph Hellwig Signed-off-by: Luis Chamberlain --- drivers/md/md.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index ae8fe54ea358..5c0d3536d7c7 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5704,7 +5704,11 @@ static int md_alloc(dev_t dev, char *name) * through to md_open, so make sure it doesn't get too far */ mutex_lock(&mddev->open_mutex); - add_disk(disk); + error = add_disk(disk); + if (error) { + blk_cleanup_disk(disk); + goto abort_unlock; + } error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md"); if (error) { @@ -5718,6 +5722,7 @@ static int md_alloc(dev_t dev, char *name) if (mddev->kobj.sd && sysfs_create_group(&mddev->kobj, &md_bitmap_group)) pr_debug("pointless warning\n"); + abort_unlock: mutex_unlock(&mddev->open_mutex); abort: mutex_unlock(&disks_mutex); -- 2.30.2