ACK: [PATCH 1/5] lib: fwts_olog: minor fwts coding style reformatting

Alex Hung alex.hung at canonical.com
Wed Apr 6 02:43:14 UTC 2016


On 2016-04-03 01:52 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> No functional change, just making the source more akin to the usual
> fwts coding style and 80 tty column friendly.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/src/fwts_olog.c | 134 +++++++++++++++++++++++++++++-------------------
>   1 file changed, 80 insertions(+), 54 deletions(-)
>
> diff --git a/src/lib/src/fwts_olog.c b/src/lib/src/fwts_olog.c
> index be13ee6..46a920c 100644
> --- a/src/lib/src/fwts_olog.c
> +++ b/src/lib/src/fwts_olog.c
> @@ -42,7 +42,7 @@ static const char msglog[] = "/sys/firmware/opal/msglog";
>   static const char msglog_outfile[] = "/var/log/opal_msglog";
>
>   /*
> - *	fwts_olog_read(fwts_framework *fw)
> + *  fwts_olog_read(fwts_framework *fw)
>    *	read olog log and return as list of lines
>    */
>   fwts_list *fwts_olog_read(fwts_framework *fw)
> @@ -56,59 +56,79 @@ fwts_list *fwts_olog_read(fwts_framework *fw)
>   	FILE* msglog_f;
>   	FILE* msglog_outfile_f;
>
> -/* Check for the existance of the opal msglog and only if it exists dump it out         */
> -/* This makes the use of the OLOG as a custom option and not just for PPC               */
> -/* We don't use compiler flags since we want to run this as a custom job cross platform */
> -
> -	if (stat(msglog,&filestat)) /* stat fails so not PPC with OPAL msglog and no -o OLOG sent */
> +	/*
> +	 * Check for the existance of the opal msglog and only if it exists
> +	 * dump it out.  This makes the use of the OLOG as a custom option
> +	 * and not just for PPC.  We don't use compiler flags since we want
> +	 * to run this as a custom job cross platform
> +	 */
> +	if (stat(msglog,&filestat)) {
> +		/*
> +		 * stat fails so not PPC with OPAL msglog and
> +		 * no -o OLOG sent
> +		 */
>   		return NULL;
> +	}
>
> -/* Special file handling to sequentially fread the sysfs msglog into a static buffer	*/
> -/* based on inodes in the stat								*/
> -/* The sysfs msglog has a 0 byte file size since it is a sysfs object			*/
> -/* Real size of the sysfs msglog is not in the stat statistics				*/
> -/* Using the st_blksize (the preferred i/o blksize)					*/
> -/* st_blocks is zero so must fread block by block					*/
> -
> -
> -	if (!(msglog_f = fopen(msglog, "r")))			/* open the sysfs msglog for read only */
> +	/*
> +	 * Special file handling to sequentially fread the sysfs msglog into
> +	 * a static buffer based on inodes in the stat.  The sysfs msglog has
> +	 * a 0 byte file size since it is a sysfs object.
> +	 * Real size of the sysfs msglog is not in the stat statistics
> +	 * Using the st_blksize (the preferred i/o blksize)
> +	 * st_blocks is zero so must fread block by block
> +	 */
> +	if (!(msglog_f = fopen(msglog, "r"))) {
> +		/* open the sysfs msglog for read only */
>   		goto olog_common_exit;
> +	}
>
> -	if ((len = filestat.st_blksize) < 1) 			/* if any size at all continue */
> +	if ((len = filestat.st_blksize) < 1) {
> +		/* if any size at all continue */
>   		goto olog_cleanup_msglog;
> +	}
>
> -	if ((buffer = calloc(1,len+1)) == NULL)
> +	if ((buffer = calloc(1,len+1)) == NULL) {
>   		goto olog_cleanup_msglog;
> +	}
>
> -	if (!(msglog_outfile_f = fopen(msglog_outfile, "w")))	/* create the output file for the sysfs msglog */
> -		goto olog_cleanup_msglog;			/* so we can dump it out as a real fs file     */
> +	if (!(msglog_outfile_f = fopen(msglog_outfile, "w"))) {
> +		/* create the output file for the sysfs msglog */
> +		goto olog_cleanup_msglog;
> +	}
>
>   	while (!feof (msglog_f)) {
>   		read_actual = fread(buffer,1,len,msglog_f);
>   		if (read_actual == len) {
> -			write_actual = fwrite(buffer,1,len,msglog_outfile_f);
> +			write_actual = fwrite(buffer, 1, len, msglog_outfile_f);
>   			if (!(write_actual == len)) {
>   				free(buffer);
>   				goto olog_cleanup_common;
>   			}
>   		} else {
>   			if (feof(msglog_f)) {
> -				write_actual = fwrite(buffer,1,read_actual,msglog_outfile_f);
> +				write_actual = fwrite(buffer, 1, read_actual, msglog_outfile_f);
>   				if (!(write_actual == read_actual)) {
>   					free(buffer);
>   					goto olog_cleanup_common;
>   				}
> -			} else
> -				break;	/* we didn't get a full read and file did not test for EOF so bail */
> +			} else {
> +				/*
> +				 * we didn't get a full read and file did not
> +				 * test for EOF so bail
> +				 */
> +				break;
> +			}
>   		}
>   	}
>
> -	free(buffer);			/* done with the static small buffer			*/
> -	fclose(msglog_f);		/* close the sysfs msglog we don't need it anymore	*/
> -	fclose(msglog_outfile_f);	/* close the msglog outfile which was opened for write	*/
> -
> -	/* Now work on the dumped out msglog as a real file system file */
> +	free(buffer);
> +	(void)fclose(msglog_f);
> +	(void)fclose(msglog_outfile_f);
>
> +	/*
> +	 * Now work on the dumped out msglog as a real file system file
> +	 */
>   	if (!(msglog_outfile_f = fopen(msglog_outfile, "r")))
>   		goto olog_cleanup_common;
>
> @@ -128,28 +148,29 @@ fwts_list *fwts_olog_read(fwts_framework *fw)
>   	if (read_actual == len) {
>   		list = fwts_list_from_text(buffer);
>   		free(buffer);
> -		fclose(msglog_outfile_f);
> +		(void)fclose(msglog_outfile_f);
>   		return list;
> -	}
> -	else {
> +	} else {
>   		free(buffer);
>   		goto olog_cleanup_msglog_outfile;
>   	}
>
>   olog_cleanup_msglog_outfile:
> -	fclose(msglog_outfile_f);
> +	(void)fclose(msglog_outfile_f);
>   	goto olog_common_exit;
>
>   olog_cleanup_msglog:
> -	fclose(msglog_f);
> +	(void)fclose(msglog_f);
>   	goto olog_common_exit;
>
>   olog_cleanup_common:
> -	fclose(msglog_f);
> -	fclose(msglog_outfile_f);
> +	(void)fclose(msglog_f);
> +	(void)fclose(msglog_outfile_f);
>
>   olog_common_exit:
> -	fwts_log_error(fw, "Problem with the file handling on the default dumped OPAL msglog, %s, try using -o to specify a specific saved OPAL msglog for analysis.\n", msglog_outfile);
> +	fwts_log_error(fw, "Problem with the file handling on the default dumped "
> +		"OPAL msglog, %s, try using -o to specify a specific saved OPAL "
> +		"msglog for analysis.", msglog_outfile);
>   	return NULL;
>   }
>
> @@ -160,21 +181,18 @@ static int fwts_olog_check(fwts_framework *fw,
>   	fwts_list *olog,
>   	int *errors)
>   {
> -	int ret = FWTS_ERROR;
> -	int n;
> -	int i;
> -	int fd;
> -	json_object *olog_objs;
> -	json_object *olog_table;
> +	int n, i, fd, ret = FWTS_ERROR;
> +	json_object *olog_objs, *olog_table;
>   	fwts_klog_pattern *patterns;
>   	char json_data_path[PATH_MAX];
>
> -
>   	if (fw->json_data_file) {
> -		snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path,(fw->json_data_file));
> -	}
> -	else { /* use the hard coded OLOG JSON as default */
> -		snprintf(json_data_path, sizeof(json_data_path), "%s/%s", fw->json_data_path, OLOG_DATA_JSON_FILE);
> +		snprintf(json_data_path, sizeof(json_data_path), "%s/%s",
> +			fw->json_data_path,(fw->json_data_file));
> +	} else {
> +		/* use the hard coded OLOG JSON as default */
> +		snprintf(json_data_path, sizeof(json_data_path), "%s/%s",
> +			fw->json_data_path, OLOG_DATA_JSON_FILE);
>   	}
>
>   	/*
> @@ -182,10 +200,12 @@ static int fwts_olog_check(fwts_framework *fw,
>   	 * so check if we can open for read before calling json_object_from_file()
>   	 */
>   	if ((fd = open(json_data_path, O_RDONLY)) < 0) {
> -		fwts_log_error(fw, "Cannot read file %s, check the path and check that the file exists, you may need to specify -j or -J.", json_data_path);
> +		fwts_log_error(fw, "Cannot read file %s, check the path and "
> +			"check that the file exists, you may need to specify "
> +			"-j or -J.", json_data_path);
>   		return FWTS_ERROR;
>   	}
> -	close(fd);
> +	(void)close(fd);
>
>   	olog_objs = json_object_from_file(json_data_path);
>   	if (FWTS_JSON_ERROR(olog_objs)) {
> @@ -195,13 +215,15 @@ static int fwts_olog_check(fwts_framework *fw,
>
>   #if JSON_HAS_GET_EX
>   	if (!json_object_object_get_ex(olog_objs, table, &olog_table)) {
> -		fwts_log_error(fw, "Cannot fetch olog table object '%s' from %s.", table, json_data_path);
> +		fwts_log_error(fw, "Cannot fetch olog table object '%s' from %s.",
> +			table, json_data_path);
>   		goto fail_put;
>   	}
>   #else
>   	olog_table = json_object_object_get(olog_objs, table);
>   	if (FWTS_JSON_ERROR(olog_table)) {
> -		fwts_log_error(fw, "Cannot fetch olog table object '%s' from %s.", table, json_data_path);
> +		fwts_log_error(fw, "Cannot fetch olog table object '%s' from %s.",
> +			table, json_data_path);
>   		goto fail_put;
>   	}
>   #endif
> @@ -221,7 +243,8 @@ static int fwts_olog_check(fwts_framework *fw,
>
>   		obj = json_object_array_get_idx(olog_table, i);
>   		if (FWTS_JSON_ERROR(obj)) {
> -			fwts_log_error(fw, "Cannot fetch %d item from table %s.", i, table);
> +			fwts_log_error(fw, "Cannot fetch %d item from table %s.",
> +				i, table);
>   			goto fail;
>   		}
>   		if ((str = fwts_json_str(fw, table, i, obj, "compare_mode", true)) == NULL)
> @@ -278,8 +301,11 @@ fail_put:
>   	return ret;
>   }
>
> -int fwts_olog_firmware_check(fwts_framework *fw, fwts_olog_progress_func progress,
> -	fwts_list *olog, int *errors)
> +int fwts_olog_firmware_check(
> +	fwts_framework *fw,
> +	fwts_olog_progress_func progress,
> +	fwts_list *olog,
> +	int *errors)
>   {
>   	return fwts_olog_check(fw, "olog_error_warning_patterns",
>   		progress, olog, errors);
>

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list