[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170518041602.28689-3-davidcc@google.com>
Date: Wed, 17 May 2017 21:15:57 -0700
From: David Carrillo-Cisneros <davidcc@...gle.com>
To: linux-kernel@...r.kernel.org
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Andi Kleen <ak@...ux.intel.com>, Simon Que <sque@...omium.org>,
Wang Nan <wangnan0@...wei.com>, Jiri Olsa <jolsa@...nel.org>,
He Kuang <hekuang@...wei.com>,
Masami Hiramatsu <mhiramat@...nel.org>,
David Ahern <dsa@...ulusnetworks.com>,
Namhyung Kim <namhyung@...nel.org>,
Stephane Eranian <eranian@...gle.com>,
Paul Turner <pjt@...gle.com>,
David Carrillo-Cisneros <davidcc@...gle.com>
Subject: [PATCH 2/7] 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@...gle.com>
---
tools/perf/util/util.c | 6 ++++--
tools/perf/util/util.h | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 6450c75a6f5b..31ca7661e5fb 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -260,6 +260,7 @@ static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
size_t left = n;
while (left) {
+ /* buf must be treated as const if !is_read. */
ssize_t ret = is_read ? read(fd, buf, left) :
write(fd, buf, left);
@@ -287,9 +288,10 @@ ssize_t readn(int fd, void *buf, size_t n)
/*
* Write exactly 'n' bytes or return an error.
*/
-ssize_t writen(int fd, void *buf, size_t n)
+ssize_t writen(int fd, const void *buf, size_t n)
{
- return ion(false, fd, buf, n);
+ /* ion does not modify buf. */
+ return ion(false, fd, (void *)buf, n);
}
size_t hex_width(u64 v)
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 3852b6d3270a..e0881bf67fc9 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -57,7 +57,7 @@ int copyfile_mode(const char *from, const char *to, mode_t mode);
int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
ssize_t readn(int fd, void *buf, size_t n);
-ssize_t writen(int fd, void *buf, size_t n);
+ssize_t writen(int fd, const void *buf, size_t n);
struct perf_event_attr;
--
2.13.0.303.g4ebf302169-goog
Powered by blists - more mailing lists