From: WANG Cong <xiyou.wangcong@gmail.com>
To: kexec@lists.infradead.org
Cc: WANG Cong <xiyou.wangcong@gmail.com>, horms@verge.net.au
Subject: [Patch] kexec: fix several issues in get_crash_notes()
Date: Wed, 16 Nov 2011 21:09:26 +0800 [thread overview]
Message-ID: <1321448966-25163-1-git-send-email-xiyou.wangcong@gmail.com> (raw)
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
next reply other threads:[~2011-11-16 13:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 13:09 WANG Cong [this message]
2011-11-18 2:11 ` [Patch] kexec: fix several issues in get_crash_notes() Simon Horman
2011-11-21 7:43 ` Cong Wang
2011-11-21 8:50 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1321448966-25163-1-git-send-email-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=horms@verge.net.au \
--cc=kexec@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox