From patchwork Wed Nov 3 18:12: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: 12601435 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 66B0DC433FE for ; Wed, 3 Nov 2021 18:13:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5365C60EDF for ; Wed, 3 Nov 2021 18:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbhKCSPx (ORCPT ); Wed, 3 Nov 2021 14:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbhKCSPt (ORCPT ); Wed, 3 Nov 2021 14:15:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A02C061203; Wed, 3 Nov 2021 11:13: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=/VvXRoVO5D/RYmzfu2Viv3DDMIMX9DlAinlG2alJ+SM=; b=1/rCXzNN+PwirBOGOC8vCCcR8M kySObapW1OL41gTI+sELio+8ML6oU6Y3wEQwuuVfVQt4rpeXAfvwmDHZ4oztyVfVjgVxTy20bhdZi y9R4e5ZAn7bOCRVQNdOJ/KV1KwIdekM5esv+RTeRP7XBFuPIxN9RftKWAKlN2MvPqAFQQUzzQuqcB nDNra97HMYoEi8Br1AXOXrtjZ29T7OjalLZ6QTecRAVGsblz//PBXGwTjdgX2bLRu/OtDGBqUWTLN Nl2wziqcIgxTRTzki0SUxTy7VW7DQet8fvevSCWgnQblDSWc9AhVm9iBUxoJz7MUkvxR88+uPLjfI /U06Y0tg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1miKkt-0068XC-RD; Wed, 03 Nov 2021 18:12:59 +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 v4 1/4] block: update __register_blkdev() probe documentation Date: Wed, 3 Nov 2021 11:12:55 -0700 Message-Id: <20211103181258.1462704-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103181258.1462704-1-mcgrof@kernel.org> References: <20211103181258.1462704-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org __register_blkdev() is used to register a probe callback, and that callback is typically used to call add_disk(). Now that we are able to capture errors for add_disk(), we need to fix those probe calls where add_disk() fails and clean up resources. We don't extend the probe call to return the error given: 1) we'd have to always special-case the case where the disk was already present, as otherwise concurrent requests to open an existing block device would fail, and this would be a userspace visible change 2) the error from ilookup() on blkdev_get_no_open() is sufficient 3) The only thing the probe call is used for is to support pre-devtmpfs, pre-udev semantics that want to create disks when their pre-created device node is accessed, and so we don't care for failures on probe there. Expand documentation for the probe callback to ensure users cleanup resources if add_disk() is used and to clarify this interface may be removed in the future. Signed-off-by: Luis Chamberlain Reviewed-by: Christoph Hellwig --- block/genhd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/genhd.c b/block/genhd.c index 4ed87f25276a..2f5b7e24e88a 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -213,7 +213,10 @@ void blkdev_show(struct seq_file *seqf, off_t offset) * @major: the requested major device number [1..BLKDEV_MAJOR_MAX-1]. If * @major = 0, try to allocate any unused major number. * @name: the name of the new block device as a zero terminated string - * @probe: allback that is called on access to any minor number of @major + * @probe: pre-devtmpfs / pre-udev callback used to create disks when their + * pre-created device node is accessed. When a probe call uses + * add_disk() and it fails the driver must cleanup resources. This + * interface may soon be removed. * * The @name must be unique within the system. * From patchwork Wed Nov 3 18:12: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: 12601439 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 21488C433EF for ; Wed, 3 Nov 2021 18:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 110AA610E7 for ; Wed, 3 Nov 2021 18:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231590AbhKCSQK (ORCPT ); Wed, 3 Nov 2021 14:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbhKCSQE (ORCPT ); Wed, 3 Nov 2021 14:16:04 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 289E4C061714; Wed, 3 Nov 2021 11:13: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=7+hD9NoEwudZFuVmk78ozQWIhfst9nLgIC7pZG4lA28=; b=yDjLlasRgH999cIdBWjfzGuZbW B3XBm7aKgSPbukHcGcr7RzETO/d3SVEFhPofIkpxrYjBIY0BdyGALIg1ydwPaK8bdjrnfDOagXmAd jgpq1vYIKoDtYLA75wWO9HkV4JCSN65NZPn9rpQiPkjmZSa57AhF8m95lOPyA5dXOho1JEbn5VkXZ iIp/oNrKA9pgi5ZBBQSPHR8lOlp9ss+kRZJp7McUbYD75D9j8A1Wyfx+RcurggTKL9VkI8X86XAhY czFjXnL6OWFkNGriWDtFCoTIz1qvY55Ok7ebNwzjr0v7pMu6lKEOFns2gjg5691qhhNCH3GIloQ0Z T5CGZQpw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1miKkt-0068XJ-Tc; Wed, 03 Nov 2021 18:12:59 +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 v4 2/4] ataflop: address add_disk() error handling on probe Date: Wed, 3 Nov 2021 11:12:56 -0700 Message-Id: <20211103181258.1462704-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103181258.1462704-1-mcgrof@kernel.org> References: <20211103181258.1462704-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We need to cleanup resources on the probe() callback registered with __register_blkdev(), now that add_disk() error handling is supported. Address this. Signed-off-by: Luis Chamberlain Reviewed-by: Christoph Hellwig --- drivers/block/ataflop.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 170dd193cef6..e981b351f37e 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -2012,6 +2012,7 @@ static void ataflop_probe(dev_t dev) { int drive = MINOR(dev) & 3; int type = MINOR(dev) >> 2; + int err = 0; if (type) type--; @@ -2019,11 +2020,20 @@ static void ataflop_probe(dev_t dev) if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS) return; if (!unit[drive].disk[type]) { - if (ataflop_alloc_disk(drive, type) == 0) { - add_disk(unit[drive].disk[type]); - unit[drive].registered[type] = true; + err = ataflop_alloc_disk(drive, type); + if (err == 0) { + err = add_disk(unit[drive].disk[type]); + if (err) + goto err_out; + else + unit[drive].registered[type] = true; } } + return; + +err_out: + blk_cleanup_disk(unit[drive].disk[type]); + unit[drive].disk[type] = NULL; } static void atari_floppy_cleanup(void) From patchwork Wed Nov 3 18:12: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: 12601431 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 4E5A4C433F5 for ; Wed, 3 Nov 2021 18:13:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 286876112E for ; Wed, 3 Nov 2021 18:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhKCSPw (ORCPT ); Wed, 3 Nov 2021 14:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229943AbhKCSPt (ORCPT ); Wed, 3 Nov 2021 14:15:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D81AFC061714; Wed, 3 Nov 2021 11:13:12 -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=hfvcTHZKSWjoPW0PNuYwn+asx66naeAEMFOrEFwKxfY=; b=DbzYr5VuaLhS5tLME+a++7VJ1y 3qtVe1EGa0T5S6pH+S+O0yyFXuUY3rq9A//cMNqYlqrIK8TQNJzfTsRF0MBoA9it/5gg6VS/7laFY zm5V/76uelJblHJa8kAptQzCDOj4Xi4nuM0NJrkmr+iB2iWN7OlMUTyrcmQ4DQ/vgzaTMWFGRx/uY /Dow/OcYx+VSThoRBQrAsYYRZk4GzB1IdKns8Is2GWooRbcvmEh93SUX0EFHXwmCkcoJRXq0c3wM4 dgJYFrf861GNhNhpRdsPoVJl8k+8pKPEpLdU6mYUHIhGUGCkdMevsJV+QhLlwNAYzq/ii0xPZZuB1 kCxCQEag==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1miKkt-0068XM-Vf; Wed, 03 Nov 2021 18:12:59 +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 v4 3/4] floppy: address add_disk() error handling on probe Date: Wed, 3 Nov 2021 11:12:57 -0700 Message-Id: <20211103181258.1462704-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103181258.1462704-1-mcgrof@kernel.org> References: <20211103181258.1462704-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We need to cleanup resources on the probe() callback registered with __register_blkdev(), now that add_disk() error handling is supported. Address this. Signed-off-by: Luis Chamberlain --- drivers/block/floppy.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 3873e789478e..255e88efb535 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4522,6 +4522,7 @@ static void floppy_probe(dev_t dev) { unsigned int drive = (MINOR(dev) & 3) | ((MINOR(dev) & 0x80) >> 5); unsigned int type = (MINOR(dev) >> 2) & 0x1f; + int err = 0; if (drive >= N_DRIVE || !floppy_available(drive) || type >= ARRAY_SIZE(floppy_type)) @@ -4529,10 +4530,20 @@ static void floppy_probe(dev_t dev) mutex_lock(&floppy_probe_lock); if (!disks[drive][type]) { - if (floppy_alloc_disk(drive, type) == 0) - add_disk(disks[drive][type]); + err = floppy_alloc_disk(drive, type); + if (err == 0) { + err = add_disk(disks[drive][type]); + if (err) + goto err_out; + } } mutex_unlock(&floppy_probe_lock); + return; + +err_out: + blk_cleanup_disk(disks[drive][type]); + disks[drive][type] = NULL; + mutex_unlock(&floppy_probe_lock); } static int __init do_floppy_init(void) From patchwork Wed Nov 3 18:12: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: 12601433 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 251DBC43219 for ; Wed, 3 Nov 2021 18:13:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0EBBF61058 for ; Wed, 3 Nov 2021 18:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbhKCSPy (ORCPT ); Wed, 3 Nov 2021 14:15:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbhKCSPu (ORCPT ); Wed, 3 Nov 2021 14:15:50 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6558C061205; Wed, 3 Nov 2021 11:13: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=pg4gmNh1LJ/nJ2qn9IZ5B5DKTs052Xo7JbSGIRJ4CBY=; b=UlxwZ9krS4KJ4r4Dqasl2+CTo0 EfsyopjYdRXZgXXR96x/6AACGYVghBcfIH/fmLoEKO2DfnkswXtYopRhHsRN87qJjksj+VznQVo+L aqt1VtsEjrtlXz4LeHtElYrtctCpYpJ/O4+Q/OTpnqggyuMRIrHSh7rayGaAsLbla4a64+pj/h8C7 kana7ZpQR3xzUvvlPNN2LJIlljpJ45Q+7RXedSTZsX+VI80SaUC9/HwxpGBSG3kRonbSZHdjDR3Ap vqVD24mVtQwraNDgLfpYWDqNrUQJUbHrpcK1We7cBimN1yIg9I4q2PYFdpJzLAjMPT5RIcZ2Xl4zv kS1FH0zA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1miKku-0068XR-1B; Wed, 03 Nov 2021 18:13:00 +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 v4 4/4] block: add __must_check for *add_disk*() callers Date: Wed, 3 Nov 2021 11:12:58 -0700 Message-Id: <20211103181258.1462704-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103181258.1462704-1-mcgrof@kernel.org> References: <20211103181258.1462704-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Now that we have done a spring cleaning on all drivers and added error checking / handling, let's keep it that way and ensure no new drivers fail to stick with it. Signed-off-by: Luis Chamberlain Reviewed-by: Christoph Hellwig --- block/genhd.c | 6 +++--- include/linux/genhd.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 2f5b7e24e88a..2263f7862241 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -394,8 +394,8 @@ static void disk_scan_partitions(struct gendisk *disk) * This function registers the partitioning information in @disk * with the kernel. */ -int device_add_disk(struct device *parent, struct gendisk *disk, - const struct attribute_group **groups) +int __must_check device_add_disk(struct device *parent, struct gendisk *disk, + const struct attribute_group **groups) { struct device *ddev = disk_to_dev(disk); @@ -542,7 +542,7 @@ int device_add_disk(struct device *parent, struct gendisk *disk, out_free_ext_minor: if (disk->major == BLOCK_EXT_MAJOR) blk_free_ext_minor(disk->first_minor); - return WARN_ON_ONCE(ret); /* keep until all callers handle errors */ + return ret; } EXPORT_SYMBOL(device_add_disk); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 59eabbc3a36b..f7d6810e68b3 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -205,9 +205,9 @@ static inline dev_t disk_devt(struct gendisk *disk) void disk_uevent(struct gendisk *disk, enum kobject_action action); /* block/genhd.c */ -int device_add_disk(struct device *parent, struct gendisk *disk, - const struct attribute_group **groups); -static inline int add_disk(struct gendisk *disk) +int __must_check device_add_disk(struct device *parent, struct gendisk *disk, + const struct attribute_group **groups); +static inline int __must_check add_disk(struct gendisk *disk) { return device_add_disk(NULL, disk, NULL); }