From: Namhyung Kim Date: Thu, 28 Oct 2010 01:30:11 +0000 (-0400) Subject: ext4: Check return value of sb_getblk() and friends X-Git-Tag: v2.6.37-rc1~76^2^2~18 X-Git-Url: https://bbs.cooldavid.org/git/?p=net-next-2.6.git;a=commitdiff_plain;h=877836905da55e8f2426234f42a89287184949e9 ext4: Check return value of sb_getblk() and friends Fail block allocation if sb_getblk() returns NULL. In that case, sb_find_get_block() also likely to fail so that it should skip calling ext4_forget(). Signed-off-by: Namhyung Kim Signed-off-by: "Theodore Ts'o" --- diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 58604fe11f4..077c3c9c432 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -761,6 +761,11 @@ static int ext4_alloc_branch(handle_t *handle, 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); BUFFER_TRACE(bh, "call get_create_access"); diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index d732ef5a835..611c866ef3f 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4537,6 +4537,8 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, if (!bh) tbh = sb_find_get_block(inode->i_sb, block + i); + if (unlikely(!tbh)) + continue; ext4_forget(handle, flags & EXT4_FREE_BLOCKS_METADATA, inode, tbh, block + i); }