[PATCH 4/8] Move out mem_min/max checking in locate_hole
Yinghai Lu
yinghai at kernel.org
Fri Nov 16 18:04:23 EST 2012
only need to check one time out of the loop.
Signed-off-by: Yinghai Lu <yinghai at kernel.org>
---
kexec/kexec.c | 27 +++++++++++++++++----------
1 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 00f90f5..b8d77bb 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -190,9 +190,9 @@ int sort_segments(struct kexec_info *info)
return 0;
}
-unsigned long locate_hole(struct kexec_info *info,
- unsigned long hole_size, unsigned long hole_align,
- unsigned long hole_min, unsigned long hole_max,
+static unsigned long __locate_hole(struct kexec_info *info,
+ unsigned long hole_size, unsigned long hole_align,
+ unsigned long hole_min, unsigned long hole_max,
int hole_end)
{
int i, j;
@@ -253,22 +253,16 @@ unsigned long locate_hole(struct kexec_info *info,
/* First filter the range start and end values
* through the lens of mem_min, mem_max and hole_align.
*/
- if (start < mem_min) {
- start = mem_min;
- }
if (start < hole_min) {
start = hole_min;
}
start = (start + hole_align - 1) &
~((unsigned long long)hole_align - 1);
- if (end > mem_max) {
- end = mem_max;
- }
if (end > hole_max) {
end = hole_max;
}
/* Is this still a valid memory range? */
- if ((start >= end) || (start >= mem_max) || (end <= mem_min)) {
+ if (start >= end) {
continue;
}
/* Is there enough space left so we can use it? */
@@ -297,6 +291,19 @@ unsigned long locate_hole(struct kexec_info *info,
return hole_base;
}
+unsigned long locate_hole(struct kexec_info *info,
+ unsigned long hole_size, unsigned long hole_align,
+ unsigned long hole_min, unsigned long hole_max,
+ int hole_end)
+{
+ hole_min = max(hole_min, (unsigned long)mem_min);
+ hole_max = min(hole_max, (unsigned long)mem_max);
+
+ return __locate_hole(info, hole_size, hole_align,
+ hole_min, hole_max, hole_end);
+
+}
+
void add_segment_phys_virt(struct kexec_info *info,
const void *buf, size_t bufsz,
unsigned long base, size_t memsz, int phys)
--
1.7.7
More information about the kexec
mailing list