blob: fb68725e31da7dcbc4ff519e10c5a0a1368388c6 [file] [log] [blame]
From 1bf2e6fe4ba71aed8ba6d24a0ed040eaf0181e62 Mon Sep 17 00:00:00 2001
From: YueHaibing <yuehaibing@huawei.com>
Date: Sat, 28 Dec 2019 19:54:55 +0800
Subject: [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs()
commit f6d061d617124abbd55396a3bc37b9bf7d33233c upstream.
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: Paul Gortmaker <paul.gortmaker@windriver.com>
diff --git a/kernel/module.c b/kernel/module.c
index b11d200aebbd..dbea27533af1 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1727,6 +1727,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;
}
--
2.7.4