lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <58c219e5-78a9-be21-4942-b6ba9d21d467@linux.ibm.com>
Date:   Fri, 23 Oct 2020 13:19:27 +0530
From:   kajoljain <kjain@...ux.ibm.com>
To:     John Garry <john.garry@...wei.com>, peterz@...radead.org,
        mingo@...hat.com, acme@...nel.org, mark.rutland@....com,
        alexander.shishkin@...ux.intel.com, jolsa@...hat.com,
        namhyung@...nel.org, irogers@...gle.com, yao.jin@...ux.intel.com,
        yeyunfeng@...wei.com
Cc:     linux-kernel@...r.kernel.org, linuxarm@...wei.com
Subject: Re: [PATCH v2 1/2] perf jevents: Tidy error handling



On 10/22/20 4:32 PM, John Garry wrote:
> There is much duplication in the error handling for directory transvering
> for prcessing JSONs.
> 
> Factor out the common code to tidy a bit.
> 

Patch looks good to me.

Reviewed-By: Kajol Jain<kjain@...ux.ibm.com>

Thanks,
Kajol Jain
> Signed-off-by: John Garry <john.garry@...wei.com>
> ---
>  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 e47644cab3fa..7326c14c4623 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;
>  }
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ