[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-7c72440506e2108494bab3b68a4118fa61a9dbf4@git.kernel.org>
Date: Thu, 20 Jul 2017 01:59:27 -0700
From: tip-bot for David Carrillo-Cisneros <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: hpa@...or.com, linux-kernel@...r.kernel.org, sque@...omium.org,
namhyung@...nel.org, acme@...hat.com, eranian@...gle.com,
peterz@...radead.org, jolsa@...nel.org, wangnan0@...wei.com,
dsahern@...il.com, ak@...ux.intel.com, tglx@...utronix.de,
mingo@...nel.org, pjt@...gle.com, mhiramat@...nel.org,
hekuang@...wei.com, alexander.shishkin@...ux.intel.com,
davidcc@...gle.com
Subject: [tip:perf/core] perf util: Add const modifier to buf in "writen"
function
Commit-ID: 7c72440506e2108494bab3b68a4118fa61a9dbf4
Gitweb: http://git.kernel.org/tip/7c72440506e2108494bab3b68a4118fa61a9dbf4
Author: David Carrillo-Cisneros <davidcc@...gle.com>
AuthorDate: Mon, 17 Jul 2017 21:25:37 -0700
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Tue, 18 Jul 2017 23:14:29 -0300
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>
Acked-by: David Ahern <dsahern@...il.com>
Acked-by: Jiri Olsa <jolsa@...nel.org>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Andi Kleen <ak@...ux.intel.com>
Cc: He Kuang <hekuang@...wei.com>
Cc: Masami Hiramatsu <mhiramat@...nel.org>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Turner <pjt@...gle.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Simon Que <sque@...omium.org>
Cc: Stephane Eranian <eranian@...gle.com>
Cc: Wang Nan <wangnan0@...wei.com>
Link: http://lkml.kernel.org/r/20170718042549.145161-5-davidcc@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.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 9e4ea85..4c360da 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)
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);
@@ -308,9 +309,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 062dd20..b136c27 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -38,7 +38,7 @@ int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
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);
size_t hex_width(u64 v);
int hex2u64(const char *ptr, u64 *val);
Powered by blists - more mailing lists