Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Patch] kexec: fix several issues in get_crash_notes()
@ 2011-11-16 13:09 WANG Cong
  2011-11-18  2:11 ` Simon Horman
  0 siblings, 1 reply; 4+ messages in thread
From: WANG Cong @ 2011-11-16 13:09 UTC (permalink / raw)
  To: kexec; +Cc: WANG Cong, horms

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@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);

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-21  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-16 13:09 [Patch] kexec: fix several issues in get_crash_notes() WANG Cong
2011-11-18  2:11 ` Simon Horman
2011-11-21  7:43   ` Cong Wang
2011-11-21  8:50     ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox