summaryrefslogtreecommitdiffstats
path: root/common
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 /common
parent60aaeb8be019c75d86cd0aa9615d1ef470983418 (diff)
downloadbarebox-184d75a9dee979bf044649bff2854bc66172c9ff.tar.gz
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 'common')
-rw-r--r--common/ratp/md.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/common/ratp/md.c b/common/ratp/md.c
index 9ce7e99..0235352 100644
--- a/common/ratp/md.c
+++ b/common/ratp/md.c
@@ -59,8 +59,6 @@ struct ratp_bb_md_response {
uint8_t buffer[];
} __packed;
-extern char *mem_rw_buf;
-
static int do_ratp_mem_md(const char *filename,
loff_t start,
loff_t size,
@@ -70,6 +68,7 @@ static int do_ratp_mem_md(const char *filename,
int ret = 0;
int fd;
void *map;
+ char *buf = NULL;
fd = open_and_lseek(filename, O_RWSIZE_1 | O_RDONLY, start);
if (fd < 0)
@@ -81,10 +80,11 @@ static int do_ratp_mem_md(const char *filename,
goto out;
}
+ buf = xmalloc(RW_BUF_SIZE);
t = 0;
do {
now = min(size, (loff_t)RW_BUF_SIZE);
- r = read(fd, mem_rw_buf, now);
+ r = read(fd, buf, now);
if (r < 0) {
ret = -errno;
perror("read");
@@ -93,13 +93,14 @@ static int do_ratp_mem_md(const char *filename,
if (!r)
goto out;
- memcpy(output + t, (uint8_t *)(mem_rw_buf), r);
+ memcpy(output + t, buf, r);
size -= r;
t += r;
} while (size);
out:
+ free(buf);
close(fd);
return ret;