From 184d75a9dee979bf044649bff2854bc66172c9ff Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 28 Jan 2019 22:55:32 -0800 Subject: commands: Get rid of mem_rw_buf There doesn't seem to be any good reason for all of the memory commands (md, mw, etc.) to rely on a shared pre-allocated buffer anymore. So, to simplify things, drop the shared buffer and adjust all of the utilites to allocate needed memory. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/md.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'commands/md.c') diff --git a/commands/md.c b/commands/md.c index 3e83c723a3..1ca7931ae1 100644 --- a/commands/md.c +++ b/commands/md.c @@ -34,8 +34,6 @@ #include #include -extern char *mem_rw_buf; - static int do_mem_md(int argc, char *argv[]) { loff_t start = 0, size = 0x100; @@ -46,6 +44,7 @@ static int do_mem_md(int argc, char *argv[]) int mode = O_RWSIZE_4; int swab = 0; void *map; + void *buf = NULL; if (argc < 2) return COMMAND_ERROR_USAGE; @@ -74,9 +73,11 @@ static int do_mem_md(int argc, char *argv[]) goto out; } + buf = xmalloc(RW_BUF_SIZE); + do { now = min(size, (loff_t)RW_BUF_SIZE); - r = read(fd, mem_rw_buf, now); + r = read(fd, buf, now); if (r < 0) { perror("read"); goto out; @@ -84,8 +85,8 @@ static int do_mem_md(int argc, char *argv[]) if (!r) goto out; - if ((ret = memory_display(mem_rw_buf, start, r, - mode >> O_RWSIZE_SHIFT, swab))) + if ((ret = memory_display(buf, start, r, + mode >> O_RWSIZE_SHIFT, swab))) goto out; start += r; @@ -93,6 +94,7 @@ static int do_mem_md(int argc, char *argv[]) } while (size); out: + free(buf); close(fd); return ret ? 1 : 0; -- cgit v1.2.3