Skip to contentSkip to conversation

ge: common: vpd_reader: fix errloc array size in verify_bch()

PATCH In review Md Shofiqul Islam 2 participants 2 messages Jun 30

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ge: common: vpd_reader: fix errloc array size in verify_bch()

errloc stores bit positions of errors returned by decode_bch(). The maximum number of correctable errors is ecc_bits, so errloc must have ecc_bits entries. The array was allocated with data_length entries instead, which is the number of EEPROM data bytes -- orders of magnitude larger than needed and incorrect.

Fixes b418dfe16e62 ("board: ge: make VPD code common")
---
 board/ge/common/vpd_reader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/ge/common/vpd_reader.c +1 -1
index 2422db38013..b3f9e96615d 100644
@@ -66,7 +66,7 @@ static int verify_bch(int ecc_bits, unsigned int prim_poly, u8 *data,
 		return -1;
 	}
 
-	unsigned int *errloc = (unsigned int *)calloc(data_length,
+	unsigned int *errloc = (unsigned int *)calloc(ecc_bits,
 						      sizeof(unsigned int));
 	int errors = decode_bch(bch, data, data_length, ecc, NULL, NULL,
 				errloc);
Signature · 1 line
2.51.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Md Shofiqul Islam

errloc stores bit positions of errors returned by decode_bch(). The maximum number of correctable errors is ecc_bits, so errloc must have ecc_bits entries. The array was allocated with data_length entries instead, which is the number of EEPROM data bytes -- orders of magnitude larger than needed and incorrect.

Good catch, thanks for fixing this.

Quoted 3 lines
Fixes b418dfe16e62 ("board: ge: make VPD code common")
Quoted 20 lines
---
 board/ge/common/vpd_reader.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/ge/common/vpd_reader.c +1 -2
index 2422db38013..b3f9e96615d 100644
@@ -66,7 +66,7 @@ static int verify_bch(int ecc_bits, unsigned int prim_poly, u8 *data,
                return -1;
        }
 
-       unsigned int *errloc = (unsigned int *)calloc(data_length,
+       unsigned int *errloc = (unsigned int *)calloc(ecc_bits,
                                                      sizeof(unsigned int));
        int errors = decode_bch(bch, data, data_length, ecc, NULL, NULL,
                                errloc);
--

2.51.1