kernel/crash: make parse_crashkernel()'s return value more indicant
Subsystems (8)
PATCH 1/1 kernel/crash: make parse_crashkernel()'s return value more indicant
At present, both return and crash_size should be checked to guarantee the success of parse_crashkernel().
Simplify the way by returning negative if fail, positive if success. In case of failure, -EINVAL for bad syntax, -1 for the parsing results in crash_size=0.
--- arch/arm/kernel/setup.c | 2 +- arch/arm64/mm/init.c | 2 +- arch/ia64/kernel/setup.c | 2 +- arch/mips/kernel/setup.c | 2 +- arch/powerpc/kernel/fadump.c | 2 +- arch/powerpc/kernel/machine_kexec.c | 2 +- arch/s390/kernel/setup.c | 2 +- arch/sh/kernel/machine_kexec.c | 2 +- arch/x86/kernel/setup.c | 4 ++-- kernel/crash_core.c | 12 ++++++++++-- 10 files changed, 20 insertions(+), 12 deletions(-)
arch/arm/kernel/setup.c +1 -1
@@ -997,7 +997,7 @@ static void __init reserve_crashkernel(void) total_mem =get_total_mem (); ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret) +if (ret <0 )return ;if (crash_base <=0 ) {
arch/arm64/mm/init.c +1 -1
@@ -79,7 +79,7 @@ static void __init reserve_crashkernel(void) ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base);/* no crashkernel= or invalid value specified */ -if (ret || !crash_size) +if (ret <0 )return ; crash_size =PAGE_ALIGN (crash_size);
arch/ia64/kernel/setup.c +1 -1
@@ -277,7 +277,7 @@ static void __init setup_crashkernel(unsigned long total, int *n) ret =parse_crashkernel (boot_command_line, total, &size, &base); -if (ret =0 && size >0 ) { +if (ret >=0 ) {if (!base) {sort_regions (rsvd_region, *n); *n =merge_regions (rsvd_region, *n);
arch/mips/kernel/setup.c +1 -1
@@ -715,7 +715,7 @@ static void __init mips_parse_crashkernel(void) total_mem =get_total_mem (); ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) +if (ret <0 )return ;if (!memory_region_available (crash_base, crash_size)) {
arch/powerpc/kernel/fadump.c +1 -1
@@ -376,7 +376,7 @@ static inline unsigned long fadump_calculate_reserve_size(void)*/ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &size, &base); -if (ret =0 && size >0 ) { +if (ret >=0 ) {unsigned long max_size;if (fw_dump.reserve_bootvar)
arch/powerpc/kernel/machine_kexec.c +1 -1
@@ -122,7 +122,7 @@ void __init reserve_crashkernel(void)/* use common parsing */ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base); -if (ret =0 && crash_size >0 ) { +if (ret >=0 ) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; }
arch/s390/kernel/setup.c +1 -1
@@ -671,7 +671,7 @@ static void __init reserve_crashkernel(void) crash_base =ALIGN (crash_base,KEXEC_CRASH_MEM_ALIGN ); crash_size =ALIGN (crash_size,KEXEC_CRASH_MEM_ALIGN ); -if (rc || crash_size =0 ) +if (rc <0 )return ;if (memblock.memory.regions[0 ].size < crash_size) {
arch/sh/kernel/machine_kexec.c +1 -1
@@ -157,7 +157,7 @@ void __init reserve_crashkernel(void) ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base); -if (ret =0 && crash_size >0 ) { +if (ret >=0 ) { crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; }
arch/x86/kernel/setup.c +2 -2
@@ -526,11 +526,11 @@ static void __init reserve_crashkernel(void)/* crashkernel=XM */ ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) { +if (ret = -EINVAL ) {/* crashkernel=X,high */ ret =parse_crashkernel_high (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) +if (ret <0 )return ; high = true; }
kernel/crash_core.c +10 -2
@@ -87,7 +87,7 @@ static int __init parse_crashkernel_mem(char *cmdline, cur = tmp;if (size >= system_ram) {pr_warn ("crashkernel: invalid size\n" ); -return -EINVAL ; +return -1 ; }/* match ? */
@@ -108,8 +108,10 @@ static int __init parse_crashkernel_mem(char *cmdline,return -EINVAL ; } } - }else + }else {pr_info ("crashkernel size resulted in zero bytes\n" ); +return -1 ; + }return 0 ; }
@@ -139,6 +141,8 @@ static int __init parse_crashkernel_simple(char *cmdline,pr_warn ("crashkernel: unrecognized char: %c\n" , *cur);return -EINVAL ; } +if (*crash_size =0 ) +return -1 ;return 0 ; }
@@ -181,6 +185,8 @@ static int __init parse_crashkernel_suffix(char *cmdline,pr_warn ("crashkernel: unrecognized char: %c\n" , *cur);return -EINVAL ; } +if (*crash_size =0 ) +return -1 ;return 0 ; }
@@ -266,6 +272,8 @@ static int __init __parse_crashkernel(char *cmdline,/* * That function is the entry point for command line parsing and should be * called from the arch-specific code. +* On success 0 or 1 if @offset is given. On error -EINVAL if bad syntax, +* or -1 if the parsing results in crash_size=0. */ int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
Signature · 1 line
2.7.4
Quoted 5 lines · Pingfan Liu
At present, both return and
crash_sizeshould be checked to guarantee the success ofparse_crashkernel().
Simplify the way by returning negative if fail, positive if success. In case of failure,-EINVALfor bad syntax, -1 for the parsing results in crash_size=0.
I'm not entirely sure what you are trying to say here, but '-1' is not an improvement at all. We surely are not short of proper error codes, right?
Also I don't see any positive return value > 0. So what is this about:
arch/ia64/kernel/setup.c static void __init setup_crashkernel(unsigned long total, int *n) · line 280
Quoted 8 lines
arch/ia64/kernel/setup.c +1
-1@@ -277,7 +277,7 @@ static void __init setup_crashkernel(unsigned long total, int *n) ret =parse_crashkernel (boot_command_line, total, &size, &base); -if (ret =0 && size >0 ) { +if (ret >=0 ) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^ ????
arch/powerpc/kernel/fadump.c static inline unsigned long fadump_calculate_reserve_size(void) · line 379
Quoted 11 lines
arch/ia64/kernel/setup.c +0
-0if (!memory_region_available (crash_base, crash_size)) {arch/powerpc/kernel/fadump.c +1
-1@@ -376,7 +376,7 @@ static inline unsigned long fadump_calculate_reserve_size(void)*/ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &size, &base); -if (ret =0 && size >0 ) { +if (ret >=0 ) {
and this ?
arch/powerpc/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 125
Quoted 13 lines
arch/powerpc/kernel/fadump.c +0
-0unsigned long max_size;if (fw_dump.reserve_bootvar)arch/powerpc/kernel/machine_kexec.c +1
-1@@ -122,7 +122,7 @@ void __init reserve_crashkernel(void)/* use common parsing */ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base); -if (ret =0 && crash_size >0 ) { +if (ret >=0 ) {
Again.
arch/sh/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 160
Quoted 11 lines
arch/powerpc/kernel/machine_kexec.c +0
-0crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; }arch/sh/kernel/machine_kexec.c +1
-1@@ -157,7 +157,7 @@ void __init reserve_crashkernel(void) ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base); -if (ret =0 && crash_size >0 ) { +if (ret >=0 ) {
And some more.
arch/x86/kernel/setup.c static void __init reserve_crashkernel(void) · line 529
Quoted 13 lines
arch/sh/kernel/machine_kexec.c +0
-0crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; }arch/x86/kernel/setup.c +1
-1@@ -526,11 +526,11 @@ static void __init reserve_crashkernel(void)/* crashkernel=XM */ ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) { +if (ret = -EINVAL ) {
Without an explanation why this proceedes on error codes other than EINVAL this is uncomprehensible. Comments exist for a reason.
Quoted 9 lines
arch/x86/kernel/setup.c +1
-1/* crashkernel=X,high */ ret =parse_crashkernel_high (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) +if (ret <0 )return ; high = true;
arch/x86/kernel/setup.c static int __init parse_crashkernel_mem(char *cmdline, · line 90
Quoted 5 lines
arch/x86/kernel/setup.c +1
-1@@ -87,7 +87,7 @@ static int __init parse_crashkernel_mem(char *cmdline, cur = tmp;if (size >= system_ram) {pr_warn ("crashkernel: invalid size\n" ); -return -EINVAL ; +return -1 ;
Well, this is incomprehensible as well. The pr_warn() says invalid and then you change the error code to something magic.
Thanks,
tglx
Quoted 12 lines · Thomas Gleixner
Quoted 5 lines · Pingfan Liu
At present, both return and
crash_sizeshould be checked to guarantee the success ofparse_crashkernel().
Simplify the way by returning negative if fail, positive if success. In case of failure,-EINVALfor bad syntax, -1 for the parsing results in crash_size=0.I'm not entirely sure what you are trying to say here, but '-1' is not an improvement at all. We surely are not short of proper error codes, right?
The different negative return values are only used by x86. The option "crashkernel=X,high", which is only used on x86, causes parse_kernel() to return -EINVAL, then let parse_crashkernel_high() have a try.
When parsing crashkernel=size@offset and crashkernel=range1:size1, there are other cases of failure, which is not worth to call parse_crashkernel_high() to have a try. That is "-1" aiming for.
First, in parse_crashkernel_mem(), if demanded size is bigger than system ram, this one looks like -ENOMEM, but -ENOMEM normally is used for allocation. Second, in parse_crashkernel_mem(), if system ram is not inside the range listed by "crashkernel=". Third, crashkernel=0MB is given in the option (not in practice, but can not forbid user to do so).
All of these cases can be treated as -EINVAL, but hard to define the error codes.
Quoted 2 lines
Also I don't see any positive return value > 0. So what is this about:
Yes. 0 is enough for success. I had thought about returning 1 if @offset is specified in crashkernel. But at present, no use case for it.
Quoted 64 lines
arch/ia64/kernel/setup.c static void __init setup_crashkernel(unsigned long total, int *n) · line 280
Quoted 8 lines
arch/ia64/kernel/setup.c +1
-1@@ -277,7 +277,7 @@ static void __init setup_crashkernel(unsigned long total, int *n) ret =parse_crashkernel (boot_command_line, total, &size, &base); -if (ret =0 && size >0 ) { +if (ret >=0 ) {^^^^^^^^^^^^^^^^^^^^^^^^^^^ ????
arch/powerpc/kernel/fadump.c static inline unsigned long fadump_calculate_reserve_size(void) · line 379
Quoted 11 lines
arch/ia64/kernel/setup.c +0
-0if (!memory_region_available (crash_base, crash_size)) {arch/powerpc/kernel/fadump.c +1
-1@@ -376,7 +376,7 @@ static inline unsigned long fadump_calculate_reserve_size(void)*/ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &size, &base); -if (ret =0 && size >0 ) { +if (ret >=0 ) {and this ?
arch/powerpc/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 125
Quoted 13 lines
arch/powerpc/kernel/fadump.c +0
-0unsigned long max_size;if (fw_dump.reserve_bootvar)arch/powerpc/kernel/machine_kexec.c +1
-1@@ -122,7 +122,7 @@ void __init reserve_crashkernel(void)/* use common parsing */ ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base); -if (ret =0 && crash_size >0 ) { +if (ret >=0 ) {Again.
arch/sh/kernel/machine_kexec.c void __init reserve_crashkernel(void) · line 160
Quoted 11 lines
arch/powerpc/kernel/machine_kexec.c +0
-0crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; }arch/sh/kernel/machine_kexec.c +1
-1@@ -157,7 +157,7 @@ void __init reserve_crashkernel(void) ret =parse_crashkernel (boot_command_line,memblock_phys_mem_size (), &crash_size, &crash_base); -if (ret =0 && crash_size >0 ) { +if (ret >=0 ) {And some more.
Quoted 9 lines
arch/sh/kernel/machine_kexec.c +0
-0crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; }arch/x86/kernel/setup.c +0
-0@@ -526,11 +526,11 @@ static void __init reserve_crashkernel(void)
Quoted 8 lines
arch/x86/kernel/setup.c static void __init reserve_crashkernel(void) · line 529
Quoted 4 lines
arch/x86/kernel/setup.c +1
-1/* crashkernel=XM */ ret =parse_crashkernel (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) { +if (ret = -EINVAL ) {Without an explanation why this proceedes on error codes other than EINVAL this is uncomprehensible. Comments exist for a reason.
As explained above, deciding whether to let parse_crashkernel_high() try.
Quoted 8 lines
Quoted 7 lines
arch/x86/kernel/setup.c +1
-1/* crashkernel=X,high */ ret =parse_crashkernel_high (boot_command_line, total_mem, &crash_size, &crash_base); -if (ret !=0 || crash_size <=0 ) +if (ret <0 )return ; high = true;
Quoted 10 lines
arch/x86/kernel/setup.c static int __init parse_crashkernel_mem(char *cmdline, · line 90
Quoted 6 lines
arch/x86/kernel/setup.c +1
-1@@ -87,7 +87,7 @@ static int __init parse_crashkernel_mem(char *cmdline, cur = tmp;if (size >= system_ram) {pr_warn ("crashkernel: invalid size\n" ); -return -EINVAL ; +return -1 ;Well, this is incomprehensible as well. The
pr_warn()says invalid and then you change the error code to something magic.
As explained above, want to know whether worth to let parse_crashkernel_high() try.
What about the following alternative method? Treating crash_size=0 as -EINVAL. Then on x86, just call parse_crashkernel_high() blindly to have a try. Thanks for your review.
Regards,
Pingfan