PM / Hibernate: fix error handling in save_image
Subsystems (2)
PATCH 1/1 PM / Hibernate: fix error handling in save_image
There are too many retval variables in save_image. Thus error return value from snapshot_read_next may be ignored and only part of the snapshot (successfully) written.
Remove 'error' variable, invert the condition in the do-while loop and convert the loop to use only 'ret' variable.
Switch the rest of the function to consider only 'ret'.
Also make sure we end printed line by \n if an error occurs.
--- kernel/power/swap.c | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-)
kernel/power/swap.c +16 -16
@@ -415,7 +415,6 @@ static int save_image(struct swap_map_handle *handle, {unsigned int m;int ret; -int error =0 ;int nr_pages;int err2;struct bio *bio;
@@ -430,26 +429,27 @@ static int save_image(struct swap_map_handle *handle, nr_pages =0 ; bio =NULL ;do_gettimeofday (&start); -do { +while (1 ) { ret =snapshot_read_next (snapshot,PAGE_SIZE ); -if (ret >0 ) { - error =swap_write_page (handle,data_of (*snapshot), - &bio); -if (error) -break ; -if (!(nr_pages % m)) -printk ("\b\b\b\b%3d%%" , nr_pages / m); - nr_pages++; - } - }while (ret >0 ); +if (ret <=0 ) +break ; + ret =swap_write_page (handle,data_of (*snapshot), &bio); +if (ret) +break ; +if (!(nr_pages % m)) +printk ("\b\b\b\b%3d%%" , nr_pages / m); + nr_pages++; + } err2 =wait_on_bio_chain (&bio);do_gettimeofday (&stop); -if (!error) - error = err2; -if (!error) +if (!ret) + ret = err2; +if (!ret)printk ("\b\b\b\bdone\n" ); +else +printk ("\n" );swsusp_show_speed (&start, &stop, nr_to_write,"Wrote" ); -return error; +return ret; }/**
Signature · 1 line
1.6.4.2
Quoted 4 lines · Jiri Slaby
There are too many retval variables in
save_image. Thus error return value fromsnapshot_read_nextmay be ignored and only part of the snapshot (successfully) written.
Quoted 8 lines
Remove 'error' variable, invert the condition in the do-while loop and convert the loop to use only 'ret' variable.
Switch the rest of the function to consider only 'ret'.
Also make sure we end printed line by \n if an error occurs.
Signed-off-by Jiri Slaby <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rafael J. Wysocki
AppliedQuoted 8 lines · Pavel Machek
Quoted 7 lines · Jiri Slaby
There are too many retval variables in
save_image. Thus error return value fromsnapshot_read_nextmay be ignored and only part of the snapshot (successfully) written.Remove 'error' variable, invert the condition in the do-while loop and convert the loop to use only 'ret' variable.
Quoted 7 lines
Quoted 5 lines
Switch the rest of the function to consider only 'ret'.
Also make sure we end printed line by \n if an error occurs.
Signed-off-by Jiri Slaby <[email protected]>ACK.
Applied to suspend-2.6/linux-next.
Thanks,
Rafael
Rafael J. Wysocki
AppliedQuoted 8 lines · Pavel Machek
Quoted 7 lines · Jiri Slaby
There are too many retval variables in
save_image. Thus error return value fromsnapshot_read_nextmay be ignored and only part of the snapshot (successfully) written.Remove 'error' variable, invert the condition in the do-while loop and convert the loop to use only 'ret' variable.
Quoted 7 lines
Quoted 5 lines
Switch the rest of the function to consider only 'ret'.
Also make sure we end printed line by \n if an error occurs.
Signed-off-by Jiri Slaby <[email protected]>ACK.
Applied to suspend-2.6/linux-next.
Thanks,
Rafael
kernel/power/swap.c static int save_image(struct swap_map_handle *handle, · line 450
Quoted 4 lines · Jiri Slaby
kernel/power/swap.c +3
-0+if (!ret)printk ("\b\b\b\bdone\n" ); +else +printk ("\n" );
Only the hell knows why I didn't post a similar fix for load_image... Will do now.
PATCH 1/1 PM / Hibernate: add \n to load_image fail path
Finish a line by \n when load_image fails in the middle of loading.
--- kernel/power/swap.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/power/swap.c +2 -1
@@ -537,7 +537,8 @@ static int load_image(struct swap_map_handle *handle,snapshot_write_finalize (snapshot);if (!snapshot_image_loaded (snapshot)) error = -ENODATA ; - } + }else +printk ("\n" );swsusp_show_speed (&start, &stop, nr_to_read,"Read" );return error; }
Signature · 1 line
1.6.4.2
Re: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
Quoted 3 lines · Jiri Slaby
Finish a line by \n when
load_imagefails in the middle of loading.Signed-off-by Jiri Slaby <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Rafael J. Wysocki
AppliedRe: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
Quoted 6 lines · Pavel Machek
Quoted 3 lines · Jiri Slaby
Finish a line by \n when
load_imagefails in the middle of loading.Signed-off-by Jiri Slaby <[email protected]>ACK.
Applied to suspend-2.6/linux-next.
Thanks,
Rafael
Rafael J. Wysocki
AppliedRe: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
In reply to Pavel MachekQuoted 6 lines · Pavel Machek
Quoted 3 lines · Jiri Slaby
Finish a line by \n when
load_imagefails in the middle of loading.Signed-off-by Jiri Slaby <[email protected]>ACK.
Applied to suspend-2.6/linux-next.
Thanks,
Rafael