fru: ops: Return error from checksum if data is all zero's

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@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Link: https://lore.kernel.org/r/ac0366fe55c60a818a3f9ed33d96826c817d5520.1645624855.git.michal.simek@xilinx.com
This commit is contained in:
Ashok Reddy Soma 2022-02-23 15:00:57 +01:00 committed by Michal Simek
parent 952b2e60de
commit 90e8f2db60

View File

@ -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;
}