]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
vmcore-allocate-buffer-for-elf-headers-on-page-size-alignment-fix
authorAndrew Morton <akpm@linux-foundation.org>
Thu, 27 Jun 2013 23:51:33 +0000 (09:51 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 28 Jun 2013 06:37:34 +0000 (16:37 +1000)
Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/vmcore.c

index 80fea97bf5f6579d44f75a0bf43624718fe6cfdc..0b1c04e5e2c50eea54d13b7b953700dcd74c399d 100644 (file)
@@ -477,6 +477,12 @@ static void __init set_vmcore_list_offsets(size_t elfsz,
        }
 }
 
+static void free_elfcorebuf(void)
+{
+       free_pages((unsigned long)elfcorebuf, get_order(elfcorebuf_sz_orig));
+       elfcorebuf = NULL;
+}
+
 static int __init parse_crash_elf64_headers(void)
 {
        int rc=0;
@@ -505,36 +511,31 @@ static int __init parse_crash_elf64_headers(void)
        }
 
        /* Read in all elf headers. */
-       elfcorebuf_sz_orig = sizeof(Elf64_Ehdr) + ehdr.e_phnum * sizeof(Elf64_Phdr);
+       elfcorebuf_sz_orig = sizeof(Elf64_Ehdr) +
+                               ehdr.e_phnum * sizeof(Elf64_Phdr);
        elfcorebuf_sz = elfcorebuf_sz_orig;
-       elfcorebuf = (void *) __get_free_pages(GFP_KERNEL | __GFP_ZERO,
-                                              get_order(elfcorebuf_sz_orig));
+       elfcorebuf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+                                             get_order(elfcorebuf_sz_orig));
        if (!elfcorebuf)
                return -ENOMEM;
        addr = elfcorehdr_addr;
        rc = read_from_oldmem(elfcorebuf, elfcorebuf_sz_orig, &addr, 0);
-       if (rc < 0) {
-               free_pages((unsigned long)elfcorebuf,
-                          get_order(elfcorebuf_sz_orig));
-               return rc;
-       }
+       if (rc < 0)
+               goto fail;
 
        /* Merge all PT_NOTE headers into one. */
        rc = merge_note_headers_elf64(elfcorebuf, &elfcorebuf_sz, &vmcore_list);
-       if (rc) {
-               free_pages((unsigned long)elfcorebuf,
-                          get_order(elfcorebuf_sz_orig));
-               return rc;
-       }
+       if (rc)
+               goto fail;
        rc = process_ptload_program_headers_elf64(elfcorebuf, elfcorebuf_sz,
                                                        &vmcore_list);
-       if (rc) {
-               free_pages((unsigned long)elfcorebuf,
-                          get_order(elfcorebuf_sz_orig));
-               return rc;
-       }
+       if (rc)
+               goto fail;
        set_vmcore_list_offsets(elfcorebuf_sz, &vmcore_list);
        return 0;
+fail:
+       free_elfcorebuf();
+       return rc;
 }
 
 static int __init parse_crash_elf32_headers(void)
@@ -567,34 +568,28 @@ static int __init parse_crash_elf32_headers(void)
        /* Read in all elf headers. */
        elfcorebuf_sz_orig = sizeof(Elf32_Ehdr) + ehdr.e_phnum * sizeof(Elf32_Phdr);
        elfcorebuf_sz = elfcorebuf_sz_orig;
-       elfcorebuf = (void *) __get_free_pages(GFP_KERNEL | __GFP_ZERO,
-                                              get_order(elfcorebuf_sz_orig));
+       elfcorebuf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+                                             get_order(elfcorebuf_sz_orig));
        if (!elfcorebuf)
                return -ENOMEM;
        addr = elfcorehdr_addr;
        rc = read_from_oldmem(elfcorebuf, elfcorebuf_sz_orig, &addr, 0);
-       if (rc < 0) {
-               free_pages((unsigned long)elfcorebuf,
-                          get_order(elfcorebuf_sz_orig));
-               return rc;
-       }
+       if (rc < 0)
+               goto fail;
 
        /* Merge all PT_NOTE headers into one. */
        rc = merge_note_headers_elf32(elfcorebuf, &elfcorebuf_sz, &vmcore_list);
-       if (rc) {
-               free_pages((unsigned long)elfcorebuf,
-                          get_order(elfcorebuf_sz_orig));
-               return rc;
-       }
+       if (rc)
+               goto fail;
        rc = process_ptload_program_headers_elf32(elfcorebuf, elfcorebuf_sz,
                                                                &vmcore_list);
-       if (rc) {
-               free_pages((unsigned long)elfcorebuf,
-                          get_order(elfcorebuf_sz_orig));
-               return rc;
-       }
+       if (rc)
+               goto fail;
        set_vmcore_list_offsets(elfcorebuf_sz, &vmcore_list);
        return 0;
+fail:
+       free_elfcorebuf();
+       return rc;
 }
 
 static int __init parse_crash_elf_headers(void)
@@ -672,8 +667,6 @@ void vmcore_cleanup(void)
                list_del(&m->list);
                kfree(m);
        }
-       free_pages((unsigned long)elfcorebuf,
-                  get_order(elfcorebuf_sz_orig));
-       elfcorebuf = NULL;
+       free_elfcorebuf();
 }
 EXPORT_SYMBOL_GPL(vmcore_cleanup);