diff mbox series

dm-settings: fix a possible integer overflow in blk_queue_max_hw_sectors

Message ID alpine.LRH.2.02.2011200451180.28876@file01.intranet.prod.int.rdu2.redhat.com (mailing list archive)
State New, archived
Headers show
Series dm-settings: fix a possible integer overflow in blk_queue_max_hw_sectors | expand

Commit Message

Mikulas Patocka Nov. 20, 2020, 9:55 a.m. UTC
Fix a possible overflow due to shift left.
Also, replace the constant "9" with SECTOR_SHIFT.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 block/blk-settings.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

Index: linux-2.6/block/blk-settings.c
===================================================================
--- linux-2.6.orig/block/blk-settings.c	2020-11-19 21:20:18.000000000 +0100
+++ linux-2.6/block/blk-settings.c	2020-11-20 10:50:15.000000000 +0100
@@ -151,8 +151,8 @@  void blk_queue_max_hw_sectors(struct req
 	struct queue_limits *limits = &q->limits;
 	unsigned int max_sectors;
 
-	if ((max_hw_sectors << 9) < PAGE_SIZE) {
-		max_hw_sectors = 1 << (PAGE_SHIFT - 9);
+	if (max_hw_sectors < 1 << (PAGE_SHIFT - SECTOR_SHIFT)) {
+		max_hw_sectors = 1 << (PAGE_SHIFT - SECTOR_SHIFT);
 		printk(KERN_INFO "%s: set to minimum %d\n",
 		       __func__, max_hw_sectors);
 	}
@@ -161,7 +161,7 @@  void blk_queue_max_hw_sectors(struct req
 	max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors);
 	max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
 	limits->max_sectors = max_sectors;
-	q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9);
+	q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - SECTOR_SHIFT);
 }
 EXPORT_SYMBOL(blk_queue_max_hw_sectors);