swsusp fixes
Subsystems (2)
cover swsusp fixes
Hi,
The following patches fix some bugs I've found recently in swsusp. They don't affect the mainline code.
Please apply.
Greetings,
Rafael
PATCH 1/2 swsusp: userland interface fixes
Fix two bugs in the swsusp userland interface:
1) Prevent the SNAPSHOT_FREE_SWAP_PAGES ioctl from leaking swap pages due to the wrong condition.
2) Pevent snapshot_write_next() and snapshot_read_next() from using a freed page (this could happend if the snapshot ioctls were called repeatedly without closing the device, eg. when attempting to create the image for the second time with image_size = 0).
--- kernel/power/snapshot.c | 5 ++--- kernel/power/user.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-)
kernel/power/user.c +1 -1
@@ -237,7 +237,7 @@ static int snapshot_ioctl(struct inode *break ;case SNAPSHOT_FREE_SWAP_PAGES : -if (data->swap >=0 && data->swap <MAX_SWAPFILES ) { +if (data->swap <0 || data->swap >=MAX_SWAPFILES ) { error = -ENODEV ;break ; }
kernel/power/snapshot.c +2 -3
@@ -37,6 +37,7 @@struct pbe *pagedir_nosave;static unsigned int nr_copy_pages;static unsigned int nr_meta_pages; +static unsigned long *buffer;#ifdef CONFIG_HIGHMEM unsigned int count_highmem_pages (void )
@@ -421,6 +422,7 @@ void swsusp_free(void) nr_copy_pages =0 ; nr_meta_pages =0 ; pagedir_nosave =NULL ; + buffer =NULL ; }
@@ -573,8 +575,6 @@ static inline struct pbe *pack_orig_addrint snapshot_read_next (struct snapshot_handle *handle,size_t count) { -static unsigned long *buffer; -if (handle->page > nr_meta_pages + nr_copy_pages)return 0 ;if (!buffer) {
@@ -779,7 +779,6 @@ static int create_image(struct snapshot_int snapshot_write_next (struct snapshot_handle *handle,size_t count) { -static unsigned long *buffer;int error =0 ;if (handle->prev && handle->page > nr_meta_pages + nr_copy_pages)
PATCH 2/2 swsusp: fix writing progress meter
In reply to Rafael J. WysockiDue to the wrong value passed to load_image() in swap.c the writing progress meter could run over 100%. Fix it.
--- kernel/power/swap.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
kernel/power/swap.c +2 -5
@@ -467,7 +467,6 @@ int swsusp_read(void)struct swap_map_handle handle;struct snapshot_handle snapshot;struct swsusp_info *header; -unsigned int nr_pages;if (IS_ERR (resume_bdev)) {pr_debug ("swsusp: block device not initialised\n" );
@@ -482,10 +481,8 @@ int swsusp_read(void) error =get_swap_reader (&handle, swsusp_header.image);if (!error) error =swap_read_page (&handle, header); -if (!error) { - nr_pages = header->image_pages; - error =load_image (&handle, &snapshot, nr_pages); - } +if (!error) + error =load_image (&handle, &snapshot, header->pages -1 );release_swap_reader (&handle);blkdev_put (resume_bdev);