Hi.

This patch cleans up the return code.

Thanks
Ken'ichi Ohmichi

diff -puN makedumpfile.org/makedumpfile.c makedumpfile/makedumpfile.c
--- makedumpfile.org/makedumpfile.c     2006-10-11 13:10:10.000000000 +0900
+++ makedumpfile/makedumpfile.c 2006-10-11 13:10:25.000000000 +0900
@@ -29,7 +29,7 @@ struct offset_table   offset_table;
 struct dwarf_info      dwarf_info;
 struct vm_table                *vt = 0;
 
-int retcd = COMPLETED; /* return code */
+int retcd = FAILED;    /* return code */
 
 void
 show_version()
@@ -493,12 +493,13 @@ int
 get_elf_info(struct DumpInfo *info)
 {
        int i, j;
-       int rc = FALSE;
        unsigned long tmp;
        Elf *elfd = NULL;
        GElf_Ehdr ehdr;
        GElf_Phdr load;
 
+       int ret = FALSE;
+
        lseek(info->fd_memory, 0, SEEK_SET);
        if (!(elfd = elf_begin(info->fd_memory, ELF_C_READ, NULL))) {
                ERRMSG("Can't get first elf header of %s.\n",
@@ -571,12 +572,12 @@ get_elf_info(struct DumpInfo *info)
        if (info->flag_exclude_free)
                info->len_3rd_bitmap = info->len_bitmap / 2;
 
-       rc = TRUE;
+       ret = TRUE;
 out:
        if (elfd != NULL)
                elf_end(elfd);
-       
-       return rc;
+
+       return ret;
 }
 
 unsigned long
@@ -803,12 +804,11 @@ get_debug_info(void)
        Dwarf_Die cu_die;
        uint8_t address_size;
        uint8_t offset_size;
-       int rc;
        uint32_t found_map = 0;
        char *name = NULL;
        size_t shstrndx;
 
-       rc = FALSE;
+       int ret = FALSE;
 
        lseek(dwarf_info.vmlinux_fd, 0, SEEK_SET);
        if (!(elfd = elf_begin(dwarf_info.vmlinux_fd, ELF_C_READ_MMAP, NULL))) {
@@ -848,7 +848,7 @@ get_debug_info(void)
                if (found_map & DWARF_INFO_FOUND_STRUCT)
                        break;
        }
-       rc = TRUE;
+       ret = TRUE;
 out:
        if (dwarfd != NULL)
                dwarf_end(dwarfd);
@@ -856,7 +856,7 @@ out:
                elf_end(elfd);
        dwarf_info.status = found_map;
 
-       return rc;
+       return ret;
 }
 
 /*
@@ -1310,7 +1310,9 @@ get_mm_sparsemem(struct DumpInfo *info)
        unsigned int section_nr, mem_section_size, num_section;
        unsigned long pfn_start, pfn_end;
        unsigned long addr_section, addr_mem_map;
-       unsigned long *mem_sec;
+       unsigned long *mem_sec = NULL;
+
+       int ret = FALSE;
 
        /*
         * Get the address of the symbol "mem_section".
@@ -1330,14 +1332,14 @@ get_mm_sparsemem(struct DumpInfo *info)
        }
        if (!readmem(info, SYMBOL(mem_section), mem_sec, mem_section_size)) {
                ERRMSG("Can't get the address of mem_section.\n");
-               return FALSE;
+               goto out;
        }
        info->num_mem_map = num_section;
        if ((info->mem_map_data = (struct mem_map_data *)
            malloc(sizeof(struct mem_map_data)*info->num_mem_map)) == NULL) {
                ERRMSG("Can't allocate memory for the mem_map_data. %s\n",
                    strerror(errno));
-               return FALSE;
+               goto out;
        }
        for (section_nr = 0; section_nr < num_section; section_nr++) {
                addr_section = nr_to_section(info, section_nr, mem_sec);
@@ -1351,8 +1353,12 @@ get_mm_sparsemem(struct DumpInfo *info)
                        pfn_end = info->max_mapnr;
                dump_mem_map(info, pfn_start, pfn_end, addr_mem_map, 
section_nr);
        }
-       free(mem_sec);
-       return TRUE;
+       ret = TRUE;
+out:
+       if (mem_sec != NULL)
+               free(mem_sec);
+
+       return ret;
 }
 
 int
@@ -2079,6 +2085,8 @@ create_dump_bitmap(struct DumpInfo *info
        off_t offset_page;
        const off_t failed = (off_t)-1;
 
+       int ret = FALSE;
+
        offset_page  = info->offset_load_memory;
 
        bm1.fd         = info->fd_bitmap;
@@ -2275,14 +2283,7 @@ create_dump_bitmap(struct DumpInfo *info
                if (!create_contig_bitmap(info))
                        goto out;
 
-       if (page_cache != NULL)
-               free(page_cache);
-       free(buf);
-       free(bm1.buf);
-       free(bm2.buf);
-       if (bm3.buf != NULL)
-               free(bm3.buf);
-       return TRUE;
+       ret = TRUE;
 out:
        if (page_cache != NULL)
                free(page_cache);
@@ -2294,7 +2295,8 @@ out:
                free(bm2.buf);
        if (bm3.buf != NULL)
                free(bm3.buf);
-       return FALSE;
+
+       return ret;
 }
 
 int
@@ -2317,6 +2319,8 @@ write_elf_header(struct DumpInfo *info)
        struct dump_bitmap bitmap2;
        const off_t failed = (off_t)-1;
 
+       int ret = FALSE;
+
        size_hdr_memory = info->offset_load_memory;
 
        bitmap2.fd        = info->fd_bitmap;
@@ -2563,14 +2567,7 @@ write_elf_header(struct DumpInfo *info)
                goto out;
        }
 
-       free(bitmap2.buf);
-       free(header_memory);
-       if (info->flag_elf & ELF32)
-               free(load32);
-       else
-               free(load64);
-       free(buf);
-       return TRUE;
+       ret = TRUE;
 out:
        if (bitmap2.buf != NULL)
                free(bitmap2.buf);
@@ -2582,7 +2579,8 @@ out:
                free(load64);
        if (buf != NULL)
                free(buf);
-       return FALSE;
+
+       return ret;
 }
 
 int
@@ -2685,6 +2683,8 @@ write_pages(struct DumpInfo *info)
        struct dump_bitmap bitmap1, bitmap2;
        const off_t failed = (off_t)-1;
 
+       int ret = FALSE;
+
        bm2.fd         = info->fd_bitmap;
        bm2.file_name  = info->name_bitmap;
        bm2.cache_size = BUFSIZE_BITMAP;
@@ -2890,14 +2890,7 @@ write_pages(struct DumpInfo *info)
         */
        print_progress(info->max_mapnr, info->max_mapnr);
 
-       free(buf);
-       free(buf_out);
-       free(bm2.buf);
-       free(pdesc.buf);
-       free(pdata.buf);
-       free(bitmap1.buf);
-       free(bitmap2.buf);
-       return TRUE;
+       ret = TRUE;
 out:
        if (buf != NULL)
                free(buf);
@@ -2913,7 +2906,8 @@ out:
                free(bitmap1.buf);
        if (bitmap2.buf != NULL)
                free(bitmap2.buf);
-       return FALSE;
+
+       return ret;
 }
 
 int write_dump_bitmap(struct DumpInfo *info)
@@ -2922,6 +2916,8 @@ int write_dump_bitmap(struct DumpInfo *i
        long buf_size;
        const off_t failed = (off_t)-1;
 
+       int ret = FALSE;
+
        if (info->flag_elf_dumpfile)
                return TRUE;
 
@@ -2960,12 +2956,12 @@ int write_dump_bitmap(struct DumpInfo *i
                }
                buf_size -= BUFSIZE_BITMAP;
        }
-       free(bm.buf);
-       return TRUE;
+       ret = TRUE;
 out:
        if (bm.buf != NULL)
                free(bm.buf);
-       return FALSE;
+
+       return ret;
 }
 
 void
@@ -2973,13 +2969,13 @@ close_config_file(struct DumpInfo *info)
 {
        if(fclose(info->file_configfile) < 0)
                ERRMSG("Can't close the config file(%s). %s\n",
-               info->name_configfile, strerror(errno));
+                   info->name_configfile, strerror(errno));
 }
 
 void
 close_dump_memory(struct DumpInfo *info)
 {
-       if (close(info->fd_memory) < 0)
+       if ((info->fd_memory = close(info->fd_memory)) < 0)
                ERRMSG("Can't close the dump memory(%s). %s\n",
                    info->name_memory, strerror(errno));
 }
@@ -2987,7 +2983,7 @@ close_dump_memory(struct DumpInfo *info)
 void
 close_dump_file(struct DumpInfo *info)
 {
-       if (close(info->fd_dumpfile) < 0)
+       if ((info->fd_dumpfile = close(info->fd_dumpfile)) < 0)
                ERRMSG("Can't close the dump file(%s). %s\n",
                    info->name_dumpfile, strerror(errno));
 }
@@ -2995,7 +2991,7 @@ close_dump_file(struct DumpInfo *info)
 void
 close_3rd_bitmap(struct DumpInfo *info)
 {
-       if (close(info->fd_3rd_bitmap) < 0)
+       if ((info->fd_3rd_bitmap = close(info->fd_3rd_bitmap)) < 0)
                ERRMSG("Can't close the bitmap file(%s). %s\n",
                    info->name_3rd_bitmap, strerror(errno));
        free(info->name_3rd_bitmap);
@@ -3004,7 +3000,7 @@ close_3rd_bitmap(struct DumpInfo *info)
 void
 close_dump_bitmap(struct DumpInfo *info)
 {
-       if (close(info->fd_bitmap) < 0)
+       if ((info->fd_bitmap = close(info->fd_bitmap)) < 0)
                ERRMSG("Can't close the bitmap file(%s). %s\n",
                    info->name_bitmap, strerror(errno));
        free(info->name_bitmap);
@@ -3220,18 +3216,14 @@ main(int argc, char *argv[])
                MSG("\n");
                MSG("The dumpfile is saved to %s.\n", info->name_dumpfile);
        }
-       MSG("makedumpfile Completed.\n");
-       if (!info->flag_generate_config) {
-               free(info->pt_load_segments);
-               free(info->mem_map_data);
-       }
-       free(info->dump_header);
-       free(info);
-       return COMPLETED;
-
+       retcd = COMPLETED;
 out:
        ERRMSG("\n");
-       ERRMSG("makedumpfile Failed.\n");
+       if (retcd == COMPLETED)
+               MSG("makedumpfile Completed.\n");
+       else
+               ERRMSG("makedumpfile Failed.\n");
+
        if (info->fd_memory)
                close(info->fd_memory);
        if (info->fd_dumpfile)
@@ -3248,8 +3240,6 @@ out:
                free(info->dump_header);
        if (info != NULL)
                free(info);
-       if (retcd != COMPLETED)
-               return retcd;
-       else
-               return FAILED;
+
+       return retcd;
 }
_
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot

Reply via email to