linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: axboe@kernel.dk, efremov@linux.com, hch@lst.de
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 12/14] block/ataflop: add registration bool before calling del_gendisk()
Date: Fri,  3 Sep 2021 18:35:34 -0700	[thread overview]
Message-ID: <20210904013536.3181237-13-mcgrof@kernel.org> (raw)
In-Reply-To: <20210904013536.3181237-1-mcgrof@kernel.org>

The ataflop assumes del_gendisk() is safe to call, this is only
true because add_disk() does not return a failure, but that will
change soon. And so, before we get to adding error handling for
that case, let's make sure we keep track of which disks actually
get registered. Then we use this to only call del_gendisk for them.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/block/ataflop.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 6a865d42b1fd..97f1c19f9c02 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -298,6 +298,7 @@ static struct atari_floppy_struct {
 				   disk change detection) */
 	int flags;		/* flags */
 	struct gendisk *disk[NUM_DISK_MINORS];
+	bool registered[NUM_DISK_MINORS];
 	int ref;
 	int type;
 	struct blk_mq_tag_set tag_set;
@@ -2000,8 +2001,10 @@ static void ataflop_probe(dev_t dev)
 		return;
 	mutex_lock(&ataflop_probe_lock);
 	if (!unit[drive].disk[type]) {
-		if (ataflop_alloc_disk(drive, type) == 0)
+		if (ataflop_alloc_disk(drive, type) == 0) {
 			add_disk(unit[drive].disk[type]);
+			unit[drive].registered[type] = true;
+		}
 	}
 	mutex_unlock(&ataflop_probe_lock);
 }
@@ -2065,6 +2068,7 @@ static int __init atari_floppy_init (void)
 		unit[i].track = -1;
 		unit[i].flags = 0;
 		add_disk(unit[i].disk[0]);
+		unit[i].registered[0] = true;
 	}
 
 	printk(KERN_INFO "Atari floppy driver: max. %cD, %strack buffering\n",
@@ -2133,7 +2137,8 @@ static void __exit atari_floppy_exit(void)
 		for (type = 0; type < NUM_DISK_MINORS; type++) {
 			if (!unit[i].disk[type])
 				continue;
-			del_gendisk(unit[i].disk[type]);
+			if (unit[i].registered[type])
+				del_gendisk(unit[i].disk[type]);
 			blk_cleanup_disk(unit[i].disk[type]);
 		}
 		blk_mq_free_tag_set(&unit[i].tag_set);
-- 
2.30.2


  parent reply	other threads:[~2021-09-04  1:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04  1:35 [PATCH 00/14] block: 6th batch of add_disk() error handling conversions Luis Chamberlain
2021-09-04  1:35 ` [PATCH 01/14] block/swim3: add error handling support for add_disk() Luis Chamberlain
2021-09-04  1:35 ` [PATCH 02/14] floppy: fix add_disk() assumption on exit due to new developments Luis Chamberlain
2021-09-04  1:35 ` [PATCH 03/14] floppy: use blk_cleanup_disk() Luis Chamberlain
2021-09-04  1:35 ` [PATCH 04/14] floppy: fix calling platform_device_unregister() on invalid drives Luis Chamberlain
2021-09-04  1:35 ` [PATCH 05/14] floppy: add error handling support for add_disk() Luis Chamberlain
2021-09-04  1:35 ` [PATCH 06/14] amiflop: " Luis Chamberlain
2021-09-04  1:35 ` [PATCH 07/14] swim: simplify using blk_cleanup_disk() on swim_remove() Luis Chamberlain
2021-09-04  1:35 ` [PATCH 08/14] swim: add helper for disk cleanup Luis Chamberlain
2021-09-04  1:35 ` [PATCH 09/14] swim: add a floppy registration bool which triggers del_gendisk() Luis Chamberlain
2021-09-04  1:35 ` [PATCH 10/14] swim: add error handling support for add_disk() Luis Chamberlain
2021-09-04  1:35 ` [PATCH 11/14] block/ataflop: use the blk_cleanup_disk() helper Luis Chamberlain
2021-09-04  1:35 ` Luis Chamberlain [this message]
2021-09-04  1:35 ` [PATCH 13/14] block/ataflop: provide a helper for cleanup up an atari disk Luis Chamberlain
2021-09-04  1:35 ` [PATCH 14/14] block/ataflop add error handling support for add_disk() Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210904013536.3181237-13-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=efremov@linux.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).