From patchwork Thu Oct 21 16:38: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: 12575835 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 733F1C4167B for ; Thu, 21 Oct 2021 16:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 574766152B for ; Thu, 21 Oct 2021 16:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbhJUQlY (ORCPT ); Thu, 21 Oct 2021 12:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbhJUQlW (ORCPT ); Thu, 21 Oct 2021 12:41:22 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A08C061764; Thu, 21 Oct 2021 09:39:06 -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=lGkULHYlBjDIPGiB/BE49QsU3PYu09QZP7ud3a4qHGY=; b=e+di7685rK0Ua2QBhEel7x35Px 3s9d5JRAOPeveFkDA/VOmRmn9bcR4GTZGXpjO9ktTY3II/UvdclAeQ67CM6rbgnx0w+CCHMBO4i8V 8/tDbERibVZ6ZlTNPzN8Aq76Ia7jChl6tJuZxW9j4ftW5W8Kr30QWFPEPbR/ByTkaRozPqAFiuZhq 3Fs+OgC0I7oXorZrTRLykSvVJrShdqoO+/njEZ+LdVpITTPF15ynxc697N8JyVnfAoBRwR9QsLkjQ YEwOd74lmXfDOV3cIoNRUcjAVQMfCxr0p+2i+zru5oqreCfjvOMRB7yV0704XRlasxTz7VDw/wTZD Ru2964cA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdb5l-008OYw-VX; Thu, 21 Oct 2021 16:38:57 +0000 From: Luis Chamberlain To: axboe@kernel.dk, hch@lst.de, penguin-kernel@i-love.sakura.ne.jp, schmitzmic@gmail.com, efremov@linux.com, song@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, viro@zeniv.linux.org.uk, hare@suse.de, jack@suse.cz, ming.lei@redhat.com, tj@kernel.org Cc: linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tetsuo Handa , Luis Chamberlain Subject: [PATCH v3 1/3] ataflop: remove ataflop_probe_lock mutex Date: Thu, 21 Oct 2021 09:38:54 -0700 Message-Id: <20211021163856.2000993-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021163856.2000993-1-mcgrof@kernel.org> References: <20211021163856.2000993-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Tetsuo Handa Commit bf9c0538e485b591 ("ataflop: use a separate gendisk for each media format") introduced ataflop_probe_lock mutex, but forgot to unlock the mutex when atari_floppy_init() (i.e. module loading) succeeded. This will result in double lock deadlock if ataflop_probe() is called. Also, unregister_blkdev() must not be called from atari_floppy_init() with ataflop_probe_lock held when atari_floppy_init() failed, for ataflop_probe() waits for ataflop_probe_lock with major_names_lock held (i.e. AB-BA deadlock). __register_blkdev() needs to be called last in order to avoid calling ataflop_probe() when atari_floppy_init() is about to fail, for memory for completing already-started ataflop_probe() safely will be released as soon as atari_floppy_init() released ataflop_probe_lock mutex. As with commit 8b52d8be86d72308 ("loop: reorder loop_exit"), unregister_blkdev() needs to be called first in order to avoid calling ataflop_alloc_disk() from ataflop_probe() after del_gendisk() from atari_floppy_exit(). By relocating __register_blkdev() / unregister_blkdev() as explained above, we can remove ataflop_probe_lock mutex, for probe function and __exit function are serialized by major_names_lock mutex. Signed-off-by: Tetsuo Handa Fixes: bf9c0538e485b591 ("ataflop: use a separate gendisk for each media format") Reviewed-by: Luis Chamberlain Tested-by: Michael Schmitz --- drivers/block/ataflop.c | 47 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 3d217f1d7440..9aecd37ea8a5 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -1976,8 +1976,6 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type) return 0; } -static DEFINE_MUTEX(ataflop_probe_lock); - static void ataflop_probe(dev_t dev) { int drive = MINOR(dev) & 3; @@ -1988,14 +1986,32 @@ static void ataflop_probe(dev_t dev) if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS) return; - mutex_lock(&ataflop_probe_lock); if (!unit[drive].disk[type]) { if (ataflop_alloc_disk(drive, type) == 0) { add_disk(unit[drive].disk[type]); unit[drive].registered[type] = true; } } - mutex_unlock(&ataflop_probe_lock); +} + +static void atari_floppy_cleanup(void) +{ + int i; + int type; + + for (i = 0; i < FD_MAX_UNITS; i++) { + for (type = 0; type < NUM_DISK_MINORS; type++) { + if (!unit[i].disk[type]) + continue; + del_gendisk(unit[i].disk[type]); + blk_cleanup_queue(unit[i].disk[type]->queue); + put_disk(unit[i].disk[type]); + } + blk_mq_free_tag_set(&unit[i].tag_set); + } + + del_timer_sync(&fd_timer); + atari_stram_free(DMABuffer); } static void atari_cleanup_floppy_disk(struct atari_floppy_struct *fs) @@ -2021,11 +2037,6 @@ static int __init atari_floppy_init (void) /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */ return -ENODEV; - mutex_lock(&ataflop_probe_lock); - ret = __register_blkdev(FLOPPY_MAJOR, "fd", ataflop_probe); - if (ret) - goto out_unlock; - for (i = 0; i < FD_MAX_UNITS; i++) { memset(&unit[i].tag_set, 0, sizeof(unit[i].tag_set)); unit[i].tag_set.ops = &ataflop_mq_ops; @@ -2081,7 +2092,12 @@ static int __init atari_floppy_init (void) UseTrackbuffer ? "" : "no "); config_types(); - return 0; + ret = __register_blkdev(FLOPPY_MAJOR, "fd", ataflop_probe); + if (ret) { + printk(KERN_ERR "atari_floppy_init: cannot register block device\n"); + atari_floppy_cleanup(); + } + return ret; err_out_dma: atari_stram_free(DMABuffer); @@ -2089,9 +2105,6 @@ static int __init atari_floppy_init (void) while (--i >= 0) atari_cleanup_floppy_disk(&unit[i]); - unregister_blkdev(FLOPPY_MAJOR, "fd"); -out_unlock: - mutex_unlock(&ataflop_probe_lock); return ret; } @@ -2136,14 +2149,8 @@ __setup("floppy=", atari_floppy_setup); static void __exit atari_floppy_exit(void) { - int i; - - for (i = 0; i < FD_MAX_UNITS; i++) - atari_cleanup_floppy_disk(&unit[i]); unregister_blkdev(FLOPPY_MAJOR, "fd"); - - del_timer_sync(&fd_timer); - atari_stram_free( DMABuffer ); + atari_floppy_cleanup(); } module_init(atari_floppy_init) From patchwork Thu Oct 21 16:38: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: 12575839 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 5462CC4332F for ; Thu, 21 Oct 2021 16:39:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F53061505 for ; Thu, 21 Oct 2021 16:39:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232168AbhJUQlb (ORCPT ); Thu, 21 Oct 2021 12:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232130AbhJUQl2 (ORCPT ); Thu, 21 Oct 2021 12:41:28 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55958C061764; Thu, 21 Oct 2021 09:39: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=+b/lrsIDFJhqrjd+tWsnOZ+oYDQEr0WPrNW7mTh7MZo=; b=No8x6av4qzP/egn5c0VTK9TDf8 VPRKWFy/ipwPrcZixJJ3ATWLb1E/KnHvJeqNKaOHnpOWz50I3dykhIkp6UdTPW3M41yl2XWQ8Fd4l jSukRGum5dhv5HIXMLGt8QOdcqIjcTaawzvVHKkSaiv6ZAaDJ4hF0lPVUdFFwsbo1hsns3rE63z6N c6dt8MH2e8GQif/8qWgbs5eBWb8awwlOdHtsNuGTMxmX9Udq6yBLB2XVBFMDwcr5lAHOHrF96Ue4v iFVfo3UrNtWCqsWWCasFDWuRFGnEg5km89tAShalSStaQGW9QmmIbTGh3rWVWcDaPx4XhDL9PrBHO lno9GyHg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdb5m-008OYy-0T; Thu, 21 Oct 2021 16:38:58 +0000 From: Luis Chamberlain To: axboe@kernel.dk, hch@lst.de, penguin-kernel@i-love.sakura.ne.jp, schmitzmic@gmail.com, efremov@linux.com, song@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, viro@zeniv.linux.org.uk, hare@suse.de, jack@suse.cz, ming.lei@redhat.com, tj@kernel.org Cc: linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH v3 2/3] block: make __register_blkdev() return an error Date: Thu, 21 Oct 2021 09:38:55 -0700 Message-Id: <20211021163856.2000993-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021163856.2000993-1-mcgrof@kernel.org> References: <20211021163856.2000993-1-mcgrof@kernel.org> MIME-Version: 1.0 Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This makes __register_blkdev() return an error, and also changes the probe() call to return an error as well. We expand documentation for the probe call to ensure that if the block device already exists we don't return on error on that condition. We do this as otherwise we loose ability to handle concurrent requests if the block device already existed. Cc: Tetsuo Handa Signed-off-by: Luis Chamberlain --- block/bdev.c | 5 ++++- block/genhd.c | 21 +++++++++++++++------ drivers/block/ataflop.c | 19 ++++++++++++++----- drivers/block/brd.c | 7 +++++-- drivers/block/floppy.c | 17 +++++++++++++---- drivers/block/loop.c | 11 ++++++++--- drivers/md/md.c | 12 +++++++++--- drivers/scsi/sd.c | 3 ++- include/linux/genhd.h | 4 ++-- 9 files changed, 72 insertions(+), 27 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index cff0bb3a4578..ec6982f7c4a6 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -735,10 +735,13 @@ struct block_device *blkdev_get_no_open(dev_t dev) { struct block_device *bdev; struct inode *inode; + int ret; inode = ilookup(blockdev_superblock, dev); if (!inode) { - blk_request_module(dev); + ret = blk_request_module(dev); + if (ret) + return NULL; inode = ilookup(blockdev_superblock, dev); if (!inode) return NULL; diff --git a/block/genhd.c b/block/genhd.c index 000e344265ca..404429e6f06c 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -183,7 +183,7 @@ static struct blk_major_name { struct blk_major_name *next; int major; char name[16]; - void (*probe)(dev_t devt); + int (*probe)(dev_t devt); } *major_names[BLKDEV_MAJOR_HASH_SIZE]; static DEFINE_MUTEX(major_names_lock); static DEFINE_SPINLOCK(major_names_spinlock); @@ -213,7 +213,13 @@ 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: callback that is called on access to any minor number of @major. + * This will return 0 if the block device is already present or was + * not present and it succcessfully added a new one. If the block device + * was not already present but it was a valid request an error reflecting + * the reason why adding the block device is returned. An error should not + * be returned if the block device already exists as otherwise concurrent + * requests to open an existing block device would fail. * * The @name must be unique within the system. * @@ -231,7 +237,7 @@ void blkdev_show(struct seq_file *seqf, off_t offset) * Use register_blkdev instead for any new code. */ int __register_blkdev(unsigned int major, const char *name, - void (*probe)(dev_t devt)) + int (*probe)(dev_t devt)) { struct blk_major_name **n, *p; int index, ret = 0; @@ -650,17 +656,18 @@ static ssize_t disk_badblocks_store(struct device *dev, return badblocks_store(disk->bb, page, len, 0); } -void blk_request_module(dev_t devt) +int blk_request_module(dev_t devt) { unsigned int major = MAJOR(devt); struct blk_major_name **n; + int err; mutex_lock(&major_names_lock); for (n = &major_names[major_to_index(major)]; *n; n = &(*n)->next) { if ((*n)->major == major && (*n)->probe) { - (*n)->probe(devt); + err = (*n)->probe(devt); mutex_unlock(&major_names_lock); - return; + return err; } } mutex_unlock(&major_names_lock); @@ -668,6 +675,8 @@ void blk_request_module(dev_t devt) if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0) /* Make old-style 2.4 aliases work */ request_module("block-major-%d", MAJOR(devt)); + + return 0; } /* diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 9aecd37ea8a5..c58750dcc685 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -1976,22 +1976,31 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type) return 0; } -static void ataflop_probe(dev_t dev) +static int ataflop_probe(dev_t dev) { int drive = MINOR(dev) & 3; int type = MINOR(dev) >> 2; + int err = 0; if (type) type--; if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS) - return; + return -EINVAL; + 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) { + blk_cleanup_disk(unit[drive].disk[type]); + unit[drive].disk[type] = NULL; + } else + unit[drive].registered[type] = true; } } + + return err; } static void atari_floppy_cleanup(void) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index a896ee175d86..fa6f532035fc 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -437,9 +437,12 @@ static int brd_alloc(int i) return err; } -static void brd_probe(dev_t dev) +static int brd_probe(dev_t dev) { - brd_alloc(MINOR(dev) / max_part); + int ret = brd_alloc(MINOR(dev) / max_part); + if (ret == -EEXIST) + return 0; + return ret; } static void brd_del_one(struct brd_device *brd) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 3873e789478e..ff3422f517a6 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4518,21 +4518,30 @@ static int floppy_alloc_disk(unsigned int drive, unsigned int type) static DEFINE_MUTEX(floppy_probe_lock); -static void floppy_probe(dev_t dev) +static int 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)) - return; + return -EINVAL; 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) { + blk_cleanup_disk(disks[drive][type]); + disks[drive][type] = NULL; + } + } } mutex_unlock(&floppy_probe_lock); + + return err; } static int __init do_floppy_init(void) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 00ee365ed5e0..5ffb1900baa9 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2433,13 +2433,18 @@ static void loop_remove(struct loop_device *lo) kfree(lo); } -static void loop_probe(dev_t dev) +static int loop_probe(dev_t dev) { int idx = MINOR(dev) >> part_shift; + int ret; if (max_loop && idx >= max_loop) - return; - loop_add(idx); + return -EINVAL; + ret = loop_add(idx); + if (ret == -EEXIST) + return 0; + + return ret; } static int loop_control_remove(int idx) diff --git a/drivers/md/md.c b/drivers/md/md.c index 5111ed966947..cdfabb90acb5 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5737,12 +5737,18 @@ static int md_alloc(dev_t dev, char *name) return error; } -static void md_probe(dev_t dev) +static int md_probe(dev_t dev) { + int error = 0; + if (MAJOR(dev) == MD_MAJOR && MINOR(dev) >= 512) - return; + return -EINVAL; if (create_on_open) - md_alloc(dev, NULL); + error = md_alloc(dev, NULL); + if (error == -EEXIST) + return 0; + + return error; } static int add_named_array(const char *val, const struct kernel_param *kp) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 665e79d3f06c..5f5e4a4cbe28 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -632,8 +632,9 @@ static struct scsi_driver sd_template = { * Don't request a new module, as that could deadlock in multipath * environment. */ -static void sd_default_probe(dev_t devt) +static int sd_default_probe(dev_t devt) { + return 0; } /* diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 8d98ff613aae..f805173de312 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -288,7 +288,7 @@ struct gendisk *__blk_alloc_disk(int node, struct lock_class_key *lkclass); void blk_cleanup_disk(struct gendisk *disk); int __register_blkdev(unsigned int major, const char *name, - void (*probe)(dev_t devt)); + int (*probe)(dev_t devt)); #define register_blkdev(major, name) \ __register_blkdev(major, name, NULL) void unregister_blkdev(unsigned int major, const char *name); @@ -320,7 +320,7 @@ static inline int bd_register_pending_holders(struct gendisk *disk) dev_t part_devt(struct gendisk *disk, u8 partno); void inc_diskseq(struct gendisk *disk); dev_t blk_lookup_devt(const char *name, int partno); -void blk_request_module(dev_t devt); +int blk_request_module(dev_t devt); #ifdef CONFIG_BLOCK void printk_all_partitions(void); #else /* CONFIG_BLOCK */ From patchwork Thu Oct 21 16:38: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: 12575837 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 B055EC43217 for ; Thu, 21 Oct 2021 16:39:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 983A161505 for ; Thu, 21 Oct 2021 16:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231912AbhJUQlW (ORCPT ); Thu, 21 Oct 2021 12:41:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbhJUQlW (ORCPT ); Thu, 21 Oct 2021 12:41:22 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E64C061764; Thu, 21 Oct 2021 09:39:06 -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=5Fa6osgzG4VxZaX6kVT87k4aCBY3SA+fIXDyr0H5bnE=; b=fWW+67KN3XFJuIVdLP4+f1eJyf OR/jzg6Rs5PFWWNWnsCldxuJ0lRuI967CxMhJdBVWUsqXs8SMf5X/+HGSk11k6vPQcbMndfz1J2Gd N3nVElpGhlnLbq82g/XXeTs+R/SKFqcrTcV5MEpSM0eY6RLn8kUxgRu9Rp2Q3erouKJNi/VXd3fV7 D/KIUulfZ7DfcjtSxa5QIF1iOrrXiWuK7aOdFBXjNiQb2+Th+I8rC4bd7uyEVeUsQ8O/24QjHKRqV qJqWoDVDYmIjRW0KMH4ZhozF2irk/8OC8F1co9A8cnrcfTxzm0zvro1N8+ydfi8U8qalRumDg+WC+ 6XNRJh7A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdb5m-008OZ0-1p; Thu, 21 Oct 2021 16:38:58 +0000 From: Luis Chamberlain To: axboe@kernel.dk, hch@lst.de, penguin-kernel@i-love.sakura.ne.jp, schmitzmic@gmail.com, efremov@linux.com, song@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, viro@zeniv.linux.org.uk, hare@suse.de, jack@suse.cz, ming.lei@redhat.com, tj@kernel.org Cc: linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH v3 3/3] block: add __must_check for *add_disk*() callers Date: Thu, 21 Oct 2021 09:38:56 -0700 Message-Id: <20211021163856.2000993-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021163856.2000993-1-mcgrof@kernel.org> References: <20211021163856.2000993-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 --- 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 404429e6f06c..51ceb084135a 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -397,8 +397,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); @@ -543,7 +543,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 f805173de312..bddcb30d94c1 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); }