From 60e476244d09302625a51fd92f3cad217a4adae9 Mon Sep 17 00:00:00 2001 From: jeff-lien-sndk Date: Tue, 10 Mar 2026 10:24:21 -0500 Subject: [PATCH] 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 --- plugins/ocp/ocp-nvme.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 2ec2d98b7c..a6feb03ef4 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -1333,7 +1333,8 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, ret = ocp_get_log_simple(hdl, OCP_LID_TELSLG, total_log_page_sz, pC9_string_buffer); } else { - fprintf(stderr, "ERROR : OCP : Unable to read C9 data.\n"); + fprintf(stderr, "ERROR : OCP : Unable to read C9 data, ret: %d.\n", ret); + return ret; } if (save_bin) { @@ -1341,15 +1342,21 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, if (fd < 0) { fprintf(stderr, "Failed to open output file %s: %s!\n", output_file, nvme_strerror(errno)); - return fd; + ret = fd; + goto free; } ret = write(fd, (void *)pC9_string_buffer, total_log_page_sz); if (ret != total_log_page_sz) - fprintf(stderr, "Failed to flush all data to file!\n"); + fprintf(stderr, "Failed to flush all data to file! ret: %d\n", ret); + else + /* all data written, set ret = SUCCESS */ + ret = 0; } - return 0; +free: + free(pC9_string_buffer); + return ret; } int parse_ocp_telemetry_log(struct ocp_telemetry_parse_options *options)