diff mbox series

[2/7] mem: Make _putmem consistent with _getmem

Message ID 20190410080854.430335-3-amitay@ozlabs.org
State Accepted
Headers show
Series Implement sbe fifo driver | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (854c4c5facff43af9e0fe5d7062b58f631987b0b)
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master

Commit Message

Amitay Isaacs April 10, 2019, 8:08 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 src/mem.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/src/mem.c b/src/mem.c
index fe76c64..421eea3 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -153,31 +153,34 @@  static int _putmem(uint64_t addr, uint8_t block_size, bool ci)
 {
 	uint8_t *buf;
 	size_t buflen;
-	int rc = 0;
-	struct pdbg_target *adu_target;
-
-	pdbg_for_each_class_target("adu", adu_target)
-		break;
-
-	if (pdbg_target_probe(adu_target) != PDBG_TARGET_ENABLED)
-		return 0;
+	int rc, count = 0;
+	struct pdbg_target *target;
 
 	buf = read_stdin(&buflen);
 	assert(buf);
 
-	pdbg_set_progress_tick(progress_tick);
-	progress_init();
-	rc = mem_write(adu_target, addr, buf, buflen, block_size, ci);
-	progress_end();
-	if (rc) {
-		printf("Unable to write memory\n");
-		free(buf);
-		return 0;
+	pdbg_for_each_class_target("adu", target) {
+		if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED)
+			continue;
+
+		pdbg_set_progress_tick(progress_tick);
+		progress_init();
+		rc = mem_write(target, addr, buf, buflen, block_size, ci);
+		progress_end();
+		if (rc) {
+			printf("Unable to write memory\n");
+			continue;
+		}
+
+		count++;
+		break;
 	}
 
-	printf("Wrote %zu bytes starting at 0x%016" PRIx64 "\n", buflen, addr);
+	if (count > 0)
+		printf("Wrote %zu bytes starting at 0x%016" PRIx64 "\n", buflen, addr);
+
 	free(buf);
-	return 1;
+	return count;
 }
 
 static int putmem(uint64_t addr, struct mem_flags flags)