From patchwork Mon Sep 27 21:59:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12521063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 163E0C433FE for ; Mon, 27 Sep 2021 22:00:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF055610A2 for ; Mon, 27 Sep 2021 22:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237497AbhI0WCL (ORCPT ); Mon, 27 Sep 2021 18:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237245AbhI0WCG (ORCPT ); Mon, 27 Sep 2021 18:02:06 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A50FC061575; Mon, 27 Sep 2021 15:00:28 -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=/2Y2MKFwUhO35iq3LLeVGpx3NHoUnH6gtoSyzdn2zgY=; b=O7xOt0yQy7+6NTR/u/7MXeXiyI kyzS+V7ltb/1KPWatLq8px6EZNtTcLe7H582Ox379kivuzLvFGklALlQjFCkAy3gIyOYG+Uvb3J+u KXzcppsVAKWBWVVw/O2WcuiFIQkF5vQMPJFsv6WyvLnFbE5diBACBx/mukDDSH2WU8SD26J212KM8 TtKeyTcOC59nhG6+Y6wn05cPuoJy26ePaDfiYJlltSDVqAUXnVmCdpRHuC9/paIvuBNJY2hPwbZs8 iDJYESn6bfqszE+eFwoHa4WxnNebufhulzC7m5ZzhanDdS6zIab8sCkN1irrRB/sH/vn/sTvxOatC EK2MxMPA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfM-004SUv-Rf; Mon, 27 Sep 2021 22:00:04 +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 v4 1/6] scsi/sd: add error handling support for add_disk() Date: Mon, 27 Sep 2021 14:59:53 -0700 Message-Id: <20210927215958.1062466-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927215958.1062466-1-mcgrof@kernel.org> References: <20210927215958.1062466-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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. As with the error handling for device_add() we follow the same logic and just put the device so that cleanup is done via the scsi_disk_release(). Reviewed-by: Christoph Hellwig Signed-off-by: Luis Chamberlain --- drivers/scsi/sd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 523bf2fdc253..3a101ad4d16e 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3449,7 +3449,13 @@ static int sd_probe(struct device *dev) pm_runtime_set_autosuspend_delay(dev, sdp->host->hostt->rpm_autosuspend_delay); } - device_add_disk(dev, gd, NULL); + + error = device_add_disk(dev, gd, NULL); + if (error) { + put_device(&sdkp->dev); + goto out; + } + if (sdkp->capacity) sd_dif_config_host(sdkp); From patchwork Mon Sep 27 21:59:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12521069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BA29C433F5 for ; Mon, 27 Sep 2021 22:00:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 177E361359 for ; Mon, 27 Sep 2021 22:00:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237654AbhI0WCR (ORCPT ); Mon, 27 Sep 2021 18:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237404AbhI0WCJ (ORCPT ); Mon, 27 Sep 2021 18:02:09 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4554C06176C; Mon, 27 Sep 2021 15:00:30 -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=GSnwJGqE24fGphaFobcSY6Y9xf4YP0gJ4SZNHqUVKO0=; b=rrId4nxVmKTX2ZVroe7YTkZBoU M0GYACDk+yZdRa8ni89+7dCtMej5oBN3DKfmxRhXECVLY7YcTqa8tLBakNUoX0yvO/P/O9frTwHJY iJ+IVfvyf+uyZv2Q5gLSp43KDW1ZYQ3v2X/nWPujtpiNFKiF8E+SryBriKzQwift1AGwxU7Q2xPBD fTFO8OTA9RQBE/xJyfn+uyEuiGp3KLt2RQ0eUQ/MUj8gY6GJwwm+67luU25bpLuF8+XiKMPfOgqdt yulArpkEM8PTYtdWqgYQzL9AzTSujLL4xofUnpktsNAA0v0TkX2auYGy1JCFLcEJpnlBWdMWqyCfg jDhINijQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfM-004SUx-Sp; Mon, 27 Sep 2021 22:00:04 +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 v4 2/6] scsi/sr: add error handling support for add_disk() Date: Mon, 27 Sep 2021 14:59:54 -0700 Message-Id: <20210927215958.1062466-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927215958.1062466-1-mcgrof@kernel.org> References: <20210927215958.1062466-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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. Just put the cdrom kref and have the unwinding be done by sr_kref_release(). Reviewed-by: Christoph Hellwig Signed-off-by: Luis Chamberlain --- drivers/scsi/sr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 8b17b35283aa..d769057b25a0 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -727,7 +727,12 @@ static int sr_probe(struct device *dev) dev_set_drvdata(dev, cd); disk->flags |= GENHD_FL_REMOVABLE; sr_revalidate_disk(cd); - device_add_disk(&sdev->sdev_gendev, disk, NULL); + + error = device_add_disk(&sdev->sdev_gendev, disk, NULL); + if (error) { + kref_put(&cd->kref, sr_kref_release); + goto fail; + } sdev_printk(KERN_DEBUG, sdev, "Attached scsi CD-ROM %s\n", cd->cdi.name); From patchwork Mon Sep 27 21:59:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12521067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31415C43219 for ; Mon, 27 Sep 2021 22:00:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1967B611C5 for ; Mon, 27 Sep 2021 22:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237667AbhI0WCS (ORCPT ); Mon, 27 Sep 2021 18:02:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237399AbhI0WCJ (ORCPT ); Mon, 27 Sep 2021 18:02:09 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27CE3C06176D; Mon, 27 Sep 2021 15:00:31 -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=HTpU756JwpvmNMTCPyUXuh2Qpa/4bMT1Du7tontR+t4=; b=A0pK45hIyb0/WC2mLfXZDclFOY vYSeo3bNtuSAKN19j+1y8Ulrkkr+TO2dNjrkURnDjL67pI/zNww2Bmf4lzFBAUuyYZ8sBM+NyCznc 9GDxypVIZ5L238CKFUiALoNaF+7JJgnPZwFg5UxI/w2QPmbf7VjD97MiRcKUCUB+fv5oEQvQ9sGy6 2Y12bvtDiOjrx2978ZFfWi8Ti9Frz7LZ7QJcioy9y+12o7L5Xp6UXFEFoRvBpEf020rmUkGntrv2C j6eGSHwM1p0VL0g0NPHC3SZvRVYuTwIuz95vcQKJBih7o/zKFMngWLokRbcT4wUmQkfBYuFgEuqXF RwLNNeVA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfM-004SUz-Tn; Mon, 27 Sep 2021 22:00:04 +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 , Song Liu Subject: [PATCH v4 3/6] md: add error handling support for add_disk() Date: Mon, 27 Sep 2021 14:59:55 -0700 Message-Id: <20210927215958.1062466-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927215958.1062466-1-mcgrof@kernel.org> References: <20210927215958.1062466-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 Signed-off-by: Song Liu --- drivers/md/md.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 6c0c3d0d905a..6bd5ad3c30b4 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5700,7 +5700,11 @@ static int md_alloc(dev_t dev, char *name) disk->flags |= GENHD_FL_EXT_DEVT; disk->events |= DISK_EVENT_MEDIA_CHANGE; mddev->gendisk = disk; - add_disk(disk); + error = add_disk(disk); + if (error) { + blk_cleanup_disk(disk); + goto abort; + } error = kobject_add(&mddev->kobj, &disk_to_dev(disk)->kobj, "%s", "md"); if (error) { From patchwork Mon Sep 27 21:59:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12521071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86D81C433FE for ; Mon, 27 Sep 2021 22:00:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7198D61058 for ; Mon, 27 Sep 2021 22:00:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237639AbhI0WCQ (ORCPT ); Mon, 27 Sep 2021 18:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237393AbhI0WCJ (ORCPT ); Mon, 27 Sep 2021 18:02:09 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14B21C06176A; Mon, 27 Sep 2021 15:00:30 -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=qKliB10CfGq8L4QLEdlnpwyZaQvLLM7XDzH+61TZwL8=; b=XEH5n0CyNS6aPwksdoPT0SWQwJ 2NWFQEDY+TnIX6LyAAy7m0gpsuDiHOzrCN9BGZ/IvsBuEYf28BDSUcJkXXZ19i9N9boDuWqOKNpOP s8XWHSI+GpMKvoYWUytNbQmi4aG392YfwYK5fMfvzQ+EXuhjoWDERdFCRZ1XOfUW14du81gYPIZLR xGXWkL8p7wCmxAjbum96HT1EsS63pWr+xgRaROL0aEc33mfFDN43Q91+/fomdaBfa6XNYbTe/HuZ9 ZoHPAZ10vsOb2IhgTDasF61ETEu6UVDrGmygSV/3b3a1YZWph4mFcj1niNsyOVeWOir8F/ZwmSPQw sqD1jwZA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfM-004SV1-Ur; Mon, 27 Sep 2021 22:00:04 +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 Subject: [PATCH v4 4/6] dm: add add_disk() error handling Date: Mon, 27 Sep 2021 14:59:56 -0700 Message-Id: <20210927215958.1062466-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927215958.1062466-1-mcgrof@kernel.org> References: <20210927215958.1062466-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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. There are two calls to dm_setup_md_queue() which can fail then, one on dm_early_create() and we can easily see that the error path there calls dm_destroy in the error path. The other use case is on the ioctl table_load case. If that fails userspace needs to call the DM_DEV_REMOVE_CMD to cleanup the state - similar to any other failure. Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain Reviewed-by: Mike Snitzer --- drivers/md/dm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index a011d09cb0fa..b83aab8507c2 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2083,7 +2083,9 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) if (r) return r; - add_disk(md->disk); + r = add_disk(md->disk); + if (r) + return r; r = dm_sysfs_init(md); if (r) { From patchwork Mon Sep 27 21:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12521061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 862E6C43217 for ; Mon, 27 Sep 2021 22:00:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6495A610A2 for ; Mon, 27 Sep 2021 22:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237561AbhI0WCN (ORCPT ); Mon, 27 Sep 2021 18:02:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237306AbhI0WCH (ORCPT ); Mon, 27 Sep 2021 18:02:07 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 928FAC061765; Mon, 27 Sep 2021 15:00:29 -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=eOGl5IZyZNnFXmP+I7kKDBQKd7BBidBOUcZv+xPQqWI=; b=lliCu+eKd3V1P+/sYJ0yd2PCrh 9ELPfdPTivFsxLYVUQdamOKpTZQ5EjeWqzTGXImkFZuCCORPUD+0L7y3MbC4152PxLGq8Q1x3nR/y WbH9zYoGLr25pTRIqdL8Iu252s6oS8y94K/V+SoZG/YWmCX6lWaIFAVta7RgjUzwN4eZpHHbAljny jv2QEBGFzrDs1l7laCe38Z7KLC4Fkl4R9S9hCiIPX6RUKp9M4N4rKNplc99ZW22MSmEaB6Zf+XayC yn1e0cU462V4kxPmlszoM+JuCqTn1LzCOZ63BKAAsE7Uby00tY6XZZ6oGKLaoejvN+6vYqRkn+h/6 FCYNbmoQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfM-004SV3-Vt; Mon, 27 Sep 2021 22:00:05 +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 v4 5/6] loop: add error handling support for add_disk() Date: Mon, 27 Sep 2021 14:59:57 -0700 Message-Id: <20210927215958.1062466-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927215958.1062466-1-mcgrof@kernel.org> References: <20210927215958.1062466-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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. Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain --- drivers/block/loop.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 7bf4686af774..00ee365ed5e0 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2394,13 +2394,19 @@ static int loop_add(int i) disk->event_flags = DISK_EVENT_FLAG_UEVENT; sprintf(disk->disk_name, "loop%d", i); /* Make this loop device reachable from pathname. */ - add_disk(disk); + err = add_disk(disk); + if (err) + goto out_cleanup_disk; + /* Show this loop device. */ mutex_lock(&loop_ctl_mutex); lo->idr_visible = true; mutex_unlock(&loop_ctl_mutex); + return i; +out_cleanup_disk: + blk_cleanup_disk(disk); out_cleanup_tags: blk_mq_free_tag_set(&lo->tag_set); out_free_idr: From patchwork Mon Sep 27 21:59:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 12521065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C73D6C4332F for ; Mon, 27 Sep 2021 22:00:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC68660EE9 for ; Mon, 27 Sep 2021 22:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237599AbhI0WCO (ORCPT ); Mon, 27 Sep 2021 18:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237364AbhI0WCI (ORCPT ); Mon, 27 Sep 2021 18:02:08 -0400 Received: from bombadil.infradead.org (unknown [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5253C061769; Mon, 27 Sep 2021 15:00:29 -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=Dn0nwO97tF5sgMNA9UASzPzbBLRiiVkhBQPIhqix1v4=; b=M3AH6Wnz5zIiS4kLah8jwnFJa1 ltMKTFrQbN9BwJYv5ZCv995arAvOdhSKf8EhWlYPhIV7Sr4AAwpOdJUyB/F7ufNhgmWKlJA6kT51u oEr8JdB9+9L2GBUGN066ftfZvxsFamjpWTEunnhVUUlrH0gNd7c9KTDB5OwTMlb2O/mt+cQjgJpxf EADkOpygKHi6dbUm5sFFGcyQ4TNHklG/jXADY24VCBj8UGxfRD6IUN/ewsC4aZXuMafNSgQZs1d2N kmO4Jj/Pkj7TUy+slVYTrDQ5GgBAgTRhJEN1V6r0g+5HcdKvRMN4F6JlNsbifP6Tro38G+UrmTvbP 1KQBjKAw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mUyfN-004SV5-96; Mon, 27 Sep 2021 22:00:05 +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 v4 6/6] nbd: add error handling support for add_disk() Date: Mon, 27 Sep 2021 14:59:58 -0700 Message-Id: <20210927215958.1062466-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210927215958.1062466-1-mcgrof@kernel.org> References: <20210927215958.1062466-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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. Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain --- drivers/block/nbd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 5170a630778d..741365295157 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1757,7 +1757,9 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) disk->fops = &nbd_fops; disk->private_data = nbd; sprintf(disk->disk_name, "nbd%d", index); - add_disk(disk); + err = add_disk(disk); + if (err) + goto out_err_disk; /* * Now publish the device. @@ -1766,6 +1768,8 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) nbd_total_devices++; return nbd; +out_err_disk: + blk_cleanup_disk(disk); out_free_idr: mutex_lock(&nbd_index_mutex); idr_remove(&nbd_index_idr, index);