From 0e0ed5361d058820c920ff9c7080714346002a72 Mon Sep 17 00:00:00 2001
From: Christos Gentsos <christos.gentsos@cern.ch>
Date: Thu, 28 Oct 2021 10:05:02 +0200
Subject: [PATCH] Master: fill data with 0xFF on failed I2C transactions

Previously, a failed I2C transaction would leave the data buffer
intact, and if one didn't look at the return status they might assume
valid data were returned. This modification should make it easier to
identify failed transactions.
---
 test_master/src/i2c_master_mod_fns.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/test_master/src/i2c_master_mod_fns.c b/test_master/src/i2c_master_mod_fns.c
index 24a8a5a..73e9b88 100644
--- a/test_master/src/i2c_master_mod_fns.c
+++ b/test_master/src/i2c_master_mod_fns.c
@@ -396,6 +396,7 @@ int32_t i2c_m_sync_my_cmd_read(struct i2c_m_sync_desc *i2c, uint8_t reg, uint8_t
 
 	if (ret != 0) {
 		/* error occurred */
+                memset(buffer, 0xFF, length);
 		return ret;
 	}
 
@@ -417,6 +418,7 @@ int32_t i2c_m_sync_my_cmd_read(struct i2c_m_sync_desc *i2c, uint8_t reg, uint8_t
 		/* error occurred */
                 if (use_pec)
                         free(pec_buf);
+                memset(buffer, 0xFF, length);
 		return ret;
 	}
 
@@ -567,6 +569,7 @@ int32_t i2c_m_sync_ext_cmd_read(struct i2c_m_sync_desc *i2c, uint8_t cmd, uint8_
 
 	if (ret != 0) {
 		/* error occurred */
+                memset(buffer, 0xFF, length);
 		return ret;
 	}
 
@@ -588,6 +591,7 @@ int32_t i2c_m_sync_ext_cmd_read(struct i2c_m_sync_desc *i2c, uint8_t cmd, uint8_
 		/* error occurred */
                 if (use_pec)
                         free(pec_buf);
+                memset(buffer, 0xFF, length);
 		return ret;
 	}
 
-- 
GitLab