Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@verge.net.au>
To: WANG Cong <xiyou.wangcong@gmail.com>
Cc: kexec@lists.infradead.org
Subject: Re: [Patch] kexec: fix several issues in get_crash_notes()
Date: Fri, 18 Nov 2011 11:11:56 +0900	[thread overview]
Message-ID: <20111118021155.GM14082@verge.net.au> (raw)
In-Reply-To: <1321448966-25163-1-git-send-email-xiyou.wangcong@gmail.com>

On Wed, Nov 16, 2011 at 09:09:26PM +0800, WANG Cong wrote:
> 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];

I wonder if the following might reduce memory usage:

	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");
> +	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
> 

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

  reply	other threads:[~2011-11-18  2:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-16 13:09 [Patch] kexec: fix several issues in get_crash_notes() WANG Cong
2011-11-18  2:11 ` Simon Horman [this message]
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=20111118021155.GM14082@verge.net.au \
    --to=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    --cc=xiyou.wangcong@gmail.com \
    /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