]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
ext4: Check return value of sb_getblk() and friends
authorNamhyung Kim <namhyung@gmail.com>
Thu, 28 Oct 2010 01:30:11 +0000 (21:30 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 28 Oct 2010 01:30:11 +0000 (21:30 -0400)
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 <namhyung@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/inode.c
fs/ext4/mballoc.c

index 58604fe11f4ff04f8986a0d505b9d63981cd7ae7..077c3c9c432e0bc01316ebe4cf68191dfca74b90 100644 (file)
@@ -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");
index d732ef5a835d4eeb7e0f58a01507dd768816b120..611c866ef3fe8cb3057732c4a18cf797ec1ec174 100644 (file)
@@ -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);
                }