2007-05-10 12:05:36

by Mika Kukkonen

[permalink] [raw]
Subject: [PATCH] Bug in fs/afs/write.c function afs_write_back_from_locked_page()

Following bug was uncovered by compiling with '-W' flag:

CC [M] fs/afs/write.o
fs/afs/write.c: In function ‘afs_write_back_from_locked_page’:
fs/afs/write.c:398: warning: comparison of unsigned expression >= 0 is always true

Loop variable 'n' is unsigned, so wraps around happily as far as I can
see. Trival fix attached (compile tested only).

Signed-Off-By: Mika Kukkonen <[email protected]>

diff --git a/fs/afs/write.c b/fs/afs/write.c
index 83ff292..4bca263 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -395,8 +395,9 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb,
if (n == 0)
goto no_more;
if (pages[0]->index != start) {
- for (n--; n >= 0; n--)
+ for (n--; n > 0; n--)
put_page(pages[n]);
+ put_page(pages[0]);
goto no_more;
}


2007-05-10 12:33:32

by David Howells

[permalink] [raw]
Subject: Re: [PATCH] Bug in fs/afs/write.c function afs_write_back_from_locked_page()


How about the attached instead?

David
---
AFS: Fix interminable loop in afs_write_back_from_locked_page()

From: Mika Kukkonen <[email protected]>

Following bug was uncovered by compiling with '-W' flag:

CC [M] fs/afs/write.o
fs/afs/write.c: In function ‘afs_write_back_from_locked_page’:
fs/afs/write.c:398: warning: comparison of unsigned expression >= 0 is always true

Loop variable 'n' is unsigned, so wraps around happily as far as I can
see. Trival fix attached (compile tested only).

Signed-Off-By: Mika Kukkonen <[email protected]>
Signed-off-by: David Howells <[email protected]>
---

fs/afs/write.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index 67ae4db..c26d5e8 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -395,8 +395,10 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb,
if (n == 0)
goto no_more;
if (pages[0]->index != start) {
- for (n--; n >= 0; n--)
- put_page(pages[n]);
+ do {
+ put_page(pages[--n]);
+ } while (n > 0);
+ put_page(pages[0]);
goto no_more;
}

2007-05-10 13:23:17

by David Howells

[permalink] [raw]
Subject: Re: [PATCH] Bug in fs/afs/write.c function afs_write_back_from_locked_page()

David Howells <[email protected]> wrote:

> How about the attached instead?

Blech. How about this instead? I forgot to remove the extra put_page() you
added.

David
---
AFS: Fix interminable loop in afs_write_back_from_locked_page()

From: Mika Kukkonen <[email protected]>

Following bug was uncovered by compiling with '-W' flag:

CC [M] fs/afs/write.o
fs/afs/write.c: In function ‘afs_write_back_from_locked_page’:
fs/afs/write.c:398: warning: comparison of unsigned expression >= 0 is always true

Loop variable 'n' is unsigned, so wraps around happily as far as I can
see. Trival fix attached (compile tested only).

Signed-Off-By: Mika Kukkonen <[email protected]>
Signed-off-by: David Howells <[email protected]>
---

fs/afs/write.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index 67ae4db..28f3751 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -395,8 +395,9 @@ static int afs_write_back_from_locked_page(struct afs_writeback *wb,
if (n == 0)
goto no_more;
if (pages[0]->index != start) {
- for (n--; n >= 0; n--)
- put_page(pages[n]);
+ do {
+ put_page(pages[--n]);
+ } while (n > 0);
goto no_more;
}