ataflop: potential out of bounds in do_format()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 21 Apr 2021 10:18:35 +0000 (13:18 +0300)
committerJens Axboe <axboe@kernel.dk>
Wed, 21 Apr 2021 15:15:25 +0000 (09:15 -0600)
commit1ffec389a6431782a8a28805830b6fae9bf00af1
tree5eb749bdeb0c889294504c4232ea0977d0f9966b
parent6327c911aa69bdf0c5f21a44970eab6dba213dde
ataflop: potential out of bounds in do_format()

The function uses "type" as an array index:

q = unit[drive].disk[type]->queue;

Unfortunately the bounds check on "type" isn't done until later in the
function.  Fix this by moving the bounds check to the start.

Fixes: bf9c0538e485 ("ataflop: use a separate gendisk for each media format")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ataflop.c