summaryrefslogtreecommitdiffstats
path: root/commands/mm.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands/mm.c')
-rw-r--r--commands/mm.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/commands/mm.c b/commands/mm.c
index 9ce8839644..8755a0f2c9 100644
--- a/commands/mm.c
+++ b/commands/mm.c
@@ -16,7 +16,7 @@
static int do_mem_mm(int argc, char *argv[])
{
- int ret = 0;
+ int ret;
int fd;
char *filename = "/dev/mem";
int mode = O_RWSIZE_4;
@@ -40,8 +40,10 @@ static int do_mem_mm(int argc, char *argv[])
mask = simple_strtoull(argv[optind++], NULL, 0);
fd = open_and_lseek(filename, mode | O_RDWR | O_CREAT, adr);
- if (fd < 0)
+ if (fd < 0) {
+ printf("Could not open \"%s\": %m\n", filename);
return 1;
+ }
switch (mode) {
case O_RWSIZE_1:
@@ -65,9 +67,9 @@ static int do_mem_mm(int argc, char *argv[])
goto out_write;
break;
case O_RWSIZE_4:
+ ret = pread(fd, &val32, 4, adr);
if (ret < 0)
goto out_read;
- ret = pread(fd, &val32, 4, adr);
val32 &= ~mask;
val32 |= (value & mask);
ret = pwrite(fd, &val32, 4, adr);
@@ -75,9 +77,9 @@ static int do_mem_mm(int argc, char *argv[])
goto out_write;
break;
case O_RWSIZE_8:
+ ret = pread(fd, &val64, 8, adr);
if (ret < 0)
goto out_read;
- ret = pread(fd, &val64, 8, adr);
val64 &= ~mask;
val64 |= (value & mask);
ret = pwrite(fd, &val64, 8, adr);