firmware: dmi-sysfs: fix error handling in dmi_system_event_log()
PATCH 1/1 firmware: dmi-sysfs: fix error handling in dmi_system_event_log()
Once kobject_init_and_add() has been called, the error path should call kobject_put() to decrement the reference count for cleanup. Freeing the object directly with kfree() bypasses the kobject cleanup path.
If sysfs_create_bin_file() fails, kobject_del() removes the kobject from sysfs, but kobject_put() is still needed to drop the reference count and release the object.
Fix this by replacing kfree() with kobject_put(). Then the object can be freed by the release callback through kobject_cleanup().
This issue was found by a static analysis tool I am developing.
Fixes 925a1da7477f ("firmware: Break out system_event_log in dmi-sysfs")
Signed-off-by Guangshuo Li <[email protected]>
--- drivers/firmware/dmi-sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/firmware/dmi-sysfs.c +3 -3
@@ -459,7 +459,7 @@ static int dmi_system_event_log(struct dmi_sysfs_entry *entry) &entry->kobj, "system_event_log");if (ret) - goto out_free; + goto out_put; ret =sysfs_create_bin_file (entry->child, &bin_attr_raw_event_log);if (ret)
@@ -469,8 +469,8 @@ static int dmi_system_event_log(struct dmi_sysfs_entry *entry) out_del:kobject_del (entry->child); -out_free: -kfree (entry->child); +out_put: +kobject_put (entry->child);return ret; }
Signature · 1 line
2.43.0