aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2009-10-07 16:37:35 -0400
committerRafael J. Wysocki <rjw@sisk.pl>2009-11-03 05:01:46 -0500
commit76b57e613f6006ff525a17876c89326d127cadc9 (patch)
tree244d876f24581fb40d1900003c55b1c7ca5abb91 /kernel
parent9905d1b411946fb3fb228e8c6529fd94afda8a92 (diff)
PM / Hibernate: Fix blkdev refleaks
While cruising through the swsusp code I found few blkdev reference leaks of resume_bdev. swsusp_read: remove blkdev_put altogether. Some fail paths do not do that. swsusp_check: make sure we always put a reference on fail paths software_resume: all fail paths between swsusp_check and swsusp_read omit swsusp_close. Add it in those cases. And since swsusp_read doesn't drop the reference anymore, do it here unconditionally. [rjw: Fixed a small coding style issue.] Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/power/hibernate.c11
-rw-r--r--kernel/power/swap.c8
2 files changed, 12 insertions, 7 deletions
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 04b3a83d686f..04a9e90d248f 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -693,21 +693,22 @@ static int software_resume(void)
693 /* The snapshot device should not be opened while we're running */ 693 /* The snapshot device should not be opened while we're running */
694 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { 694 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
695 error = -EBUSY; 695 error = -EBUSY;
696 swsusp_close(FMODE_READ);
696 goto Unlock; 697 goto Unlock;
697 } 698 }
698 699
699 pm_prepare_console(); 700 pm_prepare_console();
700 error = pm_notifier_call_chain(PM_RESTORE_PREPARE); 701 error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
701 if (error) 702 if (error)
702 goto Finish; 703 goto close_finish;
703 704
704 error = usermodehelper_disable(); 705 error = usermodehelper_disable();
705 if (error) 706 if (error)
706 goto Finish; 707 goto close_finish;
707 708
708 error = create_basic_memory_bitmaps(); 709 error = create_basic_memory_bitmaps();
709 if (error) 710 if (error)
710 goto Finish; 711 goto close_finish;
711 712
712 pr_debug("PM: Preparing processes for restore.\n"); 713 pr_debug("PM: Preparing processes for restore.\n");
713 error = prepare_processes(); 714 error = prepare_processes();
@@ -719,6 +720,7 @@ static int software_resume(void)
719 pr_debug("PM: Reading hibernation image.\n"); 720 pr_debug("PM: Reading hibernation image.\n");
720 721
721 error = swsusp_read(&flags); 722 error = swsusp_read(&flags);
723 swsusp_close(FMODE_READ);
722 if (!error) 724 if (!error)
723 hibernation_restore(flags & SF_PLATFORM_MODE); 725 hibernation_restore(flags & SF_PLATFORM_MODE);
724 726
@@ -737,6 +739,9 @@ static int software_resume(void)
737 mutex_unlock(&pm_mutex); 739 mutex_unlock(&pm_mutex);
738 pr_debug("PM: Resume from disk failed.\n"); 740 pr_debug("PM: Resume from disk failed.\n");
739 return error; 741 return error;
742close_finish:
743 swsusp_close(FMODE_READ);
744 goto Finish;
740} 745}
741 746
742late_initcall(software_resume); 747late_initcall(software_resume);
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index b101cdc4df3f..a4388624ed98 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -572,8 +572,6 @@ int swsusp_read(unsigned int *flags_p)
572 error = load_image(&handle, &snapshot, header->pages - 1); 572 error = load_image(&handle, &snapshot, header->pages - 1);
573 release_swap_reader(&handle); 573 release_swap_reader(&handle);
574 574
575 blkdev_put(resume_bdev, FMODE_READ);
576
577 if (!error) 575 if (!error)
578 pr_debug("PM: Image successfully loaded\n"); 576 pr_debug("PM: Image successfully loaded\n");
579 else 577 else
@@ -596,7 +594,7 @@ int swsusp_check(void)
596 error = bio_read_page(swsusp_resume_block, 594 error = bio_read_page(swsusp_resume_block,
597 swsusp_header, NULL); 595 swsusp_header, NULL);
598 if (error) 596 if (error)
599 return error; 597 goto put;
600 598
601 if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) { 599 if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) {
602 memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10); 600 memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10);
@@ -604,8 +602,10 @@ int swsusp_check(void)
604 error = bio_write_page(swsusp_resume_block, 602 error = bio_write_page(swsusp_resume_block,
605 swsusp_header, NULL); 603 swsusp_header, NULL);
606 } else { 604 } else {
607 return -EINVAL; 605 error = -EINVAL;
608 } 606 }
607
608put:
609 if (error) 609 if (error)
610 blkdev_put(resume_bdev, FMODE_READ); 610 blkdev_put(resume_bdev, FMODE_READ);
611 else 611 else