Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5217076ybi; Tue, 11 Jun 2019 22:00:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh8I5FoqQto7rzZq37z32pE+T9AxGhsB5XGr4RSr7mwKrL5E01mOgt7O+9Z8HpqTrHRg+I X-Received: by 2002:a63:5c15:: with SMTP id q21mr9447875pgb.248.1560315643102; Tue, 11 Jun 2019 22:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560315643; cv=none; d=google.com; s=arc-20160816; b=ayxGH/TKud6gKuW67rlFN6ZJcb7lVS8zFBRsLX4fDyO4g3kIsse4+VPPJCU7YwjLw8 3+GiiFEy3X4lYaZ0MWENMh6JgMKBtBxQPn7WuNOQZmAZSVgOSOHLHypDkYzghNDrwSxR Bv4mYpW7d2iLM18mjv9jdErg0wDBo9nsWT0fhFLjX23lED/ffs+IvKsbvf9bfqY5I6UB Jlv1/i0pH8/93h9pKJZDNS0/Vl7npLVgV+gGKKpuD59Mo9Aj/ymi6jpnZDX5TTaj7d0o SEl7bWSgVLdk6WNgwGIeHxD1vbPKPU5lfCdHIOiY1sMcIkMr5/V0Dxh5VbiNQfOvWVyF f5NQ== 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=meKCb65VRFbTMf7zCh7PF+5QtyRrKWk4ptCT/xtWjVA=; b=en6ADDid4cx/edzBnadfmdliXnVHB/D7pHAw4rFz2WAvGiU6e5w9G9DsPe46BH/OW7 CV9iYVMTYXbRT4tnseyVKXRGst6MtkUf2KPnxNYMNkwyVg9av9KG3iF0tnfc/9StRH1R +W1aVEMcB48EYauaKYFNe4F2luq1AHMgk1eB8deut4RKgstKj/x22JOPkhs2lHgjJIKy 7ClOeoYMkOsyfteQYsLQPTrUqdF+NmEu4g6PPsEjnf2rboJd7VFh9g4MEh80LYTHSBQd v0jtwn8C98nCJb5qBgwYucfrJS1rICBd0N22fCfPpOEP4ueHjyJrxCHr1xXyT/eWllEM 5hVw== 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 g190si13905702pgc.1.2019.06.11.22.00.26; Tue, 11 Jun 2019 22:00:43 -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 S2436870AbfFKWWY (ORCPT + 99 others); Tue, 11 Jun 2019 18:22:24 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:3288 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436820AbfFKWWS (ORCPT ); Tue, 11 Jun 2019 18:22:18 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Tue, 11 Jun 2019 15:22:09 -0700 Received: from rlwimi.localdomain (unknown [10.129.220.121]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 297B441BAB; Tue, 11 Jun 2019 15:22:16 -0700 (PDT) From: Matt Helsley To: LKML CC: Ingo Molnar , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt , Matt Helsley Subject: [PATCH v2 07/13] recordmcount: Remove redundant cleanup() calls Date: Tue, 11 Jun 2019 15:21:49 -0700 Message-ID: <1a1bc8fc3b04c4d42aff0de5b7e78ebb8a9c4919.1560285597.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-001.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 9ae975ccf2dc..111419c282d3 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 3198459f7431..b7348f1af758 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -468,7 +468,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; } @@ -487,7 +486,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