mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: mm: don't ignore pread() errors for larger access sizes
@ 2022-09-02 10:04 Ahmad Fatoum
  2022-09-12 10:14 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-09-02 10:04 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Error check was before pread was called and because ret was initialized,
compiler didn't warn about it. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/mm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commands/mm.c b/commands/mm.c
index 9ce883964485..8fe87a80a18e 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;
@@ -65,9 +65,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 +75,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);
-- 
2.30.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-12 10:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02 10:04 [PATCH] commands: mm: don't ignore pread() errors for larger access sizes Ahmad Fatoum
2022-09-12 10:14 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox