Skip to content

Commit fc7f0dd

Browse files
louis-langholtztorvalds
authored andcommitted
kernel: avoid overflow in cmp_range
Avoid overflow possibility. [ The overflow is purely theoretical, since this is used for memory ranges that aren't even close to using the full 64 bits, but this is the right thing to do regardless. - Linus ] Signed-off-by: Louis Langholtz <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: Peter Anvin <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7ad4b4a commit fc7f0dd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/range.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ static int cmp_range(const void *x1, const void *x2)
113113
{
114114
const struct range *r1 = x1;
115115
const struct range *r2 = x2;
116-
s64 start1, start2;
117116

118-
start1 = r1->start;
119-
start2 = r2->start;
120-
121-
return start1 - start2;
117+
if (r1->start < r2->start)
118+
return -1;
119+
if (r1->start > r2->start)
120+
return 1;
121+
return 0;
122122
}
123123

124124
int clean_sort_range(struct range *range, int az)

0 commit comments

Comments
 (0)