Skip to contentSkip to conversation

PM / Hibernate: fix error handling in save_image

PATCH Applied Jiri Slaby 3 participants 9 messages Oct 10, 2009 – Oct 28, 2009

Subsystems (2)
lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

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
index 89e958e..47586d9 100644
@@ -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
#1 lore raw
Quoted 4 lines · Jiri Slaby

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.

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.

ACK.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Jiri Slaby

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.

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.

ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

#3 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Jiri Slaby

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.

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.

ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

author
#4 lore raw
In reply to Jiri Slaby

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.

author
#5 lore raw

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
index 893f522..4bb5c3b 100644
@@ -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
#6 lore raw

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_image fails in the middle of loading.

ACK.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#7 lore raw

Re: [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_image fails in the middle of loading.

ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael