-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Martin K. Petersen
authored and
Jens Axboe
committed
Mar 15, 2010
1 parent
f11c9c5
commit 2cda272
Showing
4 changed files
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _LCM_H | ||
#define _LCM_H | ||
|
||
#include <linux/compiler.h> | ||
|
||
unsigned long lcm(unsigned long a, unsigned long b) __attribute_const__; | ||
|
||
#endif /* _LCM_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/gcd.h> | ||
#include <linux/module.h> | ||
|
||
/* Lowest common multiple */ | ||
unsigned long lcm(unsigned long a, unsigned long b) | ||
{ | ||
if (a && b) | ||
return (a * b) / gcd(a, b); | ||
else if (b) | ||
return b; | ||
|
||
return a; | ||
} | ||
EXPORT_SYMBOL_GPL(lcm); |