kexec: fix several issues in get_crash_notes()
Subsystems (2)
PATCH 1/1 kexec: fix several issues in get_crash_notes()
a) We don't need 'crash_notes' array at all, save some bytes on stack.
b) We forgot to fclose 'fp' before return.
---
kexec/arch/i386/crashdump-x86.c +4 -5
@@ -589,20 +589,18 @@ static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)*/ static int get_crash_notes (int cpu,uint64_t *addr,uint64_t *len) { -char crash_notes[PATH_MAX ];char line[MAX_LINE ];FILE *fp;unsigned long vaddr;int count; -sprintf (crash_notes,"/sys/kernel/crash_notes" ); - fp =fopen (crash_notes,"r" ); + fp =fopen ("/sys/kernel/crash_notes" ,"r" );if (fp) {if (fgets (line,sizeof (line), fp) !=0 ) { count =sscanf (line,"%lx" , &vaddr);if (count !=1 ) -die ("Cannot parse %s: %s\n" , crash_notes, -strerror (errno)); +die ("Cannot parse /sys/kernel/crash_notes:" +" %s\n" ,strerror (errno)); } *addr =x86__pa (vaddr + (cpu *MAX_NOTE_BYTES ));
@@ -610,6 +608,7 @@ static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len)#ifdef DEBUG printf ("crash_notes addr = %Lx\n" , *addr);#endif +fclose (fp);return 0 ; }else return get_crash_notes_per_cpu (cpu, addr, len);
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 11 lines · WANG Cong
a) We don't need '
crash_notes' array at all, save some bytes on stack.
b) We forgot to fclose 'fp' before return.Signed-off-by WANG Cong <[email protected]>---
kexec/arch/i386/crashdump-x86.c +0
-0
kexec/arch/i386/crashdump-x86.c static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr) · line 592
Quoted 4 lines
kexec/arch/i386/crashdump-x86.c +0
-1@@ -589,20 +589,18 @@ static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)*/ static int get_crash_notes (int cpu,uint64_t *addr,uint64_t *len) { -char crash_notes[PATH_MAX ];
I wonder if the following might reduce memory usage:
const char *crash_notes = "/sys/kernel/crash_notes";
Quoted 28 lines
kexec/arch/i386/crashdump-x86.c +4
-4char line[MAX_LINE ];FILE *fp;unsigned long vaddr;int count; -sprintf (crash_notes,"/sys/kernel/crash_notes" ); - fp =fopen (crash_notes,"r" ); + fp =fopen ("/sys/kernel/crash_notes" ,"r" );if (fp) {if (fgets (line,sizeof (line), fp) !=0 ) { count =sscanf (line,"%lx" , &vaddr);if (count !=1 ) -die ("Cannot parse %s: %s\n" , crash_notes, -strerror (errno)); +die ("Cannot parse /sys/kernel/crash_notes:" +" %s\n" ,strerror (errno)); } *addr =x86__pa (vaddr + (cpu *MAX_NOTE_BYTES ));@@ -610,6 +608,7 @@ static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len)#ifdef DEBUG printf ("crash_notes addr = %Lx\n" , *addr);#endif +fclose (fp);return 0 ; }else return get_crash_notes_per_cpu (cpu, addr, len);
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 19 lines · Simon Horman
Quoted 11 lines · WANG Cong
a) We don't need '
crash_notes' array at all, save some bytes on stack.
b) We forgot to fclose 'fp' before return.Signed-off-by WANG Cong <[email protected]>---
kexec/arch/i386/crashdump-x86.c +0
-0kexec/arch/i386/crashdump-x86.c static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr) · line 592
Quoted 4 lines
kexec/arch/i386/crashdump-x86.c +0
-1@@ -589,20 +589,18 @@ static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)*/ static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len) { - char crash_notes[PATH_MAX];I wonder if the following might reduce memory usage:
Quoted 1 line
const char
*crash_notes= "/sys/kernel/crash_notes";
Yeah, sure. Below is the new patch.
-------------------->
a) We don't need 'crash_notes' array at all, save some bytes on stack.
b) We forgot to fclose 'fp' before return.
---
kexec/arch/i386/crashdump-x86.c +2 -2
@@ -589,13 +589,12 @@ static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)*/ static int get_crash_notes (int cpu,uint64_t *addr,uint64_t *len) { -char crash_notes[PATH_MAX ]; +const char *crash_notes ="/sys/kernel/crash_notes" ;char line[MAX_LINE ];FILE *fp;unsigned long vaddr;int count; -sprintf (crash_notes,"/sys/kernel/crash_notes" ); fp =fopen (crash_notes,"r" );if (fp) {if (fgets (line,sizeof (line), fp) !=0 ) {
@@ -610,6 +609,7 @@ static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len)#ifdef DEBUG printf ("crash_notes addr = %Lx\n" , *addr);#endif +fclose (fp);return 0 ; }else return get_crash_notes_per_cpu (cpu, addr, len);
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
AppliedQuoted 20 lines · Cong Wang
Quoted 19 lines · Simon Horman
Quoted 11 lines · WANG Cong
a) We don't need '
crash_notes' array at all, save some bytes on stack.
b) We forgot to fclose 'fp' before return.Signed-off-by WANG Cong <[email protected]>---
kexec/arch/i386/crashdump-x86.c +0
-0kexec/arch/i386/crashdump-x86.c static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr) · line 592
Quoted 4 lines
kexec/arch/i386/crashdump-x86.c +0
-1@@ -589,20 +589,18 @@ static int cmdline_add_elfcorehdr(char *cmdline, unsigned long addr)*/ static int get_crash_notes(int cpu, uint64_t *addr, uint64_t *len) { - char crash_notes[PATH_MAX];I wonder if the following might reduce memory usage:
Quoted 7 lines
Quoted 1 line
const char
*crash_notes= "/sys/kernel/crash_notes";Yeah, sure. Below is the new patch.
-------------------->a) We don't need '
crash_notes' array at all, save some bytes on stack.
b) We forgot to fclose 'fp' before return.
Thanks, applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec