diff mbox series

[4.19,003/195] kernel/module: Fix memleak in module_add_modinfo_attrs()

Message ID 20200210122306.091895826@linuxfoundation.org
State New
Headers show
Series None | expand

Commit Message

Greg KH Feb. 10, 2020, 12:31 p.m. UTC
From: YueHaibing <yuehaibing@huawei.com>

[ Upstream commit f6d061d617124abbd55396a3bc37b9bf7d33233c ]

In module_add_modinfo_attrs() if sysfs_create_file() fails
on the first iteration of the loop (so i = 0), we forget to
free the modinfo_attrs.

Fixes: bc6f2a757d52 ("kernel/module: Fix mem leak in module_add_modinfo_attrs")
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/module.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/kernel/module.c b/kernel/module.c
index d3aaec62c1423..70a75a7216abb 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1729,6 +1729,8 @@  static int module_add_modinfo_attrs(struct module *mod)
 error_out:
 	if (i > 0)
 		module_remove_modinfo_attrs(mod, --i);
+	else
+		kfree(mod->modinfo_attrs);
 	return error;
 }