]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
ocp: fix to free hwcomp log desc memory allocated
authorTokunori Ikegami <ikegami.t@gmail.com>
Wed, 5 Feb 2025 15:30:12 +0000 (00:30 +0900)
committerDaniel Wagner <wagi@monom.org>
Fri, 7 Feb 2025 16:27:23 +0000 (17:27 +0100)
Since the desc pointer used _cleanup_free_ only set NULL value.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
[wagi: free buffer on error in get_hwcomp_log_data]
Signed-off-by: Daniel Wagner <wagi@kernel.org>
plugins/ocp/ocp-hardware-component-log.c

index 3c6890af835f33aed390ba52f74e299b67387509..e4a8e065cfb663b0d4cd1f8e0bf9e0f33fb1033a 100644 (file)
@@ -219,7 +219,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
        log->desc = calloc(1, args.len);
        if (!log->desc) {
                fprintf(stderr, "error: ocp: calloc: %s\n", strerror(errno));
-               return -1;
+               return -errno;
        }
 
        args.log = log->desc,
@@ -232,6 +232,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
        if (ret) {
                print_info_error("error: ocp: failed to get log page (hwcomp: %02X, ret: %d)\n",
                                 OCP_LID_HWCOMP, ret);
+               free(log->desc);
                return ret;
        }
 #endif /* HWCOMP_DUMMY */
@@ -241,12 +242,10 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
 
 static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list)
 {
-       _cleanup_free_ __u8 *desc = NULL;
-
        int ret;
        nvme_print_flags_t fmt;
        struct hwcomp_log log = {
-               .desc = (struct hwcomp_desc *)desc,
+               .desc = NULL,
        };
 
        ret = validate_output_format(nvme_cfg.output_format, &fmt);
@@ -264,6 +263,8 @@ static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list)
 
        ocp_show_hwcomp_log(&log, id, list, fmt);
 
+       free(log.desc);
+
        return 0;
 }