Skip to content

Commit

Permalink
PM / Hibernate: Do not leak memory in error/test code paths
Browse files Browse the repository at this point in the history
The hibernation core code forgets to release memory preallocated
for hibernation if there's an error in its early stages or if test
modes causing hibernation_snapshot() to return early are used.  This
causes the system to be hardly usable, because the amount of
preallocated memory is usually huge.  Fix this problem.

Reported-by: Srivatsa S. Bhat <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
Acked-by: Srivatsa S. Bhat <[email protected]>
  • Loading branch information
rjwysocki committed Nov 23, 2011
1 parent f10cdea commit bb58dd5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kernel/power/hibernate.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ int hibernation_snapshot(int platform_mode)

error = freeze_kernel_threads();
if (error)
goto Close;
goto Cleanup;

if (hibernation_test(TEST_FREEZER) ||
hibernation_testmode(HIBERNATION_TESTPROC)) {
Expand All @@ -357,12 +357,14 @@ int hibernation_snapshot(int platform_mode)
* successful freezer test.
*/
freezer_test_done = true;
goto Close;
goto Cleanup;
}

error = dpm_prepare(PMSG_FREEZE);
if (error)
goto Complete_devices;
if (error) {
dpm_complete(msg);
goto Cleanup;
}

suspend_console();
pm_restrict_gfp_mask();
Expand Down Expand Up @@ -391,8 +393,6 @@ int hibernation_snapshot(int platform_mode)
pm_restore_gfp_mask();

resume_console();

Complete_devices:
dpm_complete(msg);

Close:
Expand All @@ -402,6 +402,10 @@ int hibernation_snapshot(int platform_mode)
Recover_platform:
platform_recover(platform_mode);
goto Resume_devices;

Cleanup:
swsusp_free();
goto Close;
}

/**
Expand Down

0 comments on commit bb58dd5

Please sign in to comment.