]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
segment_report_module: Remove nested finish() function
authorTimm Bäder <tbaeder@redhat.com>
Thu, 12 Nov 2020 15:04:01 +0000 (16:04 +0100)
committerMark Wielaard <mark@klomp.org>
Thu, 19 Nov 2020 11:16:45 +0000 (12:16 +0100)
This works just as well with a goto-out style label.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c

index 791cb8700639dcbefd413b2af061178f8f2872e6..59ef37aa188def734ba0a5fd89eab636e0f233c2 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-12  Timm Bäder <tbaeder@redhat.com>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Remove
+       finish function, replace with goto out.
+
 2020-11-12  Timm Bäder <tbaeder@redhat.com>
 
        * dwfl_segment_report_module.c (dwfl_segment_report_module): Declare
index dd3fdb9e563280ec3b54f65b2f6109b72f69cc74..c7725002f8e04a5e3f9ff67256b1488203caac46 100644 (file)
@@ -282,21 +282,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
      here so we can always safely free it.  */
   void *phdrsp = NULL;
 
-  inline int finish (void)
-  {
-    free (phdrsp);
-    release_buffer (&buffer, &buffer_available);
-    if (elf != NULL)
-      elf_end (elf);
-    if (fd != -1)
-      close (fd);
-    return ndx;
-  }
-
   if (segment_read (ndx, &buffer, &buffer_available,
                    start, sizeof (Elf64_Ehdr))
       || memcmp (buffer, ELFMAG, SELFMAG) != 0)
-    return finish ();
+    goto out;
 
   inline bool read_portion (void **data, size_t *data_size,
                            GElf_Addr vaddr, size_t filesz)
@@ -363,13 +352,13 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
     case ELFCLASS32:
       xlatefrom.d_size = sizeof (Elf32_Ehdr);
       if (elf32_xlatetom (&xlateto, &xlatefrom, ei_data) == NULL)
-       return finish ();
+       goto out;
       e_type = ehdr.e32.e_type;
       phoff = ehdr.e32.e_phoff;
       phnum = ehdr.e32.e_phnum;
       phentsize = ehdr.e32.e_phentsize;
       if (phentsize != sizeof (Elf32_Phdr))
-       return finish ();
+       goto out;
       /* NOTE if the number of sections is > 0xff00 then e_shnum
         is zero and the actual number would come from the section
         zero sh_size field. We ignore this here because getting shdrs
@@ -381,19 +370,19 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
     case ELFCLASS64:
       xlatefrom.d_size = sizeof (Elf64_Ehdr);
       if (elf64_xlatetom (&xlateto, &xlatefrom, ei_data) == NULL)
-       return finish ();
+       goto out;
       e_type = ehdr.e64.e_type;
       phoff = ehdr.e64.e_phoff;
       phnum = ehdr.e64.e_phnum;
       phentsize = ehdr.e64.e_phentsize;
       if (phentsize != sizeof (Elf64_Phdr))
-       return finish ();
+       goto out;
       /* See the NOTE above for shdrs_end and ehdr.e32.e_shnum.  */
       shdrs_end = ehdr.e64.e_shoff + ehdr.e64.e_shnum * ehdr.e64.e_shentsize;
       break;
 
     default:
-      return finish ();
+      goto out;
     }
 
   /* The file header tells where to find the program headers.
@@ -401,7 +390,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
      Without them, we don't have a module to report.  */
 
   if (phnum == 0)
-    return finish ();
+    goto out;
 
   xlatefrom.d_type = xlateto.d_type = ELF_T_PHDR;
   xlatefrom.d_size = phnum * phentsize;
@@ -410,7 +399,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   size_t ph_buffer_size = 0;
   if (read_portion (&ph_buffer, &ph_buffer_size,
                    start + phoff, xlatefrom.d_size))
-    return finish ();
+    goto out;
 
   /* ph_buffer_size will be zero if we got everything from the initial
      buffer, otherwise it will be the size of the new buffer that
@@ -423,11 +412,11 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   bool class32 = ei_class == ELFCLASS32;
   size_t phdr_size = class32 ? sizeof (Elf32_Phdr) : sizeof (Elf64_Phdr);
   if (unlikely (phnum > SIZE_MAX / phdr_size))
-    return finish ();
+    goto out;
   const size_t phdrsp_bytes = phnum * phdr_size;
   phdrsp = malloc (phdrsp_bytes);
   if (unlikely (phdrsp == NULL))
-    return finish ();
+    goto out;
 
   xlateto.d_buf = phdrsp;
   xlateto.d_size = phdrsp_bytes;
@@ -638,7 +627,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   if (unlikely (!found_bias))
     {
       free (build_id);
-      return finish ();
+      goto out;
     }
 
   /* Now we know enough to report a module for sure: its bounds.  */
@@ -709,7 +698,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       if (skip_this_module)
        {
          free (build_id);
-         return finish ();
+         goto out;
        }
     }
 
@@ -799,7 +788,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       Elf32_Dyn *d32 = dyns;
       Elf64_Dyn *d64 = dyns;
       if (unlikely (dyns == NULL))
-       return finish ();
+       goto out;
 
       xlatefrom.d_type = xlateto.d_type = ELF_T_DYN;
       xlatefrom.d_buf = (void *) dyn_data;
@@ -889,7 +878,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   if (unlikely (mod == NULL))
     {
       ndx = -1;
-      return finish ();
+      goto out;
     }
 
   /* We have reported the module.  Now let the caller decide whether we
@@ -913,7 +902,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
 
       void *contents = calloc (1, file_trimmed_end);
       if (unlikely (contents == NULL))
-       return finish ();
+       goto out;
 
       inline void final_read (size_t offset, GElf_Addr vaddr, size_t size)
       {
@@ -975,5 +964,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       mod->main_bias = bias;
     }
 
-  return finish ();
+out:
+  free (phdrsp);
+  release_buffer (&buffer, &buffer_available);
+  if (elf != NULL)
+    elf_end (elf);
+  if (fd != -1)
+    close (fd);
+  return ndx;
 }