2021-03-22 13:32:26

by Lv Yunlong

[permalink] [raw]
Subject: [PATCH] firmware/dmi-sysfs: Fix a double free in dmi_sysfs_register_handle

In the case of DMI_ENTRY_SYSTEM_EVENT_LOG, it calls
dmi_system_event_log(entry). If dmi_system_event_log()
failed, it will free the entry->child and return err.

But in the out_err branch, the entry->child will be freed
again. My patch adds a new label "out_err1" to avoid freeing
entry->child twice.

Signed-off-by: Lv Yunlong <[email protected]>
---
drivers/firmware/dmi-sysfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c
index 8b8127fa8955..fd498f2037a8 100644
--- a/drivers/firmware/dmi-sysfs.c
+++ b/drivers/firmware/dmi-sysfs.c
@@ -622,16 +622,17 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
break;
}
if (*ret)
- goto out_err;
+ goto out_err1;

/* Create the raw binary file to access the entry */
*ret = sysfs_create_bin_file(&entry->kobj, &dmi_entry_raw_attr);
if (*ret)
- goto out_err;
+ goto out_err2;

return;
-out_err:
+out_err2:
kobject_put(entry->child);
+out_err1:
kobject_put(&entry->kobj);
return;
}
--
2.25.1