NVMe: Fix possible arithmetic overflow for max segments
authorKeith Busch <keith.busch@intel.com>
Wed, 18 Nov 2015 23:33:08 +0000 (16:33 -0700)
committerJens Axboe <axboe@fb.com>
Thu, 19 Nov 2015 20:02:24 +0000 (13:02 -0700)
Reported-by: Paul Grabinar <paul.grabinar@ranbarg.com>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/nvme/host/pci.c

index 8187df20469535023ae9966aecfb1542260b4270..394fd1631cd0147c0ddd18da7814830f44a7fdd9 100644 (file)
@@ -2268,7 +2268,7 @@ static void nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid)
        if (dev->max_hw_sectors) {
                blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors);
                blk_queue_max_segments(ns->queue,
-                       ((dev->max_hw_sectors << 9) / dev->page_size) + 1);
+                       (dev->max_hw_sectors / (dev->page_size >> 9)) + 1);
        }
        if (dev->stripe_size)
                blk_queue_chunk_sectors(ns->queue, dev->stripe_size >> 9);