ACK: [PATCH 2/3] lib: fwts_cpu: return info struct only when requested CPU is found

Colin Ian King colin.king at canonical.com
Sun Jul 10 18:24:01 UTC 2016


On 09/07/16 00:42, Ricardo Neri wrote:
> If the requested CPU is not found, we would be returning an empty
> structure (along with NULL pointers). It makes no sense to return
> such useless structure. Instead, return NULL.
> 
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon at linux.intel.com>
> ---
>  src/lib/src/fwts_cpu.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
> index 053f850..2e0834d 100644
> --- a/src/lib/src/fwts_cpu.c
> +++ b/src/lib/src/fwts_cpu.c
> @@ -106,7 +106,7 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(const int which_cpu)
>  	FILE *fp;
>  	char buffer[1024];
>  	fwts_cpuinfo_x86 *cpu;
> -	int cpu_num = -1;
> +	int cpu_num = -1, found = 0;
>  
>  	if ((cpu = (fwts_cpuinfo_x86*)calloc(1, sizeof(fwts_cpuinfo_x86))) == NULL)
>  		return NULL;
> @@ -135,6 +135,8 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(const int which_cpu)
>  				continue;
>  		}
>  
> +		found = 1;
> +
>  		if (!strncmp(buffer, "vendor_id", 9)) {
>  			cpu->vendor_id = strdup(ptr);
>  			continue;
> @@ -162,6 +164,11 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(const int which_cpu)
>  	}
>  	fclose(fp);
>  
> +	if (!found) {
> +		free(cpu);
> +		cpu = NULL;
> +	}
> +
>  	return cpu;
>  }
>  
> 
Acked-by: Colin Ian King <colin.king at canonical.com>



More information about the fwts-devel mailing list