summaryrefslogtreecommitdiffstats
path: root/commands/md.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-28 22:55:32 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-01-29 09:21:28 +0100
commit184d75a9dee979bf044649bff2854bc66172c9ff (patch)
tree7205a5e431d0f9728c10218695d997e619e35375 /commands/md.c
parent60aaeb8be019c75d86cd0aa9615d1ef470983418 (diff)
downloadbarebox-184d75a9dee979bf044649bff2854bc66172c9ff.tar.gz
barebox-184d75a9dee979bf044649bff2854bc66172c9ff.tar.xz
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 <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/md.c')
-rw-r--r--commands/md.c12
1 files changed, 7 insertions, 5 deletions
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 <linux/stat.h>
#include <xfuncs.h>
-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;