mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-31 06:14:39 +01:00
firmware: Fix a reference count leak.
kobject_init_and_add() takes reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Callback function fw_cfg_sysfs_release_entry() in kobject_put() can handle the pointer "entry" properly. Signed-off-by: Qiushi Wu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
This commit is contained in:
1 parent
92ed301919
commit
fe3c606843
1 file changed
+4
-3
@@ -605,8 +605,10 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
|
||||
/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
|
||||
err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,
|
||||
fw_cfg_sel_ko, "%d", entry->select);
|
||||
if (err)
|
||||
goto err_register;
|
||||
if (err) {
|
||||
kobject_put(&entry->kobj);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* add raw binary content access */
|
||||
err = sysfs_create_bin_file(&entry->kobj, &fw_cfg_sysfs_attr_raw);
|
||||
@@ -622,7 +624,6 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
|
||||
|
||||
err_add_raw:
|
||||
kobject_del(&entry->kobj);
|
||||
err_register:
|
||||
kfree(entry);
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user