summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDenis Orlov <denorl2009@gmail.com>2023-01-13 17:06:48 +0300
committerSascha Hauer <s.hauer@pengutronix.de>2023-01-16 13:40:38 +0100
commitefae55f80b6e6df0a1d3516ff3ddd688d1035169 (patch)
treeacac418869aa57e0dfd9d160accef6c89d605e45 /common
parent31e5e23730ea2459d4d370596a43a8c8b4bf8758 (diff)
downloadbarebox-efae55f80b6e6df0a1d3516ff3ddd688d1035169.tar.gz
barebox-efae55f80b6e6df0a1d3516ff3ddd688d1035169.tar.xz
ddr_spd: use unsigned type for crc bytes in DDR3/4 SPD check
Using signed char type for computed CRC bytes leads to them being sign extended on comparison with unsigned char values from SPD EEPROM struct. This happens as when being compared those values undergo integer promotion that converts them into ints, sign extending signed types. Having most significant byte set for any of computed CRC bytes thus results in the mismatch being erroneously detected. While at it, also remove redundant type casts. Signed-off-by: Denis Orlov <denorl2009@gmail.com> Link: https://lore.barebox.org/20230113140648.31572-1-denorl2009@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/ddr_spd.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/common/ddr_spd.c b/common/ddr_spd.c
index 52773178e7..dd3b8511e6 100644
--- a/common/ddr_spd.c
+++ b/common/ddr_spd.c
@@ -65,8 +65,8 @@ int ddr3_spd_check(const struct ddr3_spd_eeprom *spd)
char *p = (char *)spd;
int csum16;
int len;
- char crc_lsb; /* byte 126 */
- char crc_msb; /* byte 127 */
+ unsigned char crc_lsb; /* byte 126 */
+ unsigned char crc_msb; /* byte 127 */
/*
* SPD byte0[7] - CRC coverage
@@ -77,8 +77,8 @@ int ddr3_spd_check(const struct ddr3_spd_eeprom *spd)
len = !(spd->info_size_crc & 0x80) ? 126 : 117;
csum16 = crc_itu_t(0, p, len);
- crc_lsb = (char) (csum16 & 0xff);
- crc_msb = (char) (csum16 >> 8);
+ crc_lsb = csum16 & 0xff;
+ crc_msb = csum16 >> 8;
if (spd->crc[0] == crc_lsb && spd->crc[1] == crc_msb) {
return 0;
@@ -96,14 +96,14 @@ int ddr4_spd_check(const struct ddr4_spd_eeprom *spd)
char *p = (char *)spd;
int csum16;
int len;
- char crc_lsb; /* byte 126 */
- char crc_msb; /* byte 127 */
+ unsigned char crc_lsb; /* byte 126 */
+ unsigned char crc_msb; /* byte 127 */
len = 126;
csum16 = crc_itu_t(0, p, len);
- crc_lsb = (char) (csum16 & 0xff);
- crc_msb = (char) (csum16 >> 8);
+ crc_lsb = csum16 & 0xff;
+ crc_msb = csum16 >> 8;
if (spd->crc[0] != crc_lsb || spd->crc[1] != crc_msb) {
printf("SPD checksum unexpected.\n"
@@ -117,8 +117,8 @@ int ddr4_spd_check(const struct ddr4_spd_eeprom *spd)
len = 126;
csum16 = crc_itu_t(0, p, len);
- crc_lsb = (char) (csum16 & 0xff);
- crc_msb = (char) (csum16 >> 8);
+ crc_lsb = csum16 & 0xff;
+ crc_msb = csum16 >> 8;
if (spd->mod_section.uc[126] != crc_lsb ||
spd->mod_section.uc[127] != crc_msb) {