Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1078891ybm; Wed, 22 May 2019 17:05:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzITC0XCgpRsBDdI4mWuEqqhLL6vkswan1SoL7hpR7alqOPkh1ph4oYgppOMe5hFWhN1gus X-Received: by 2002:a63:2c14:: with SMTP id s20mr75367551pgs.182.1558569927411; Wed, 22 May 2019 17:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558569927; cv=none; d=google.com; s=arc-20160816; b=xr54c4Tr36My5kBxFfpR9zX0yGeOBYcom1w+I61lqrma6MzisU+5XmT0iKX/d8wmI/ ZhtUwjTPKhJXSnpMa8S/m85gn4uO3Oaq/JBQSGplnzmLlxCPyCcpV7S/koWs7xtoepcu jizmlJf6EOihpr5aC1AR9zKdTLt/henZXH+y0sJILcRE8xAnZwpxmGe3hbmw490iB0Uq gGiqLnDXZ2yLsSWqWaBz9Twq2wkkz47qEQYWefyi+KAu2YAD9+8yfanQdleNYndPXPDL 95LTqNSUMc2BHS6G+4Ai0PRvwTxo25vZIVbHgora6X6BSHOLBphL+Bu/Z020mt5/npN/ cllA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LuDOFI7EY6jJVm4d+8v/vHEwmAS9GFD/B2VKGFt6lYY=; b=aBJR41Ecpj/mEbCZvN82BHFdbtk2A/KbddmmOAC+2yFXg4VQGB6X/bfroMZg0FY2pl zhBvPKQonq/x26NXUGZ3/C/0a/rUQUO091Mw3eGHf6OwieuqyEa3XuuBysX6YdNlvazm tuRsg3ouM7/4PjB+Nd1FbF5j3p2E9xrwq4ptuWlLntycGiEawYRQzwATx0AdTxfIT7LI iSRlCRQoRd7bzdsJVCUWzggBIIgiDcFof40CApDnItQ7Jv/z3P7d+NOtiL52JQdCjKoL a0gpD2NpSs/OIxCWo+aZkWqpAyd3ezMvQUHD5rrQ9zFMhZ6OR2bjTbEKjoBxC+9tdECK 1gSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j24si18402065pll.388.2019.05.22.17.05.11; Wed, 22 May 2019 17:05:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729697AbfEWAED (ORCPT + 99 others); Wed, 22 May 2019 20:04:03 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:9702 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726890AbfEWAD5 (ORCPT ); Wed, 22 May 2019 20:03:57 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 22 May 2019 17:03:49 -0700 Received: from rlwimi.localdomain (unknown [10.129.221.32]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 87311B2067; Wed, 22 May 2019 20:03:56 -0400 (EDT) From: Matt Helsley To: LKML CC: Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Matt Helsley Subject: [RFC][PATCH 07/13] recordmcount: Remove redundant cleanup() calls Date: Wed, 22 May 2019 17:03:30 -0700 Message-ID: <29af02c412faf7507561dc25d58eb73740da1c67.1558569448.git.mhelsley@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Received-SPF: None (EX13-EDG-OU-002.vmware.com: mhelsley@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Redundant cleanup calls were introduced when transitioning from the old error/success handling via setjmp/longjmp -- the longjmp ensured the cleanup() call only happened once but replacing the success_file()/fail_file() calls with cleanup() meant that multiple cleanup() calls can happen as we return from function calls. In do_file(), looking just before and after the "goto out" jumps we can see that multiple cleanups() are being performed. We remove cleanup() calls from the nested functions because it makes the code easier to review -- the resources being cleaned up are generally allocated and initialized in the callers so freeing them there makes more sense. Other redundant cleanup() calls: mmap_file() is only called from do_file() and, if mmap_file() fails, then we goto out and do cleanup() there too. write_file() is only called from do_file() and do_file() calls cleanup() unconditionally after returning from write_file() therefore the cleanup() calls in write_file() are not necessary. find_secsym_ndx(), called from do_func()'s for-loop, when we are cleaning up here it's obvious that we break out of the loop and do another cleanup(). __has_rel_mcount() is called from two parts of do_func() and calls cleanup(). In theory we move them into do_func(), however these in turn prove redundant so another simplification step removes them as well. Signed-off-by: Matt Helsley --- scripts/recordmcount.c | 13 ------------- scripts/recordmcount.h | 2 -- 2 files changed, 15 deletions(-) diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c index 3301769254ec..1c8b38c0d7fe 100644 --- a/scripts/recordmcount.c +++ b/scripts/recordmcount.c @@ -258,17 +258,14 @@ static void *mmap_file(char const *fname) fd_map = open(fname, O_RDONLY); if (fd_map < 0) { perror(fname); - cleanup(); return NULL; } if (fstat(fd_map, &sb) < 0) { perror(fname); - cleanup(); goto out; } if (!S_ISREG(sb.st_mode)) { fprintf(stderr, "not a regular file: %s\n", fname); - cleanup(); goto out; } file_map = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, @@ -314,13 +311,11 @@ static int write_file(const char *fname) fd_map = open(tmp_file, O_WRONLY | O_TRUNC | O_CREAT, sb.st_mode); if (fd_map < 0) { perror(fname); - cleanup(); return -1; } n = write(fd_map, file_map, sb.st_size); if (n != sb.st_size) { perror("write"); - cleanup(); close(fd_map); return -1; } @@ -328,7 +323,6 @@ static int write_file(const char *fname) n = write(fd_map, file_append, file_append_size); if (n != file_append_size) { perror("write"); - cleanup(); close(fd_map); return -1; } @@ -336,7 +330,6 @@ static int write_file(const char *fname) close(fd_map); if (rename(tmp_file, fname) < 0) { perror(fname); - cleanup(); return -1; } return 0; @@ -458,7 +451,6 @@ static int do_file(char const *const fname) default: fprintf(stderr, "unrecognized ELF data encoding %d: %s\n", ehdr->e_ident[EI_DATA], fname); - cleanup(); goto out; case ELFDATA2LSB: if (*(unsigned char const *)&endian != 1) { @@ -491,7 +483,6 @@ static int do_file(char const *const fname) w2(ehdr->e_type) != ET_REL || ehdr->e_ident[EI_VERSION] != EV_CURRENT) { fprintf(stderr, "unrecognized ET_REL file %s\n", fname); - cleanup(); goto out; } @@ -500,7 +491,6 @@ static int do_file(char const *const fname) default: fprintf(stderr, "unrecognized e_machine %u %s\n", w2(ehdr->e_machine), fname); - cleanup(); goto out; case EM_386: reltype = R_386_32; @@ -544,14 +534,12 @@ static int do_file(char const *const fname) default: fprintf(stderr, "unrecognized ELF class %d %s\n", ehdr->e_ident[EI_CLASS], fname); - cleanup(); goto out; case ELFCLASS32: if (w2(ehdr->e_ehsize) != sizeof(Elf32_Ehdr) || w2(ehdr->e_shentsize) != sizeof(Elf32_Shdr)) { fprintf(stderr, "unrecognized ET_REL file: %s\n", fname); - cleanup(); goto out; } if (w2(ehdr->e_machine) == EM_MIPS) { @@ -567,7 +555,6 @@ static int do_file(char const *const fname) || w2(ghdr->e_shentsize) != sizeof(Elf64_Shdr)) { fprintf(stderr, "unrecognized ET_REL file: %s\n", fname); - cleanup(); goto out; } if (w2(ghdr->e_machine) == EM_S390) { diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h index 0ce8e0aaa5ec..ffab6bb96852 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -469,7 +469,6 @@ static unsigned find_secsym_ndx(unsigned const txtndx, } fprintf(stderr, "Cannot find symbol for section %u: %s.\n", txtndx, txtname); - cleanup(); return missing_sym; } @@ -488,7 +487,6 @@ static char const * __has_rel_mcount(Elf_Shdr const *const relhdr, /* reltype */ if (strcmp("__mcount_loc", txtname) == 0) { fprintf(stderr, "warning: __mcount_loc already exists: %s\n", fname); - cleanup(); return already_has_rel_mcount; } if (w(txthdr->sh_type) != SHT_PROGBITS || -- 2.20.1