All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, John Garry <john.garry@huawei.com>,
	Kajol Jain <kjain@linux.ibm.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 52/83] perf jevents: Tidy error handling
Date: Mon, 11 Oct 2021 15:46:12 +0200	[thread overview]
Message-ID: <20211011134510.196249945@linuxfoundation.org> (raw)
In-Reply-To: <20211011134508.362906295@linuxfoundation.org>

From: John Garry <john.garry@huawei.com>

[ 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 <john.garry@huawei.com>
Reviewed-By: Kajol Jain<kjain@linux.ibm.com>
Link: https://lore.kernel.org/r/1603364547-197086-2-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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




  parent reply	other threads:[~2021-10-11 13:57 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 13:45 [PATCH 5.10 00/83] 5.10.73-rc1 review Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 01/83] Partially revert "usb: Kconfig: using select for USB_COMMON dependency" Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 02/83] usb: chipidea: ci_hdrc_imx: Also search for phys phandle Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 03/83] USB: cdc-acm: fix racy tty buffer accesses Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 04/83] USB: cdc-acm: fix break reporting Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 05/83] usb: typec: tcpm: handle SRC_STARTUP state if cc changes Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 06/83] drm/nouveau/kms/tu102-: delay enabling cursor until after assign_windows Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 07/83] xen/privcmd: fix error handling in mmap-resource processing Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 08/83] mmc: meson-gx: do not use memcpy_to/fromio for dram-access-quirk Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 09/83] mmc: sdhci-of-at91: wait for calibration done before proceed Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 10/83] mmc: sdhci-of-at91: replace while loop with read_poll_timeout Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 11/83] ovl: fix missing negative dentry check in ovl_rename() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 12/83] ovl: fix IOCB_DIRECT if underlying fs doesnt support direct IO Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 13/83] nfsd: fix error handling of register_pernet_subsys() in init_nfsd() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 14/83] nfsd4: Handle the NFSv4 READDIR dircount hint being zero Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 15/83] SUNRPC: fix sign error causing rpcsec_gss drops Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 16/83] xen/balloon: fix cancelled balloon action Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 17/83] ARM: dts: omap3430-sdp: Fix NAND device node Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 18/83] ARM: dts: imx6dl-yapp4: Fix lp5562 LED driver probe Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 19/83] ARM: dts: qcom: apq8064: use compatible which contains chipid Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 20/83] riscv: Flush current cpu icache before other cpus Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 21/83] bus: ti-sysc: Add break in switch statement in sysc_init_soc() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 22/83] soc: qcom: socinfo: Fixed argument passed to platform_set_data() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 23/83] ARM: dts: qcom: apq8064: Use 27MHz PXO clock as DSI PLL reference Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 24/83] ARM: at91: pm: do not panic if ram controllers are not enabled Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 25/83] soc: qcom: mdt_loader: Drop PT_LOAD check on hash segment Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 26/83] ARM: dts: imx: Add missing pinctrl-names for panel on M53Menlo Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 27/83] ARM: dts: imx: Fix USB host power regulator polarity " Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 28/83] ARM: dts: imx6qdl-pico: Fix Ethernet support Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 29/83] PCI: hv: Fix sleep while in non-sleep context when removing child devices from the bus Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 30/83] ath5k: fix building with LEDS=m Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 31/83] arm64: dts: qcom: pm8150: use qcom,pm8998-pon binding Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 32/83] xtensa: use CONFIG_USE_OF instead of CONFIG_OF Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 33/83] xtensa: call irqchip_init only when CONFIG_USE_OF is selected Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 34/83] iwlwifi: pcie: add configuration of a Wi-Fi adapter on Dell XPS 15 Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 35/83] bpf, arm: Fix register clobbering in div/mod implementation Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 36/83] soc: ti: omap-prm: Fix external abort for am335x pruss Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 37/83] bpf: Fix integer overflow in prealloc_elems_and_freelist() Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 38/83] net/mlx5e: IPSEC RX, enable checksum complete Greg Kroah-Hartman
2021-10-11 13:45 ` [PATCH 5.10 39/83] net/mlx5: E-Switch, Fix double allocation of acl flow counter Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 40/83] phy: mdio: fix memory leak Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 41/83] net_sched: fix NULL deref in fifo_set_limit() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 42/83] powerpc/fsl/dts: Fix phy-connection-type for fm1mac3 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 43/83] ptp_pch: Load module automatically if ID matches Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 44/83] arm64: dts: ls1028a: add missing CAN nodes Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 45/83] dt-bindings: drm/bridge: ti-sn65dsi86: Fix reg value Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 46/83] ARM: imx6: disable the GIC CPU interface before calling stby-poweroff sequence Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 47/83] net: bridge: use nla_total_size_64bit() in br_get_linkxstats_size() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 48/83] net: bridge: fix under estimation " Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 49/83] net/sched: sch_taprio: properly cancel timer from taprio_destroy() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 50/83] net: sfp: Fix typo in state machine debug string Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 51/83] netlink: annotate data races around nlk->bound Greg Kroah-Hartman
2021-10-11 13:46 ` Greg Kroah-Hartman [this message]
2021-10-11 13:46 ` [PATCH 5.10 53/83] bus: ti-sysc: Use CLKDM_NOAUTO for dra7 dcan1 for errata i893 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 54/83] drm/sun4i: dw-hdmi: Fix HDMI PHY clock setup Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 55/83] video: fbdev: gbefb: Only instantiate device when built for IP32 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 56/83] drm/nouveau: avoid a use-after-free when BO init fails Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 57/83] drm/nouveau/kms/nv50-: fix file release memory leak Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 58/83] drm/nouveau/debugfs: " Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 59/83] gve: Correct available tx qpl check Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 60/83] gve: Avoid freeing NULL pointer Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 61/83] rtnetlink: fix if_nlmsg_stats_size() under estimation Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 62/83] gve: fix gve_get_stats() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 63/83] gve: report 64bit tx_bytes counter from gve_handle_report_stats() Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 64/83] i40e: fix endless loop under rtnl Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 65/83] i40e: Fix freeing of uninitialized misc IRQ vector Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 66/83] net: prefer socket bound to interface when not in VRF Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 67/83] powerpc/iommu: Report the correct most efficient DMA mask for PCI devices Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 68/83] i2c: acpi: fix resource leak in reconfiguration device addition Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 69/83] i2c: mediatek: Add OFFSET_EXT_CONF setting back Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 70/83] riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for write killable Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 71/83] bpf, s390: Fix potential memory leak about jit_data Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 72/83] RISC-V: Include clone3() on rv32 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 73/83] powerpc/bpf: Fix BPF_MOD when imm == 1 Greg Kroah-Hartman
2021-10-11 17:29   ` Naresh Kamboju
2021-10-11 17:34     ` Naresh Kamboju
2021-10-11 13:46 ` [PATCH 5.10 74/83] powerpc/bpf: Fix BPF_SUB when imm == 0x80000000 Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 75/83] powerpc/64s: fix program check interrupt emergency stack path Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 76/83] pseries/eeh: Fix the kdump kernel crash during eeh_pseries_init Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 77/83] x86/platform/olpc: Correct ifdef symbol to intended CONFIG_OLPC_XO15_SCI Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 78/83] x86/Kconfig: Correct reference to MWINCHIP3D Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 79/83] x86/sev: Return an error on a returned non-zero SW_EXITINFO1[31:0] Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 80/83] x86/entry: Correct reference to intended CONFIG_64_BIT Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 81/83] x86/entry: Clear X86_FEATURE_SMAP when CONFIG_X86_SMAP=n Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 82/83] x86/hpet: Use another crystalball to evaluate HPET usability Greg Kroah-Hartman
2021-10-11 13:46 ` [PATCH 5.10 83/83] scsi: ufs: core: Fix task management completion Greg Kroah-Hartman
2021-10-11 15:03   ` Hunter, Adrian
2021-10-11 15:30     ` Greg Kroah-Hartman
2021-10-11 16:16 ` [PATCH 5.10 00/83] 5.10.73-rc1 review Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011134510.196249945@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=acme@redhat.com \
    --cc=john.garry@huawei.com \
    --cc=kjain@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.