diff options
author | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-03 09:23:56 +0200 |
---|---|---|
committer | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-05 09:52:39 +0200 |
commit | de4374bfaaa19ed53b6cdb037aa51f619e99b7d8 (patch) | |
tree | a7f9afcb5b6b454c03696b8fac62f75cb9cf8a68 | |
parent | 2a6179893b85991a440773ecfc46e1e4bc71da07 (diff) |
idlestat: Display error messages closer to point of failure
Functions build_cstate_info and load_and_build_cstate_info
previously handled errors by returning an error code without
printing an error message. This was a problem because the error
could be caused by something which does not set errno, but
the caller assumed this was always the case and called perror()
to report the error to user.
This patch adds reporting of errors directly from these
functions and changes the caller error propagation to be silent.
Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
-rw-r--r-- | idlestat.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -382,7 +382,7 @@ static struct cpuidle_cstates *build_cstate_info(int nrcpus) cstates = calloc(nrcpus, sizeof(*cstates)); if (!cstates) - return NULL; + return ptrerror("calloc in build_cstate_info"); memset(cstates, 0, sizeof(*cstates) * nrcpus); /* initialize cstate_max for each cpu */ @@ -535,7 +535,7 @@ static struct cpuidle_cstates *load_and_build_cstate_info(FILE* f, int nrcpus) cstates = calloc(nrcpus, sizeof(*cstates)); if (!cstates) - return NULL; + return ptrerror("calloc in load_and_build_cstate_info"); memset(cstates, 0, sizeof(*cstates) * nrcpus); @@ -546,10 +546,14 @@ static struct cpuidle_cstates *load_and_build_cstate_info(FILE* f, int nrcpus) cstates[cpu].cstate_max = -1; cstates[cpu].current_cstate = -1; - sscanf(buffer, "cpuid %d:\n", &read_cpu); - - if (read_cpu != cpu) { + if (sscanf(buffer, "cpuid %d:\n", &read_cpu) != 1 || + read_cpu != cpu) { release_cstate_info(cstates, cpu); + fprintf(stderr, + "%s: Error reading trace file\n" + "Expected: cpuid %d:\n" + "Read: %s", + __FUNCTION__, cpu, buffer); return NULL; } @@ -1030,10 +1034,7 @@ struct cpuidle_datas *idlestat_load(const char *filename) if (!datas->cstates) { free(datas); fclose(f); - if (format == IDLESTAT_HEADER) - return ptrerror("load_and_build_cstate_info: out of memory"); - else - return ptrerror("build_cstate_info: out of memory"); + return NULL; } datas->pstates = build_pstate_info(nrcpus); |