Skip to content

Commit 49379e6

Browse files
Dan Carpenteraxboe
authored andcommitted
ataflop: fix error handling in atari_floppy_init()
Smatch complains that there is an off by one if the allocation fails in: DMABuffer = atari_stram_alloc(BUFFER_SIZE+512, "ataflop"); In that situation, "i" would be point to one element beyond the end of the unit[] array. There is a second bug because the error handling calls blk_mq_free_tag_set(&unit[i].tag_set); regardless of whether "disk->queue" is NULL or non-NULL. So if blk_mq_init_sq_queue() fails, then that means unit[i].tag_set->tags is NULL and it leads to an Oops. It's easiest to call put_disk() before the goto to clean up the partial iteration. Then the earlier unit[] elements are fully allocated so we can remove the checks whether "disk->queue" is NULL and the code is simpler. Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 65cd1d1 commit 49379e6

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

drivers/block/ataflop.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,7 @@ static int __init atari_floppy_init (void)
19821982
&ataflop_mq_ops, 2,
19831983
BLK_MQ_F_SHOULD_MERGE);
19841984
if (IS_ERR(unit[i].disk->queue)) {
1985+
put_disk(unit[i].disk);
19851986
ret = PTR_ERR(unit[i].disk->queue);
19861987
unit[i].disk->queue = NULL;
19871988
goto err;
@@ -2033,18 +2034,13 @@ static int __init atari_floppy_init (void)
20332034
return 0;
20342035

20352036
err:
2036-
do {
2037+
while (--i >= 0) {
20372038
struct gendisk *disk = unit[i].disk;
20382039

2039-
if (disk) {
2040-
if (disk->queue) {
2041-
blk_cleanup_queue(disk->queue);
2042-
disk->queue = NULL;
2043-
}
2044-
blk_mq_free_tag_set(&unit[i].tag_set);
2045-
put_disk(unit[i].disk);
2046-
}
2047-
} while (i--);
2040+
blk_cleanup_queue(disk->queue);
2041+
blk_mq_free_tag_set(&unit[i].tag_set);
2042+
put_disk(unit[i].disk);
2043+
}
20482044

20492045
unregister_blkdev(FLOPPY_MAJOR, "fd");
20502046
return ret;

0 commit comments

Comments
 (0)