Skip to content

Commit 83ea637

Browse files
QiushiWugregkh
authored andcommitted
firmware: Fix a reference count leak.
[ Upstream commit fe3c606 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 01fdcb8 commit 83ea637

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/firmware/qemu_fw_cfg.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,10 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
605605
/* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
606606
err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,
607607
fw_cfg_sel_ko, "%d", entry->select);
608-
if (err)
609-
goto err_register;
608+
if (err) {
609+
kobject_put(&entry->kobj);
610+
return err;
611+
}
610612

611613
/* add raw binary content access */
612614
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)
622624

623625
err_add_raw:
624626
kobject_del(&entry->kobj);
625-
err_register:
626627
kfree(entry);
627628
return err;
628629
}

0 commit comments

Comments
 (0)