Skip to content

Commit a404eb3

Browse files
nvme: plot eye chart and hex dumping VS eye data
-Addressing review comments Signed-off-by: Sivaprasad Gutha <[email protected]>
1 parent d69c312 commit a404eb3

2 files changed

Lines changed: 38 additions & 32 deletions

File tree

nvme-print-json.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,11 +2121,11 @@ static void json_boot_part_log(void *bp_log, const char *devname,
21212121

21222122
/* Printable Eye string is allocated and returned, caller must free */
21232123
static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
2124-
struct json_object *r)
2124+
struct json_object *r)
21252125
{
21262126
char *eye = (char *)lane->eye_desc;
2127-
uint16_t nrows = lane->nrows;
2128-
uint16_t ncols = lane->ncols;
2127+
uint16_t nrows = le16_to_cpu(lane->nrows);
2128+
uint16_t ncols = le16_to_cpu(lane->ncols);
21292129

21302130
if (nrows == 0 || ncols == 0)
21312131
return NULL;
@@ -2139,11 +2139,19 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21392139

21402140
struct json_object *eye_array = json_create_array();
21412141

2142+
if (!eye_array) {
2143+
free(printable);
2144+
return NULL;
2145+
}
2146+
21422147
for (int i = 0; i < nrows; i++) {
21432148
char *row = malloc(ncols + 1);
21442149

2145-
if (!row)
2146-
continue;
2150+
if (!row) {
2151+
// Cleanup on failure
2152+
free(printable_start);
2153+
return NULL;
2154+
}
21472155

21482156
for (int j = 0; j < ncols; j++) {
21492157
char ch = eye[i * ncols + j];
@@ -2160,7 +2168,7 @@ static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
21602168

21612169
*printable = '\0';
21622170

2163-
obj_add_array(r, "printable_eye_rows", eye_array);
2171+
obj_add_array(r, "printable_eye", eye_array);
21642172

21652173
return printable_start;
21662174
}
@@ -2197,26 +2205,25 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
21972205

21982206
if (desc->edlen == 0)
21992207
continue;
2200-
else {
2201-
/* Hex dump Vendor Specific Eye Data*/
2202-
vsdata = (unsigned char *)malloc(desc->edlen);
2203-
vsdataoffset = (desc->nrows * desc->ncols) +
2204-
sizeof(struct nvme_eom_lane_desc);
2205-
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
2206-
char *hexstr = malloc(desc->edlen * 3 + 1); // 2 hex chars + space per byte
22072208

2208-
if (!hexstr)
2209-
return;
2209+
/* Hex dump Vendor Specific Eye Data*/
2210+
vsdataoffset = (le16_to_cpu(desc->nrows) * le16_to_cpu(desc->ncols)) +
2211+
sizeof(struct nvme_eom_lane_desc);
2212+
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
2213+
// 2 hex chars + space per byte
2214+
_cleanup_free_ char *hexstr = malloc(le16_to_cpu(desc->edlen) * 3 + 1);
22102215

2211-
char *p = hexstr;
2216+
if (!hexstr)
2217+
return;
22122218

2213-
for (int offset = 0; offset < desc->edlen; offset++)
2214-
p += sprintf(p, "%02X ", vsdata[offset]);
2215-
*(p - 1) = '\0'; // remove trailing space
2219+
char *hexdata = hexstr;
2220+
2221+
for (int offset = 0; offset < le16_to_cpu(desc->edlen); offset++)
2222+
hexdata += sprintf(hexdata, "%02X ", vsdata[offset]);
2223+
*(hexdata - 1) = '\0'; // remove trailing space
2224+
2225+
obj_add_str(jdesc, "vsdata_hex", hexstr);
22162226

2217-
obj_add_str(jdesc, "vsdata_hex", hexstr);
2218-
free(hexstr);
2219-
}
22202227
array_add_obj(descs, jdesc);
22212228

22222229
p += log->dsize;

nvme-print-stdout.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,15 @@ static void stdout_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log)
811811
/* Eye Data field is vendor specific */
812812
if (desc->edlen == 0)
813813
continue;
814-
else {
815-
/* Hex dump Vendor Specific Eye Data */
816-
vsdata = (unsigned char *)malloc(desc->edlen);
817-
vsdataoffset = (desc->nrows * desc->ncols) +
818-
sizeof(struct nvme_eom_lane_desc);
819-
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
820-
printf("Eye Data:\n");
821-
d(vsdata, desc->edlen, 16, 1);
822-
printf("\n");
823-
}
814+
815+
/* Hex dump Vendor Specific Eye Data */
816+
vsdata = malloc(desc->edlen);
817+
vsdataoffset = (desc->nrows * desc->ncols) +
818+
sizeof(struct nvme_eom_lane_desc);
819+
vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
820+
printf("Eye Data:\n");
821+
d(vsdata, desc->edlen, 16, 1);
822+
printf("\n");
824823

825824
p += log->dsize;
826825
}

0 commit comments

Comments
 (0)