ataflop: fix off by one in ataflop_probe()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 21 Apr 2021 10:19:45 +0000 (13:19 +0300)
committerJens Axboe <axboe@kernel.dk>
Wed, 21 Apr 2021 15:15:27 +0000 (09:15 -0600)
Smatch complains that the "type > NUM_DISK_MINORS" should be >=
instead of >.  We also need to subtract one from "type" at 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

index aed2c2a4f4ea3f95de0849e43683c79a77ebf6e6..d601e49f80e07a10c76351c07d4c79e44d135705 100644 (file)
@@ -2001,7 +2001,10 @@ static void ataflop_probe(dev_t dev)
        int drive = MINOR(dev) & 3;
        int type  = MINOR(dev) >> 2;
 
-       if (drive >= FD_MAX_UNITS || type > NUM_DISK_MINORS)
+       if (type)
+               type--;
+
+       if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
                return;
        mutex_lock(&ataflop_probe_lock);
        if (!unit[drive].disk[type]) {