Skip to contentSkip to conversation

firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle

PATCH New Miaoqian Lin 1 participant 1 message May 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle

kobject_init_and_add() takes reference even when it fails. According to the doc of kobject_init_and_add()

If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object.

Fix this issue by calling kobject_put().

Fixes 948af1f0bbc8 ("firmware: Basic dmi-sysfs support")
---
 drivers/firmware/dmi-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/dmi-sysfs.c +1 -1
index 3a353776bd34..66727ad3361b 100644
@@ -604,7 +604,7 @@ static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
 				    "%d-%d", dh->type, entry->instance);
 
 	if (*ret) {
-		kfree(entry);
+		kobject_put(&entry->kobj);
 		return;
 	}
 
Signature · 1 line
2.25.1