linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] mm/mempolicy: Fix memory leaks in mempolicy_sysfs_init()
@ 2025-03-12  7:56 Rakie Kim
  2025-03-12  7:56 ` [PATCH v2 2/4] mm/mempolicy: Support memory hotplug in weighted interleave Rakie Kim
                   ` (3 more replies)
  0 siblings, 4 replies; 27+ messages in thread
From: Rakie Kim @ 2025-03-12  7:56 UTC (permalink / raw)
  To: gourry
  Cc: akpm, linux-mm, linux-kernel, linux-cxl, joshua.hahnjy,
	dan.j.williams, ying.huang, kernel_team, honggyu.kim,
	yunjeong.mun, rakie.kim

Improper cleanup of sysfs attributes caused kobject and memory leaks when
initialization failed or nodes were removed.

This patch ensures proper deallocation of kobjects and memory, preventing
resource leaks and improving stability.

Fixes: dce41f5ae253 ("mm/mempolicy: implement the sysfs-based weighted_interleave interface")
Signed-off-by: Rakie Kim <rakie.kim@sk.com>
---
 mm/mempolicy.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index bbaadbeeb291..1691748badb2 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -3541,39 +3541,40 @@ static int __init mempolicy_sysfs_init(void)
 	int err;
 	static struct kobject *mempolicy_kobj;
 
-	mempolicy_kobj = kzalloc(sizeof(*mempolicy_kobj), GFP_KERNEL);
-	if (!mempolicy_kobj) {
+	node_attrs = kcalloc(nr_node_ids, sizeof(struct iw_node_attr *),
+			     GFP_KERNEL);
+	if (!node_attrs) {
 		err = -ENOMEM;
 		goto err_out;
 	}
 
-	node_attrs = kcalloc(nr_node_ids, sizeof(struct iw_node_attr *),
-			     GFP_KERNEL);
-	if (!node_attrs) {
+	mempolicy_kobj = kzalloc(sizeof(*mempolicy_kobj), GFP_KERNEL);
+	if (!mempolicy_kobj) {
 		err = -ENOMEM;
-		goto mempol_out;
+		goto node_out;
 	}
 
 	err = kobject_init_and_add(mempolicy_kobj, &mempolicy_ktype, mm_kobj,
 				   "mempolicy");
-	if (err)
-		goto node_out;
+	if (err) {
+		kobject_put(mempolicy_kobj);
+		goto err_out;
+	}
 
 	err = add_weighted_interleave_group(mempolicy_kobj);
 	if (err) {
-		pr_err("mempolicy sysfs structure failed to initialize\n");
 		kobject_put(mempolicy_kobj);
-		return err;
+		goto err_out;
 	}
 
-	return err;
+	return 0;
+
 node_out:
 	kfree(node_attrs);
-mempol_out:
-	kfree(mempolicy_kobj);
 err_out:
-	pr_err("failed to add mempolicy kobject to the system\n");
+	pr_err("mempolicy sysfs structure failed to initialize\n");
 	return err;
+
 }
 
 late_initcall(mempolicy_sysfs_init);

base-commit: 80e54e84911a923c40d7bee33a34c1b4be148d7a
-- 
2.34.1



^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2025-03-17  8:24 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-12  7:56 [PATCH v2 1/4] mm/mempolicy: Fix memory leaks in mempolicy_sysfs_init() Rakie Kim
2025-03-12  7:56 ` [PATCH v2 2/4] mm/mempolicy: Support memory hotplug in weighted interleave Rakie Kim
2025-03-12 16:03   ` Gregory Price
2025-03-13  6:33     ` Rakie Kim
2025-03-13 16:23       ` Gregory Price
2025-03-13 22:36         ` David Hildenbrand
2025-03-14  6:00           ` Rakie Kim
2025-03-14  9:17             ` David Hildenbrand
2025-03-17  8:23               ` Rakie Kim
2025-03-12  7:56 ` [PATCH v2 3/4] mm/mempolicy: Enable sysfs support for " Rakie Kim
2025-03-12 16:14   ` Gregory Price
2025-03-13  6:34     ` Rakie Kim
2025-03-13 16:40       ` Gregory Price
2025-03-14  6:35         ` Rakie Kim
2025-03-12  7:56 ` [PATCH v2 4/4] mm/mempolicy: Fix duplicate node addition in sysfs for " Rakie Kim
2025-03-12 15:04   ` Joshua Hahn
2025-03-13  6:34     ` Rakie Kim
2025-03-13 16:42   ` Gregory Price
2025-03-14  6:35     ` Rakie Kim
2025-03-12 15:49 ` [PATCH v2 1/4] mm/mempolicy: Fix memory leaks in mempolicy_sysfs_init() Gregory Price
2025-03-13  6:31   ` Rakie Kim
2025-03-13 15:52     ` Gregory Price
2025-03-14  7:44       ` Rakie Kim
2025-03-14 10:55       ` Jonathan Cameron
2025-03-14 13:42         ` Gregory Price
2025-03-17  8:24           ` Rakie Kim
2025-03-17  8:24         ` Rakie Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox