[PATCH] block/swim3: Fix resource leaks on add_disk() failure
From: Haoxiang Li
Date: Tue Nov 17 2026 - 07:46:17 EST
When add_disk() fails after swim3_add_device() succeeds,
swim3_attach() releases the disk and tag set but leaves the IRQ,
register mappings and MacIO resource reservations allocated.
Add swim3_remove_device() to release these resources on this failure
path. Free the IRQ before unmapping the registers, and disable the
controller when it was enabled directly by the driver.
Fixes: 2d4bcf764297 ("block/swim3: add error handling support for add_disk()")
Signed-off-by: Haoxiang Li <haoxiang_li2024@xxxxxxx>
---
drivers/block/swim3.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index a03de4c4d35f..bd3fc3326194 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -1185,6 +1185,23 @@ static int swim3_add_device(struct macio_dev *mdev, int index)
return rc;
}
+static void swim3_remove_device(struct macio_dev *mdev)
+{
+ struct device_node *swim = mdev->ofdev.dev.of_node;
+ struct floppy_state *fs = macio_get_drvdata(mdev);
+
+ free_irq(fs->swim3_intr, fs);
+
+ if (!mdev->media_bay)
+ pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 0);
+
+ iounmap(fs->dma);
+ iounmap(fs->swim3);
+
+ macio_release_resource(mdev, 0);
+ macio_release_resource(mdev, 1);
+}
+
static int swim3_attach(struct macio_dev *mdev,
const struct of_device_id *match)
{
@@ -1232,11 +1249,13 @@ static int swim3_attach(struct macio_dev *mdev,
set_capacity(disk, 2880);
rc = add_disk(disk);
if (rc)
- goto out_cleanup_disk;
+ goto out_remove_device;
disks[floppy_count++] = disk;
return 0;
+out_remove_device:
+ swim3_remove_device(mdev);
out_cleanup_disk:
put_disk(disk);
out_free_tag_set:
--
2.25.1