[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170525080848.GH14467@krava>
Date: Thu, 25 May 2017 10:08:48 +0200
From: Jiri Olsa <jolsa@...hat.com>
To: David Carrillo-Cisneros <davidcc@...gle.com>
Cc: linux-kernel@...r.kernel.org,
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>
Subject: Re: [PATCH v2 10/13] perf header: add a buffer to struct feat_fd
On Tue, May 23, 2017 at 12:48:50AM -0700, David Carrillo-Cisneros wrote:
SNIP
> @@ -82,11 +83,27 @@ bool perf_header__has_feat(const struct perf_header *header, int feat)
> /* Return: 0 if succeded, -ERR if failed. */
> int do_write(struct feat_fd *fd, const void *buf, size_t size)
> {
> - ssize_t ret;
> + void *addr;
>
> - ret = writen(fd->fd, buf, size);
> - if (ret != (ssize_t)size)
> - return ret < 0 ? (int)ret: -1;
> + if (!fd->buf) {
> + ssize_t ret = writen(fd->fd, buf, size);
> +
> + if (ret != (ssize_t)size)
> + return ret < 0 ? (int)ret : -1;
> + return 0;
> + }
> +retry:
> + if (size > (fd->size - fd->offset)) {
> + addr = realloc(fd->buf, fd->size << 1);
> + if (!addr)
> + return -ENOSPC;
> + fd->buf = addr;
> + fd->size <<= 1;
> + goto retry;
> + }
> +
> + memcpy(fd->buf + fd->offset, buf, size);
> + fd->offset += size;
>
> return 0;
please put those 2 cases in separate functions
> }
> @@ -126,10 +143,21 @@ static int do_write_string(struct feat_fd *fd, const char *str)
>
> static int __do_read(struct feat_fd *fd, void *addr, ssize_t size)
> {
> - ssize_t ret = readn(fd->fd, addr, size);
> + if (!fd->buf) {
> + ssize_t ret = readn(fd->fd, addr, size);
> +
> + if (ret != (ssize_t)size)
> + return ret < 0 ? (int)ret : -1;
> + return 0;
> + }
> +
> + assert((ssize_t)fd->size > fd->offset);
> + if (size > (ssize_t)fd->size - fd->offset)
> + return -1;
> +
> + memcpy(addr, fd->buf + fd->offset, size);
> + fd->offset += size;
>
> - if (ret != (ssize_t)size)
> - return ret < 0 ? (int)ret : -1;
> return 0;
> }
same for the read
thanks,
jirka
Powered by blists - more mailing lists