Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1615503pxb; Mon, 11 Oct 2021 09:32:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRlwsja/OGsVZwG4f4Vsq+JqjXmNBgVH4yXhY4y9SWRGGP1xQPVuhojfe+R9M4/J7dBwz5 X-Received: by 2002:a17:90b:3a85:: with SMTP id om5mr31633743pjb.115.1633969941345; Mon, 11 Oct 2021 09:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969941; cv=none; d=google.com; s=arc-20160816; b=v0LlxGwPPLljQa5GNH3MmMrtW0rLRofMa0migAk99lpYqQOvu21XrISQMh9jwrCmiZ 3BgcDQzFoB7D7tqWbLw3TPJvHExuG8BlOqxsjbgD6JEejGdwKE72Rzkljc+XFWGj6Qjh MibYrKM8Uh4s/2/Gcu7po8hLh9hPGEHMRnktLVha+C2RPwkIzK70wgpvhhlLjoDfL3mf F8jNlFAgOUdc2QsMAIwSPULuX5YcF1hIuj44DK1YTH4OJbzzVQ+G0rUbaMt7T1f2h8hC 0xCSzVGiijaRrXFowtxllONcfN2g9YOL0b6koEXgmqlUa4tVwuP8vHcLhHMMrbEaWdKE tEjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GCW0Lvg+aqfaQo2FrV54O2N69Obq+1o2+HKTwIDHxsM=; b=W0CfFAnJ2/pHMx7gql2r4Tr8usj9htkoMwLtaKGA2jOZDuYq5lU0+OLgNM9zbDMf0C 8665uEeDIKa1F5AIHYA4zBQC8hMX2kCco86Ztvcfdntte/TvQQXnEns4DHpfUVbJ38We I+z/6l4wiSt0oIDD77s+MAEYDEi5/eaZjpEO4P5bIAQsyzyGFzgl5vT47gDtpmf3UqKR 1ezPTo9SS9DR4VbG4T7GD0pE4KDBW/VpiCJ+mWuHXleFb8bFU/Agz7qCE6+82Iuky5uK 4TnNfz0WLEzLbJVOp5fH+r+SRH2XHU4Cb2eekyb4iNNFB8asqL4fi+X4FTNUX4xFrjzk mg4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JS3Q26TU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t9si9015pjd.21.2021.10.11.09.32.07; Mon, 11 Oct 2021 09:32:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JS3Q26TU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238495AbhJKN6p (ORCPT + 99 others); Mon, 11 Oct 2021 09:58:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237070AbhJKN43 (ORCPT ); Mon, 11 Oct 2021 09:56:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A4C826112D; Mon, 11 Oct 2021 13:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960407; bh=SzGh1Rg94Y+qKrv3/B+mC5SIKGHpGzNVCR/AXa86xLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JS3Q26TUMwC9zc60vUYkPqthcVQ21jERp51Fu2PfOb00Cr5aMNFkN2GQnDNjikvc0 7Bl0vOGn7JGGo+JJ0gKo/h/5Wotya8BAxmyIpvBa6JpvYx7i2t+nQa52GnGsFNRZC0 Kiflo7mBRxYhChnRfNeYbSY6iD2Sd8LDYAy6T7mw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Kajol Jain , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.10 52/83] perf jevents: Tidy error handling Date: Mon, 11 Oct 2021 15:46:12 +0200 Message-Id: <20211011134510.196249945@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry [ Upstream commit fa1b41a74d1136cbdd6960f36d7b9c7aa35c8139 ] There is much duplication in the error handling for directory transvering for prcessing JSONs. Factor out the common code to tidy a bit. Signed-off-by: John Garry Reviewed-By: Kajol Jain Link: https://lore.kernel.org/r/1603364547-197086-2-git-send-email-john.garry@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/pmu-events/jevents.c | 83 ++++++++++++++------------------- 1 file changed, 35 insertions(+), 48 deletions(-) diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c index dcfdf6a322dc..c679a79aef51 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -1100,12 +1100,13 @@ static int process_one_file(const char *fpath, const struct stat *sb, */ int main(int argc, char *argv[]) { - int rc, ret = 0; + int rc, ret = 0, empty_map = 0; int maxfds; char ldirname[PATH_MAX]; const char *arch; const char *output_file; const char *start_dirname; + char *err_string_ext = ""; struct stat stbuf; prog = basename(argv[0]); @@ -1133,7 +1134,8 @@ int main(int argc, char *argv[]) /* If architecture does not have any event lists, bail out */ if (stat(ldirname, &stbuf) < 0) { pr_info("%s: Arch %s has no PMU event lists\n", prog, arch); - goto empty_map; + empty_map = 1; + goto err_close_eventsfp; } /* Include pmu-events.h first */ @@ -1150,75 +1152,60 @@ int main(int argc, char *argv[]) */ maxfds = get_maxfds(); - mapfile = NULL; rc = nftw(ldirname, preprocess_arch_std_files, maxfds, 0); - if (rc && verbose) { - pr_info("%s: Error preprocessing arch standard files %s\n", - prog, ldirname); - goto empty_map; - } else if (rc < 0) { - /* Make build fail */ - fclose(eventsfp); - free_arch_std_events(); - return 1; - } else if (rc) { - goto empty_map; - } + if (rc) + goto err_processing_std_arch_event_dir; rc = nftw(ldirname, process_one_file, maxfds, 0); - if (rc && verbose) { - pr_info("%s: Error walking file tree %s\n", prog, ldirname); - goto empty_map; - } else if (rc < 0) { - /* Make build fail */ - fclose(eventsfp); - free_arch_std_events(); - ret = 1; - goto out_free_mapfile; - } else if (rc) { - goto empty_map; - } + if (rc) + goto err_processing_dir; sprintf(ldirname, "%s/test", start_dirname); rc = nftw(ldirname, process_one_file, maxfds, 0); - if (rc && verbose) { - pr_info("%s: Error walking file tree %s rc=%d for test\n", - prog, ldirname, rc); - goto empty_map; - } else if (rc < 0) { - /* Make build fail */ - free_arch_std_events(); - ret = 1; - goto out_free_mapfile; - } else if (rc) { - goto empty_map; - } + if (rc) + goto err_processing_dir; if (close_table) print_events_table_suffix(eventsfp); if (!mapfile) { pr_info("%s: No CPU->JSON mapping?\n", prog); - goto empty_map; + empty_map = 1; + goto err_close_eventsfp; } - if (process_mapfile(eventsfp, mapfile)) { + rc = process_mapfile(eventsfp, mapfile); + fclose(eventsfp); + if (rc) { pr_info("%s: Error processing mapfile %s\n", prog, mapfile); /* Make build fail */ - fclose(eventsfp); - free_arch_std_events(); ret = 1; + goto err_out; } + free_arch_std_events(); + free(mapfile); + return 0; - goto out_free_mapfile; - -empty_map: +err_processing_std_arch_event_dir: + err_string_ext = " for std arch event"; +err_processing_dir: + if (verbose) { + pr_info("%s: Error walking file tree %s%s\n", prog, ldirname, + err_string_ext); + empty_map = 1; + } else if (rc < 0) { + ret = 1; + } else { + empty_map = 1; + } +err_close_eventsfp: fclose(eventsfp); - create_empty_mapping(output_file); + if (empty_map) + create_empty_mapping(output_file); +err_out: free_arch_std_events(); -out_free_mapfile: free(mapfile); return ret; } -- 2.33.0