diff mbox series

[v4,3/4] floppy: address add_disk() error handling on probe

Message ID 20211103181258.1462704-4-mcgrof@kernel.org (mailing list archive)
State New, archived
Headers show
Series last set for add_disk() error handling | expand

Commit Message

Luis Chamberlain Nov. 3, 2021, 6:12 p.m. UTC
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 <mcgrof@kernel.org>
---
 drivers/block/floppy.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Nov. 3, 2021, 6:20 p.m. UTC | #1
On Wed, Nov 03, 2021 at 11:12:57AM -0700, Luis Chamberlain wrote:
> We need to cleanup resources on the probe() callback registered
> with __register_blkdev(), now that add_disk() error handling is
> supported. Address this.

Same comment as for ataflop.
diff mbox series

Patch

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)