Skip to content

Commit

Permalink
perf mmap: Add new return value logic for perf_mmap__read_init()
Browse files Browse the repository at this point in the history
Improve the readability by using meaningful enum (-EAGAIN, -EINVAL and
0) to replace the three returning states (0, -1 and 1).

Suggested-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1516310792-208685-6-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Kan Liang authored and Arnaldo Carvalho de Melo committed Feb 15, 2018
1 parent 8872481 commit 189f2cc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tools/perf/util/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,
*endp = overwrite ? old : head;

if (*startp == *endp)
return 0;
return -EAGAIN;

size = *endp - *startp;
if (size > (unsigned long)(md->mask) + 1) {
Expand All @@ -291,18 +291,18 @@ int perf_mmap__read_init(struct perf_mmap *md, bool overwrite,

md->prev = head;
perf_mmap__consume(md, overwrite);
return 0;
return -EAGAIN;
}

/*
* Backward ring buffer is full. We still have a chance to read
* most of data from it.
*/
if (overwrite_rb_find_range(data, md->mask, head, startp, endp))
return -1;
return -EINVAL;
}

return 1;
return 0;
}

int perf_mmap__push(struct perf_mmap *md, bool overwrite,
Expand All @@ -316,8 +316,8 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite,
int rc = 0;

rc = perf_mmap__read_init(md, overwrite, &start, &end);
if (rc < 1)
return rc;
if (rc < 0)
return (rc == -EAGAIN) ? 0 : -1;

size = end - start;

Expand Down

0 comments on commit 189f2cc

Please sign in to comment.