Skip to content

Commit 6e00716

Browse files
jeff-lien-sndkigaw
authored andcommitted
ocp: handle C9 log page read fails
This change will fix a seg fault that occurs when reading the OCP C9 log pages fails. Signed-off-by: jeff-lien-sndk <[email protected]>
1 parent 7d8d11d commit 6e00716

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

plugins/ocp/ocp-nvme.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,23 +1333,30 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl,
13331333

13341334
ret = ocp_get_log_simple(hdl, OCP_LID_TELSLG, total_log_page_sz, pC9_string_buffer);
13351335
} else {
1336-
fprintf(stderr, "ERROR : OCP : Unable to read C9 data.\n");
1336+
fprintf(stderr, "ERROR : OCP : Unable to read C9 data, ret: %d.\n", ret);
1337+
return ret;
13371338
}
13381339

13391340
if (save_bin) {
13401341
fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
13411342
if (fd < 0) {
13421343
fprintf(stderr, "Failed to open output file %s: %s!\n", output_file,
13431344
nvme_strerror(errno));
1344-
return fd;
1345+
ret = fd;
1346+
goto free;
13451347
}
13461348

13471349
ret = write(fd, (void *)pC9_string_buffer, total_log_page_sz);
13481350
if (ret != total_log_page_sz)
1349-
fprintf(stderr, "Failed to flush all data to file!\n");
1351+
fprintf(stderr, "Failed to flush all data to file! ret: %d\n", ret);
1352+
else
1353+
/* all data written, set ret = SUCCESS */
1354+
ret = 0;
13501355
}
13511356

1352-
return 0;
1357+
free:
1358+
free(pC9_string_buffer);
1359+
return ret;
13531360
}
13541361

13551362
int parse_ocp_telemetry_log(struct ocp_telemetry_parse_options *options)

0 commit comments

Comments
 (0)