[Patch] kexec: fix several issues in get_crash_notes()
WANG Cong
xiyou.wangcong at gmail.com
Wed Nov 16 08:09:26 EST 2011
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 <xiyou.wangcong at gmail.com>
---
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index 98cda72..333f6ba 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -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);
More information about the kexec
mailing list