[PATCH] fw_cfg: Fix memory leak in fw_cfg_register_file

Miaoqian Lin
2021-11-16T11:43:01Z

When kobject_init_and_add() fails, entry should be freed just like
when sysfs_create_bin_file() fails.

Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/firmware/qemu_fw_cfg.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 172c751a4f6c..0f404777f016 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -608,6 +608,7 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
fw_cfg_sel_ko, "%d", entry->select);
if (err) {
kobject_put(&entry->kobj);
+ kfree(entry);
return err;
}

--
2.17.1