[PATCH 2/4] fru: ops: Return error from checksum if data is all zero's

Michal Simek michal.simek at xilinx.com
Wed Feb 23 15:00:57 CET 2022


From: Ashok Reddy Soma <ashok.reddy.soma at xilinx.com>

fru_checksum function is simply adding all the bytes and returning the
sum. If the data passed to this function is all zero's then it will
return 0, and the functions calling this api will assume that checksum
is correct. Ideally this is not good. Fix this by returning error if all
the data is 0's.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma at xilinx.com>
Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---

 board/xilinx/common/fru_ops.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/board/xilinx/common/fru_ops.c b/board/xilinx/common/fru_ops.c
index a0a1441a8eef..058e750c442f 100644
--- a/board/xilinx/common/fru_ops.c
+++ b/board/xilinx/common/fru_ops.c
@@ -39,12 +39,20 @@ static int fru_check_language(u8 code)
 u8 fru_checksum(u8 *addr, u8 len)
 {
 	u8 checksum = 0;
+	u8 cnt = len;
 
 	while (len--) {
+		if (*addr == 0)
+			cnt--;
+
 		checksum += *addr;
 		addr++;
 	}
 
+	/* If all data bytes are 0's return error */
+	if (!cnt)
+		return EINVAL;
+
 	return checksum;
 }
 
-- 
2.35.1



More information about the U-Boot mailing list