linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext2: Check return value of sb_getblk()
@ 2010-10-19 13:10 Namhyung Kim
  0 siblings, 0 replies; only message in thread
From: Namhyung Kim @ 2010-10-19 13:10 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, linux-kernel

File block allocation if sb_getblk() returns NULL. unlikely() is added
because it is called in a loop and we've been OK without the check
until now.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 fs/ext2/inode.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 940c961..4acdc17 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -497,6 +497,11 @@ static int ext2_alloc_branch(struct inode *inode,
 		 * parent to disk.
 		 */
 		bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
+		if (unlikely(!bh)) {
+			err = -EIO;
+			goto failed;
+		}
+
 		branch[n].bh = bh;
 		lock_buffer(bh);
 		memset(bh->b_data, 0, blocksize);
@@ -525,6 +530,14 @@ static int ext2_alloc_branch(struct inode *inode,
 	}
 	*blks = num;
 	return err;
+failed:
+	/* Allocation failed, free what we already allocated */
+	for (i = 0; i < indirect_blks; i++)
+		ext2_free_blocks(inode, new_blocks[i], 1);
+
+	ext2_free_blocks(inode, new_blocks[i], num);
+
+	return err;
 }
 
 /**
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-10-19 13:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-19 13:10 [PATCH] ext2: Check return value of sb_getblk() Namhyung Kim

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).