]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
perf util: Add const modifier to buf in "writen" function
authorDavid Carrillo-Cisneros <davidcc@google.com>
Tue, 18 Jul 2017 04:25:37 +0000 (21:25 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 19 Jul 2017 02:14:29 +0000 (23:14 -0300)
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>
tools/perf/util/util.c
tools/perf/util/util.h

index 9e4ea852f6362c588caf440ae18a55900b14f336..4c360daa4e242cc493e4957a7d46eca62ecbca09 100644 (file)
@@ -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)
index 062dd20437f7617e31c5b3f3bea9844b9c81e199..b136c271125f02f99b017f070bbf8448ba9df426 100644 (file)
@@ -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);