diff mbox series

[05/11] target: Cleanup pib_read/write() to make easier to read

Message ID 20180607065438.18257-5-mikey@neuling.org
State Accepted
Headers show
Series [01/11] Cleanup exit code | expand

Commit Message

Michael Neuling June 7, 2018, 6:54 a.m. UTC
Currently we change input parameter addr to have a different meaning
making the code hard to read.

This adds a new local variable target_addr to make it easier to read.

This also adds a pr_debug() to each so we can see whats happening.

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 libpdbg/target.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libpdbg/target.c b/libpdbg/target.c
index bcf4bb9b69..be3b8458ec 100644
--- a/libpdbg/target.c
+++ b/libpdbg/target.c
@@ -1,5 +1,6 @@ 
 #include <stdio.h>
 #include <stdint.h>
+#include <inttypes.h>
 #include <assert.h>
 #include <ccan/list/list.h>
 #include <libfdt/libfdt.h>
@@ -112,28 +113,34 @@  static int pib_indirect_write(struct pib *pib, uint64_t addr, uint64_t data)
 int pib_read(struct pdbg_target *pib_dt, uint64_t addr, uint64_t *data)
 {
 	struct pib *pib;
+	uint64_t target_addr = addr;
 	int rc;
 
-	pib_dt = get_class_target_addr(pib_dt, "pib", &addr);
+	pib_dt = get_class_target_addr(pib_dt, "pib", &target_addr);
 	pib = target_to_pib(pib_dt);
-	if (addr & PPC_BIT(0))
-		rc = pib_indirect_read(pib, addr, data);
+	if (target_addr & PPC_BIT(0))
+		rc = pib_indirect_read(pib, target_addr, data);
 	else
-		rc = pib->read(pib, addr, data);
+		rc = pib->read(pib, target_addr, data);
+	PR_DEBUG("addr:0x%08" PRIx64 " data:0x%016" PRIx64 "\n",
+		 target_addr, *data);
 	return rc;
 }
 
 int pib_write(struct pdbg_target *pib_dt, uint64_t addr, uint64_t data)
 {
 	struct pib *pib;
+	uint64_t target_addr = addr;
 	int rc;
 
-	pib_dt = get_class_target_addr(pib_dt, "pib", &addr);
+	pib_dt = get_class_target_addr(pib_dt, "pib", &target_addr);
 	pib = target_to_pib(pib_dt);
-	if (addr & PPC_BIT(0))
-		rc = pib_indirect_write(pib, addr, data);
+	PR_DEBUG("addr:0x%08" PRIx64 " data:0x%016" PRIx64 "\n",
+		 target_addr, data);
+	if (target_addr & PPC_BIT(0))
+		rc = pib_indirect_write(pib, target_addr, data);
 	else
-		rc = pib->write(pib, addr, data);
+		rc = pib->write(pib, target_addr, data);
 	return rc;
 }