Skip to contentSkip to conversation

ext4: Check return value of sb_getblk() and friends

PATCH In review Namhyung Kim 2 participants 2 messages Oct 19, 2010 – Oct 25, 2010 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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().

---
 fs/ext4/inode.c   |    5 +++++
 fs/ext4/mballoc.c |    2 ++
 2 files changed, 7 insertions(+), 0 deletions(-)
fs/ext4/inode.c +5 -0
index 4b8debe..12c0310 100644
@@ -755,6 +755,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");
fs/ext4/mballoc.c +2 -0
index 4b4ad4b..48f5d10 100644
@@ -4531,6 +4531,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);
 		}
Signature · 1 line
1.7.0.4
maintainer
#1 lore raw
Quoted 5 lines · Namhyung Kim

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

Thanks, I've added this patch to the ext4 patch queue.

- Ted