Skip to content

Commit

Permalink
swim: add helper for disk cleanup
Browse files Browse the repository at this point in the history
Disk cleanup can be shared between exit and bringup. Use a
helper to do the work required. The only functional change at
this point is we're being overly paraoid on exit to check for
a null disk as well now, and this should be safe.

We'll later expand on this, this change just makes subsequent
changes easier to read.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20210927220302.1073499-9-mcgrof@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
mcgrof authored and axboe committed Oct 18, 2021
1 parent b76a30c commit 4e9abe7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions drivers/block/swim.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,17 @@ static const struct blk_mq_ops swim_mq_ops = {
.queue_rq = swim_queue_rq,
};

static void swim_cleanup_floppy_disk(struct floppy_state *fs)
{
struct gendisk *disk = fs->disk;

if (!disk)
return;

blk_cleanup_disk(disk);
blk_mq_free_tag_set(&fs->tag_set);
}

static int swim_floppy_init(struct swim_priv *swd)
{
int err;
Expand Down Expand Up @@ -836,12 +847,7 @@ static int swim_floppy_init(struct swim_priv *swd)
exit_put_disks:
unregister_blkdev(FLOPPY_MAJOR, "fd");
do {
struct gendisk *disk = swd->unit[drive].disk;

if (!disk)
continue;
blk_cleanup_disk(disk);
blk_mq_free_tag_set(&swd->unit[drive].tag_set);
swim_cleanup_floppy_disk(&swd->unit[drive]);
} while (drive--);
return err;
}
Expand Down Expand Up @@ -912,8 +918,7 @@ static int swim_remove(struct platform_device *dev)

for (drive = 0; drive < swd->floppy_count; drive++) {
del_gendisk(swd->unit[drive].disk);
blk_cleanup_disk(swd->unit[drive].disk);
blk_mq_free_tag_set(&swd->unit[drive].tag_set);
swim_cleanup_floppy_disk(&swd->unit[drive]);
}

unregister_blkdev(FLOPPY_MAJOR, "fd");
Expand Down

0 comments on commit 4e9abe7

Please sign in to comment.