[Skiboot] [PATCH] opal-prd: Fix missing cleanups in chip_init
Miaoqian Lin
linmq006 at gmail.com
Mon Sep 19 18:46:45 AEST 2022
1. The function calls opendir() but missing the corresponding
closedir() before exit the function.
2. asprintf() alloc memory for path, we need to free it after use.
Add missing closedir() and free() to fix it.
Signed-off-by: Miaoqian Lin <linmq006 at gmail.com>
---
external/opal-prd/opal-prd.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c
index 1c610da4c0b6..ed47260d23bd 100644
--- a/external/opal-prd/opal-prd.c
+++ b/external/opal-prd/opal-prd.c
@@ -1290,22 +1290,28 @@ static int chip_init(void)
dirent->d_name);
if (rc < 0) {
pr_log(LOG_ERR, "FW: Failed to create chip-id path");
+ closedir(dir);
return -1;
}
rc = open_and_read(path, &buf, &len);
if (rc) {
pr_log(LOG_ERR, "FW; Failed to read chipid");
+ closedir(dir);
+ free(path);
return -1;
}
chipid = buf;
chips[nr_chips++] = be32toh(*chipid);
+ free(path);
}
pr_log(LOG_DEBUG, "FW: Chip init");
for (i = 0; i < nr_chips; i++)
pr_log(LOG_DEBUG, "FW: Chip 0x%lx", chips[i]);
+ closedir(dir);
+
return 0;
}
--
2.25.1
More information about the Skiboot
mailing list