aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorMartin K. Petersen <martin.petersen@oracle.com>2010-03-15 07:46:51 -0400
committerJens Axboe <jens.axboe@oracle.com>2010-03-15 07:47:59 -0400
commit2cda2728aa1c8c006418a24f867b25e5eb7a32e2 (patch)
treec23ec7c38d74237646c5453d96bfbbea4cadfee7 /block
parentf11c9c5c259cb2c3d698548dc3936f773ab1f5b9 (diff)
block: Fix overrun in lcm() and move it to lib
lcm() was defined to take integer-sized arguments. The supplied arguments are multiplied, however, causing us to overflow given sufficiently large input. That in turn led to incorrect optimal I/O size reporting in some cases (RAID over RAID). Switch lcm() over to unsigned long similar to gcd() and move the function from blk-settings.c to lib. Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-settings.c11
1 files changed, 1 insertions, 10 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 31e7a9375c13..4c4700dca56a 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -8,6 +8,7 @@
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/bootmem.h> /* for max_pfn/max_low_pfn */ 9#include <linux/bootmem.h> /* for max_pfn/max_low_pfn */
10#include <linux/gcd.h> 10#include <linux/gcd.h>
11#include <linux/lcm.h>
11#include <linux/jiffies.h> 12#include <linux/jiffies.h>
12 13
13#include "blk.h" 14#include "blk.h"
@@ -461,16 +462,6 @@ void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
461} 462}
462EXPORT_SYMBOL(blk_queue_stack_limits); 463EXPORT_SYMBOL(blk_queue_stack_limits);
463 464
464static unsigned int lcm(unsigned int a, unsigned int b)
465{
466 if (a && b)
467 return (a * b) / gcd(a, b);
468 else if (b)
469 return b;
470
471 return a;
472}
473
474/** 465/**
475 * blk_stack_limits - adjust queue_limits for stacked devices 466 * blk_stack_limits - adjust queue_limits for stacked devices
476 * @t: the stacking driver limits (top device) 467 * @t: the stacking driver limits (top device)