linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ufs: Check if page has buffers before calling page_buffers()
@ 2011-02-01 21:23 Alessio Igor Bogani
  2011-02-02  4:23 ` Evgeniy Dushistov
  0 siblings, 1 reply; 3+ messages in thread
From: Alessio Igor Bogani @ 2011-02-01 21:23 UTC (permalink / raw)
  To: Evgeniy Dushistov
  Cc: linux-fsdevel, linux-kernel, Tim Bird, Alessio Igor Bogani

In ufs_change_blocknr() we have called page_buffers() without checking if the
page actually had pages attached to it and this could cause a BUG oops.

This work was supported by a hardware donation from the CE Linux Forum.

Signed-off-by: Alessio Igor Bogani <abogani@kernel.org>
---
 fs/ufs/balloc.c |   62 +++++++++++++++++++++++++++---------------------------
 1 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 46f7a80..8155ccd 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -276,46 +276,46 @@ static void ufs_change_blocknr(struct inode *inode, sector_t beg,
 		} else
 			page = locked_page;
 
-		head = page_buffers(page);
-		bh = head;
-		pos = i & mask;
-		for (j = 0; j < pos; ++j)
-			bh = bh->b_this_page;
-
-
 		if (unlikely(index == last_index))
 			lblock = end & mask;
 		else
 			lblock = blks_per_page;
 
-		do {
-			if (j >= lblock)
-				break;
-			pos = (i - beg) + j;
+		if (page_has_buffers(page)) {
+			bh = head = page_buffers(page);
+			pos = i & mask;
+			for (j = 0; j < pos; ++j)
+				bh = bh->b_this_page;
 
-			if (!buffer_mapped(bh))
-					map_bh(bh, inode->i_sb, oldb + pos);
-			if (!buffer_uptodate(bh)) {
-				ll_rw_block(READ, 1, &bh);
-				wait_on_buffer(bh);
-				if (!buffer_uptodate(bh)) {
-					ufs_error(inode->i_sb, __func__,
-						  "read of block failed\n");
+			do {
+				if (j >= lblock)
 					break;
+				pos = (i - beg) + j;
+
+				if (!buffer_mapped(bh))
+						map_bh(bh, inode->i_sb, oldb + pos);
+				if (!buffer_uptodate(bh)) {
+					ll_rw_block(READ, 1, &bh);
+					wait_on_buffer(bh);
+					if (!buffer_uptodate(bh)) {
+						ufs_error(inode->i_sb, __func__,
+							  "read of block failed\n");
+						break;
+					}
 				}
-			}
 
-			UFSD(" change from %llu to %llu, pos %u\n",
-			     (unsigned long long)(pos + oldb),
-			     (unsigned long long)(pos + newb), pos);
-
-			bh->b_blocknr = newb + pos;
-			unmap_underlying_metadata(bh->b_bdev,
-						  bh->b_blocknr);
-			mark_buffer_dirty(bh);
-			++j;
-			bh = bh->b_this_page;
-		} while (bh != head);
+				UFSD(" change from %llu to %llu, pos %u\n",
+				     (unsigned long long)(pos + oldb),
+					 (unsigned long long)(pos + newb), pos);
+
+				bh->b_blocknr = newb + pos;
+				unmap_underlying_metadata(bh->b_bdev,
+							  bh->b_blocknr);
+				mark_buffer_dirty(bh);
+				++j;
+				bh = bh->b_this_page;
+			} while (bh != head);
+		}
 
 		if (likely(cur_index != index))
 			ufs_put_locked_page(page);
-- 
1.7.0.4


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

end of thread, other threads:[~2011-02-02 17:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-01 21:23 [PATCH] ufs: Check if page has buffers before calling page_buffers() Alessio Igor Bogani
2011-02-02  4:23 ` Evgeniy Dushistov
2011-02-02 17:57   ` Alessio Igor Bogani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).