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

From: Luis Chamberlain
Date: Wed Nov 03 2021 - 14:13:23 EST


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@xxxxxxxxxx>
---
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)
--
2.33.0