All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] PM / Hibernate: fix error handling in save_image
@ 2009-10-10 11:51 ` Jiri Slaby
  0 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2009-10-10 11:51 UTC (permalink / raw)
  To: rjw; +Cc: pavel, linux-pm, linux-kernel, 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.

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 <jirislaby@gmail.com>
---
 kernel/power/swap.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 89e958e..47586d9 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -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;
 }
 
 /**
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 1/1] PM / Hibernate: fix error handling in save_image
@ 2009-10-10 11:51 ` Jiri Slaby
  0 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2009-10-10 11:51 UTC (permalink / raw)
  To: rjw; +Cc: linux-pm, linux-kernel, 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.

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 <jirislaby@gmail.com>
---
 kernel/power/swap.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 89e958e..47586d9 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -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;
 }
 
 /**
-- 
1.6.4.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: fix error handling in save_image
  2009-10-10 11:51 ` Jiri Slaby
@ 2009-10-10 12:17   ` Pavel Machek
  -1 siblings, 0 replies; 14+ messages in thread
From: Pavel Machek @ 2009-10-10 12:17 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: rjw, linux-pm, linux-kernel

On Sat 2009-10-10 13:51:45, Jiri Slaby wrote:
> 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.
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

ACK.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: fix error handling in save_image
@ 2009-10-10 12:17   ` Pavel Machek
  0 siblings, 0 replies; 14+ messages in thread
From: Pavel Machek @ 2009-10-10 12:17 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-pm, linux-kernel

On Sat 2009-10-10 13:51:45, Jiri Slaby wrote:
> 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.
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

ACK.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: fix error handling in save_image
  2009-10-10 11:51 ` Jiri Slaby
@ 2009-10-12 21:29   ` Jiri Slaby
  -1 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2009-10-12 21:29 UTC (permalink / raw)
  Cc: rjw, pavel, linux-pm, linux-kernel

On 10/10/2009 01:51 PM, Jiri Slaby wrote:
> +	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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: fix error handling in save_image
@ 2009-10-12 21:29   ` Jiri Slaby
  0 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2009-10-12 21:29 UTC (permalink / raw)
  Cc: linux-pm, linux-kernel

On 10/10/2009 01:51 PM, Jiri Slaby wrote:
> +	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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
  2009-10-12 21:29   ` Jiri Slaby
@ 2009-10-12 21:38     ` Jiri Slaby
  -1 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2009-10-12 21:38 UTC (permalink / raw)
  To: rjw; +Cc: pavel, linux-pm, linux-kernel, Jiri Slaby

Finish a line by \n when load_image fails in the middle of loading.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
 kernel/power/swap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 893f522..4bb5c3b 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -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;
 }
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
@ 2009-10-12 21:38     ` Jiri Slaby
  0 siblings, 0 replies; 14+ messages in thread
From: Jiri Slaby @ 2009-10-12 21:38 UTC (permalink / raw)
  To: rjw; +Cc: linux-pm, linux-kernel, Jiri Slaby

Finish a line by \n when load_image fails in the middle of loading.

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
---
 kernel/power/swap.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 893f522..4bb5c3b 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -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;
 }
-- 
1.6.4.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
  2009-10-12 21:38     ` Jiri Slaby
@ 2009-10-13  7:28       ` Pavel Machek
  -1 siblings, 0 replies; 14+ messages in thread
From: Pavel Machek @ 2009-10-13  7:28 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: rjw, linux-pm, linux-kernel

On Mon 2009-10-12 23:38:50, Jiri Slaby wrote:
> Finish a line by \n when load_image fails in the middle of loading.
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

ACK.
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
@ 2009-10-13  7:28       ` Pavel Machek
  0 siblings, 0 replies; 14+ messages in thread
From: Pavel Machek @ 2009-10-13  7:28 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-pm, linux-kernel

On Mon 2009-10-12 23:38:50, Jiri Slaby wrote:
> Finish a line by \n when load_image fails in the middle of loading.
> 
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>

ACK.
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: fix error handling in save_image
  2009-10-10 12:17   ` Pavel Machek
  (?)
  (?)
@ 2009-10-28 22:08   ` Rafael J. Wysocki
  -1 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2009-10-28 22:08 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Jiri Slaby, linux-pm, linux-kernel

On Saturday 10 October 2009, Pavel Machek wrote:
> On Sat 2009-10-10 13:51:45, Jiri Slaby wrote:
> > 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.
> > 
> > Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> 
> ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: fix error handling in save_image
  2009-10-10 12:17   ` Pavel Machek
  (?)
@ 2009-10-28 22:08   ` Rafael J. Wysocki
  -1 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2009-10-28 22:08 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-pm, Jiri Slaby, linux-kernel

On Saturday 10 October 2009, Pavel Machek wrote:
> On Sat 2009-10-10 13:51:45, Jiri Slaby wrote:
> > 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.
> > 
> > Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> 
> ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
  2009-10-13  7:28       ` Pavel Machek
  (?)
  (?)
@ 2009-10-28 22:08       ` Rafael J. Wysocki
  -1 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2009-10-28 22:08 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Jiri Slaby, linux-pm, linux-kernel

On Tuesday 13 October 2009, Pavel Machek wrote:
> On Mon 2009-10-12 23:38:50, Jiri Slaby wrote:
> > Finish a line by \n when load_image fails in the middle of loading.
> > 
> > Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> 
> ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/1] PM / Hibernate: add \n to load_image fail path
  2009-10-13  7:28       ` Pavel Machek
  (?)
@ 2009-10-28 22:08       ` Rafael J. Wysocki
  -1 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2009-10-28 22:08 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-pm, Jiri Slaby, linux-kernel

On Tuesday 13 October 2009, Pavel Machek wrote:
> On Mon 2009-10-12 23:38:50, Jiri Slaby wrote:
> > Finish a line by \n when load_image fails in the middle of loading.
> > 
> > Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> 
> ACK.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-10-28 22:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-10 11:51 [PATCH 1/1] PM / Hibernate: fix error handling in save_image Jiri Slaby
2009-10-10 11:51 ` Jiri Slaby
2009-10-10 12:17 ` Pavel Machek
2009-10-10 12:17   ` Pavel Machek
2009-10-28 22:08   ` Rafael J. Wysocki
2009-10-28 22:08   ` Rafael J. Wysocki
2009-10-12 21:29 ` Jiri Slaby
2009-10-12 21:29   ` Jiri Slaby
2009-10-12 21:38   ` [PATCH 1/1] PM / Hibernate: add \n to load_image fail path Jiri Slaby
2009-10-12 21:38     ` Jiri Slaby
2009-10-13  7:28     ` Pavel Machek
2009-10-13  7:28       ` Pavel Machek
2009-10-28 22:08       ` Rafael J. Wysocki
2009-10-28 22:08       ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.