summaryrefslogtreecommitdiff
path: root/lib/dimm_spd.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dimm_spd.c')
-rw-r--r--lib/dimm_spd.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/lib/dimm_spd.c b/lib/dimm_spd.c
index 8b6927c..d496184 100644
--- a/lib/dimm_spd.c
+++ b/lib/dimm_spd.c
@@ -1340,11 +1340,10 @@ ipmi_spd_print(uint8_t *spd_data, int len)
printf(" Memory Type : %s\n",
val2str(spd_data[2], spd_memtype_vals));
-
+
if (spd_data[2] == 0x0B) /* DDR3 SDRAM */
{
int iPN;
- char *pchPN = spd_data+128;
int sdram_cap = 0;
int pri_bus_width = 0;
int sdram_width = 0;
@@ -1353,7 +1352,7 @@ ipmi_spd_print(uint8_t *spd_data, int len)
if (len < 148)
return -1; /* we need first 91 bytes to do our thing */
-
+
sdram_cap = ldexp(256,(spd_data[4]&15));
pri_bus_width = ldexp(8,(spd_data[8]&7));
@@ -1366,7 +1365,7 @@ ipmi_spd_print(uint8_t *spd_data, int len)
printf(" SDRAM Device Width : %d bits\n", sdram_width );
printf(" Number of Ranks : %d\n", ranks );
printf(" Memory size : %d MB\n", mem_size );
-
+
/* printf(" Memory Density : %s\n", val2str(spd_data[4]&15, ddr3_density_vals)); */
printf(" 1.5 V Nominal Op : %s\n", (((spd_data[6]&1) != 0) ? "No":"Yes" ) );
printf(" 1.35 V Nominal Op : %s\n", (((spd_data[6]&2) != 0) ? "No":"Yes" ) );
@@ -1417,16 +1416,15 @@ ipmi_spd_print(uint8_t *spd_data, int len)
}
- printf(" Manufacture Date : year %c%c week %c%c\n",
+ printf(" Manufacture Date : year %c%c week %c%c\n",
'0'+(spd_data[120]>>4), '0'+(spd_data[120]&15), '0'+(spd_data[121]>>4), '0'+(spd_data[121]&15) );
-
+
printf(" Serial Number : %02x%02x%02x%02x\n",
spd_data[122], spd_data[123], spd_data[124], spd_data[125]);
-
+
printf(" Part Number : ");
- for (iPN=0; iPN < 19; iPN++)
- {
- printf( "%c", *pchPN++ );
+ for (iPN = 128; iPN < 146; iPN++) {
+ printf("%c", spd_data[iPN]);
}
printf("\n");
} else if (spd_data[2] == 0x0C) /* DDR4 SDRAM */
@@ -1552,7 +1550,7 @@ ipmi_spd_print(uint8_t *spd_data, int len)
val2str(spd_data[8], spd_voltage_vals));
printf(" Error Detect/Cor : %s\n",
val2str(spd_data[11], spd_config_vals));
-
+
/* handle jedec table bank continuation values */
printf(" Manufacturer : ");
if (spd_data[64] != 0x7f)
@@ -1603,7 +1601,7 @@ ipmi_spd_print(uint8_t *spd_data, int len)
part[18] = 0;
printf(" Part Number : %s\n", part);
}
-
+
printf(" Serial Number : %02x%02x%02x%02x\n",
spd_data[95], spd_data[96], spd_data[97], spd_data[98]);
}
@@ -1622,8 +1620,10 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
struct ipmi_rs * rsp;
struct ipmi_rq req;
struct fru_info fru;
- uint8_t *spd_data, msg_data[4];
- int len, offset;
+ uint8_t *spd_data = NULL;
+ uint8_t msg_data[4];
+ uint32_t len, offset;
+ int rc = -1;
msg_data[0] = id;
@@ -1634,14 +1634,14 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
req.msg.data_len = 1;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
- return -1;
+ goto end;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
- return -1;
+ goto end;
}
fru.size = (rsp->data[1] << 8) | rsp->data[0];
@@ -1653,15 +1653,15 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
if (fru.size < 1) {
lprintf(LOG_ERR, " Invalid FRU size %d", fru.size);
- return -1;
+ goto end;
}
spd_data = malloc(fru.size);
- if (spd_data == NULL) {
+ if (!spd_data) {
printf(" Unable to malloc memory for spd array of size=%d\n",
fru.size);
- return -1;
+ goto end;
}
memset(&req, 0, sizeof(req));
@@ -1679,34 +1679,39 @@ ipmi_spd_print_fru(struct ipmi_intf * intf, uint8_t id)
msg_data[3] = FRU_DATA_RQST_SIZE;
rsp = intf->sendrecv(intf, &req);
- if (rsp == NULL) {
+ if (!rsp) {
printf(" Device not present (No Response)\n");
- free(spd_data);
- spd_data = NULL;
- return -1;
+ goto end;
}
- if (rsp->ccode > 0) {
+ if (rsp->ccode) {
printf(" Device not present (%s)\n",
val2str(rsp->ccode, completion_code_vals));
- free(spd_data);
- spd_data = NULL;
/* Timeouts are acceptable. No DIMM in the socket */
if (rsp->ccode == 0xc3)
- return 1;
+ rc = 1;
- return -1;
+ goto end;
}
len = rsp->data[0];
+ if(rsp->data_len < 1
+ || len > rsp->data_len - 1
+ || len > fru.size - offset)
+ {
+ printf(" Not enough buffer size");
+ goto end;
+ }
memcpy(&spd_data[offset], rsp->data + 1, len);
offset += len;
} while (offset < fru.size);
/* now print spd info */
ipmi_spd_print(spd_data, offset);
- free(spd_data);
- spd_data = NULL;
+ rc = 0;
- return 0;
+end:
+ free_n(&spd_data);
+
+ return rc;
}