@@ -743,6 +743,7 @@ int hibernate(void)
}
Free_bitmaps:
+ free_image_memory_bitmaps();
free_basic_memory_bitmaps();
Thaw:
unlock_device_hotplug();
@@ -108,6 +108,7 @@ static inline void hibernate_image_size_init(void) {}
extern int create_basic_memory_bitmaps(void);
extern void free_basic_memory_bitmaps(void);
+extern void free_image_memory_bitmaps(void);
extern int hibernate_preallocate_memory(void);
extern void clear_free_pages(void);
@@ -1441,6 +1441,46 @@ static void copy_data_pages(struct memory_bitmap *copy_bm,
*/
static struct memory_bitmap copy_bm;
+/* Helper functions used for the shrinking of memory. */
+
+#define GFP_IMAGE (GFP_KERNEL | __GFP_NOWARN)
+
+/**
+ * create_image_memory_bitmaps - Create bitmaps to hold image page information.
+ *
+ */
+int create_image_memory_bitmaps(void)
+{
+ int error = 0;
+
+ error = memory_bm_create(&orig_bm, GFP_IMAGE, PG_ANY);
+ if (error)
+ goto err_out;
+
+ memset(©_bm, 0, sizeof(struct memory_bitmap));
+ error = memory_bm_create(©_bm, GFP_IMAGE, PG_ANY);
+ if (error) {
+ memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR);
+ goto err_out;
+ }
+ return 0;
+err_out:
+ return -ENOMEM;
+}
+
+/**
+ * free_image_memory_bitmaps - Free memory bitmaps holding image page information.
+ *
+ */
+void free_image_memory_bitmaps(void)
+{
+ if(copy_bm.p_list) {
+ memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR);
+ memory_bm_free(©_bm, PG_UNSAFE_CLEAR);
+ pr_debug("PM: Image memory bitmaps freed\n");
+ }
+}
+
/**
* swsusp_free - Free pages allocated for hibernation image.
*
@@ -1492,10 +1532,6 @@ void swsusp_free(void)
hibernate_restore_protection_end();
}
-/* Helper functions used for the shrinking of memory. */
-
-#define GFP_IMAGE (GFP_KERNEL | __GFP_NOWARN)
-
/**
* preallocate_image_pages - Allocate a number of pages for hibernation image.
* @nr_pages: Number of page frames to allocate.
@@ -1695,11 +1731,7 @@ int hibernate_preallocate_memory(void)
printk(KERN_INFO "PM: Preallocating image memory... ");
start = ktime_get();
- error = memory_bm_create(&orig_bm, GFP_IMAGE, PG_ANY);
- if (error)
- goto err_out;
-
- error = memory_bm_create(©_bm, GFP_IMAGE, PG_ANY);
+ error = create_image_memory_bitmaps();
if (error)
goto err_out;