diff options
author | David Carrillo-Cisneros <davidcc@google.com> | 2017-07-18 00:25:37 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-18 22:14:29 -0400 |
commit | 7c72440506e2108494bab3b68a4118fa61a9dbf4 (patch) | |
tree | 6aeb313fcf98b6225e785b0cfc438888607e62cf /tools/perf/util/util.c | |
parent | 2ff5365d75e164032f64133914046fd6be213d94 (diff) |
perf util: Add const modifier to buf in "writen" function
Make buf in helper function "writen" constant to simplify the life of
its callers.
This requires to hack a cast of buf prior to passing it to "ion" which
is simpler than the alternative of reworking the "ion" function to
provide a read and a write paths, the latter with constant buf argument.
Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
Acked-by: David Ahern <dsahern@gmail.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Simon Que <sque@chromium.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20170718042549.145161-5-davidcc@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r-- | tools/perf/util/util.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 9e4ea852f636..4c360daa4e24 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -281,6 +281,7 @@ static ssize_t ion(bool is_read, int fd, void *buf, size_t n) | |||
281 | size_t left = n; | 281 | size_t left = n; |
282 | 282 | ||
283 | while (left) { | 283 | while (left) { |
284 | /* buf must be treated as const if !is_read. */ | ||
284 | ssize_t ret = is_read ? read(fd, buf, left) : | 285 | ssize_t ret = is_read ? read(fd, buf, left) : |
285 | write(fd, buf, left); | 286 | write(fd, buf, left); |
286 | 287 | ||
@@ -308,9 +309,10 @@ ssize_t readn(int fd, void *buf, size_t n) | |||
308 | /* | 309 | /* |
309 | * Write exactly 'n' bytes or return an error. | 310 | * Write exactly 'n' bytes or return an error. |
310 | */ | 311 | */ |
311 | ssize_t writen(int fd, void *buf, size_t n) | 312 | ssize_t writen(int fd, const void *buf, size_t n) |
312 | { | 313 | { |
313 | return ion(false, fd, buf, n); | 314 | /* ion does not modify buf. */ |
315 | return ion(false, fd, (void *)buf, n); | ||
314 | } | 316 | } |
315 | 317 | ||
316 | size_t hex_width(u64 v) | 318 | size_t hex_width(u64 v) |