Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update crash_reserve.c: Optimizing Crash Kernel Memory Reservation, Fixing a few typos #948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions kernel/crash_reserve.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int __init parse_crashkernel_mem(char *cmdline,
}
cur++;

/* if no ':' is here, than we read the end */
/* if no ':' is here, then we read the end */
if (*cur != ':') {
end = memparse(cur, &tmp);
if (cur == tmp) {
Expand Down Expand Up @@ -131,12 +131,13 @@ static int __init parse_crashkernel_mem(char *cmdline,
cur++;
*crash_base = memparse(cur, &tmp);
if (cur == tmp) {
pr_warn("crahskernel: Memory value expected after '@'\n");
pr_warn("crashkernel: Memory value expected after '@'\n"); // Fixed typo
return -EINVAL;
}
}
} else
} else {
pr_info("crashkernel size resulted in zero bytes\n");
}

return 0;
}
Expand Down Expand Up @@ -180,7 +181,7 @@ static __initdata char *suffix_tbl[] = {
};

/*
* That function parses "suffix" crashkernel command lines like
* That function parses "suffix" crashkernel command lines like
*
* crashkernel=size,[high|low]
*
Expand Down Expand Up @@ -332,8 +333,10 @@ int __init parse_crashkernel(char *cmdline,
*high = true;
}
#endif
if (!*crash_size)
if (!*crash_size) {
pr_warn("crashkernel: calculated crash size is zero\n");
ret = -EINVAL;
}

return ret;
}
Expand Down Expand Up @@ -380,6 +383,8 @@ void __init reserve_crashkernel_generic(char *cmdline,
{
unsigned long long search_end = CRASH_ADDR_LOW_MAX, search_base = 0;
bool fixed_base = false;
int retry_count = 0;
const int max_retries = 5; // To prevent infinite loops

/* User specifies base address explicitly. */
if (crash_base) {
Expand All @@ -395,6 +400,11 @@ void __init reserve_crashkernel_generic(char *cmdline,
crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
search_base, search_end);
if (!crash_base) {
if (retry_count++ >= max_retries) {
pr_warn("crashkernel reservation failed after maximum retries.\n");
return;
}

/*
* For crashkernel=size[KMG]@offset[KMG], print out failure
* message if can't reserve the specified region.
Expand Down