Skip to content

Commit 4906467

Browse files
ikegami-tigaw
authored andcommitted
ocp: fix to free hwcomp log desc memory allocated
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>
1 parent eea4913 commit 4906467

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plugins/ocp/ocp-hardware-component-log.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
219219
log->desc = calloc(1, args.len);
220220
if (!log->desc) {
221221
fprintf(stderr, "error: ocp: calloc: %s\n", strerror(errno));
222-
return -1;
222+
return -errno;
223223
}
224224

225225
args.log = log->desc,
@@ -232,6 +232,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
232232
if (ret) {
233233
print_info_error("error: ocp: failed to get log page (hwcomp: %02X, ret: %d)\n",
234234
OCP_LID_HWCOMP, ret);
235+
free(log->desc);
235236
return ret;
236237
}
237238
#endif /* HWCOMP_DUMMY */
@@ -241,12 +242,10 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
241242

242243
static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list)
243244
{
244-
_cleanup_free_ __u8 *desc = NULL;
245-
246245
int ret;
247246
nvme_print_flags_t fmt;
248247
struct hwcomp_log log = {
249-
.desc = (struct hwcomp_desc *)desc,
248+
.desc = NULL,
250249
};
251250

252251
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)
264263

265264
ocp_show_hwcomp_log(&log, id, list, fmt);
266265

266+
free(log.desc);
267+
267268
return 0;
268269
}
269270

0 commit comments

Comments
 (0)