From b743a7d5ed203ed87a06dddbd27cfb3fd04ceba5 Mon Sep 17 00:00:00 2001 From: Tuukka Tikkanen Date: Tue, 13 Jan 2015 20:48:07 +0200 Subject: idlestat: Check return value in cpuidle_get_target_residency The return value from call to fscanf was previously ignored. Now the function cpuidle_get_target_residency will return -1 if fscanf fails to parse the value. Signed-off-by: Tuukka Tikkanen --- idlestat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/idlestat.c b/idlestat.c index 4392920..dbf8400 100644 --- a/idlestat.c +++ b/idlestat.c @@ -271,6 +271,7 @@ int cpuidle_get_target_residency(int cpu, int state) char *fpath; unsigned int tr; FILE *snf; + int ret; if (asprintf(&fpath, CPUIDLE_STATE_TARGETRESIDENCY_PATH_FORMAT, cpu, state) < 0) @@ -283,10 +284,10 @@ int cpuidle_get_target_residency(int cpu, int state) free(fpath); return -1; } - fscanf(snf, "%u", &tr); + ret = fscanf(snf, "%u", &tr); fclose(snf); - return tr; + return (ret == 1) ? tr : -1; } /** -- cgit v1.2.3