diff --git a/lib/perf-counter.c b/lib/perf-counter.c index 7bd783451ca..b700e492bcc 100644 --- a/lib/perf-counter.c +++ b/lib/perf-counter.c @@ -39,9 +39,9 @@ static int fd__ = 0; uint64_t perf_counter_read(uint64_t *counter) { - if (fd__ > 0) { - read(fd__, counter, sizeof(*counter)); - } else { + size_t size = sizeof *counter; + + if (fd__ <= 0 || read(fd__, counter, size) < size) { *counter = 0; }