mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] PM: hibernate: Fix potential memory leak in hibernate_preallocate_memory() and prepare_highmem_image()
@ 2022-09-05  8:35 Jianglei Nie
  2022-09-05 17:33 ` kernel test robot
  2022-09-05 18:24 ` kernel test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Jianglei Nie @ 2022-09-05  8:35 UTC (permalink / raw)
  To: rafael; +Cc: linux-pm, linux-kernel, Jianglei Nie

hibernate_preallocate_memory() and prepare_highmem_image() allocates
memory chunk with memory_bm_create(). When the function gets some error
after memory_bm_create(), relavent memory should be released with
memory_bm_free().

Fix it by calling memory_bm_free() at the right time.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 kernel/power/snapshot.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 2a406753af90..15345ad0b319 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1752,6 +1752,7 @@ int hibernate_preallocate_memory(void)
 
 	error = memory_bm_create(&copy_bm, GFP_IMAGE, PG_ANY);
 	if (error) {
+		memory_bm_free(orig_bm, PG_UNSAFE_CLEAR);
 		pr_err("Cannot allocate copy bitmap\n");
 		goto err_out;
 	}
@@ -2335,8 +2336,10 @@ static int prepare_highmem_image(struct memory_bitmap *bm,
 	if (memory_bm_create(bm, GFP_ATOMIC, PG_SAFE))
 		return -ENOMEM;
 
-	if (get_highmem_buffer(PG_SAFE))
+	if (get_highmem_buffer(PG_SAFE)) {
+		memory_bm_free(bm, PG_UNSAFE_CLEAR);
 		return -ENOMEM;
+	}
 
 	to_alloc = count_free_highmem_pages();
 	if (to_alloc > *nr_highmem_p)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] PM: hibernate: Fix potential memory leak in hibernate_preallocate_memory() and prepare_highmem_image()
@ 2022-09-07  6:43 Jianglei Nie
  2022-10-25 15:57 ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Jianglei Nie @ 2022-09-07  6:43 UTC (permalink / raw)
  To: rafael; +Cc: linux-pm, linux-kernel, Jianglei Nie

hibernate_preallocate_memory() and prepare_highmem_image() allocates
memory chunk with memory_bm_create(). When the function gets some error
after memory_bm_create(), relavent memory should be released with
memory_bm_free().

Fix it by calling memory_bm_free() at the right time.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 kernel/power/snapshot.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 2a406753af90..e5ec204ebe22 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1752,6 +1752,7 @@ int hibernate_preallocate_memory(void)
 
 	error = memory_bm_create(&copy_bm, GFP_IMAGE, PG_ANY);
 	if (error) {
+		memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR);
 		pr_err("Cannot allocate copy bitmap\n");
 		goto err_out;
 	}
@@ -2335,8 +2336,10 @@ static int prepare_highmem_image(struct memory_bitmap *bm,
 	if (memory_bm_create(bm, GFP_ATOMIC, PG_SAFE))
 		return -ENOMEM;
 
-	if (get_highmem_buffer(PG_SAFE))
+	if (get_highmem_buffer(PG_SAFE)) {
+		memory_bm_free(bm, PG_UNSAFE_CLEAR);
 		return -ENOMEM;
+	}
 
 	to_alloc = count_free_highmem_pages();
 	if (to_alloc > *nr_highmem_p)
-- 
2.25.1


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

end of thread, other threads:[~2022-10-25 15:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05  8:35 [PATCH] PM: hibernate: Fix potential memory leak in hibernate_preallocate_memory() and prepare_highmem_image() Jianglei Nie
2022-09-05 17:33 ` kernel test robot
2022-09-05 18:24 ` kernel test robot
2022-09-07  6:43 Jianglei Nie
2022-10-25 15:57 ` Rafael J. Wysocki

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

all inboxes | Powered by JetHome®