Skip to contentSkip to conversation

ext3: Check return value of sb_getblk()

PATCH In review Namhyung Kim 2 participants 3 messages Oct 19, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext3: Check return value of sb_getblk()

Check return value of sb_getblk() is NULL. unlikely is addded here since it is called from a loop and we've been OK without the check until now.

---
 fs/ext3/inode.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
fs/ext3/inode.c +6 -0
index ef1c23a..a7ac778 100644
@@ -655,6 +655,12 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
 		 * parent to disk.
 		 */
 		bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
+		if (unlikely(!bh)) {
+			n--;
+			err = -ENOMEM;
+			goto failed;
+		}
+
 		branch[n].bh = bh;
 		lock_buffer(bh);
 		BUFFER_TRACE(bh, "call get_create_access");
Signature · 1 line
1.7.0.4
#1 lore raw

2010-10-19 (화), 15:34 +0900, Namhyung Kim:

Quoted 16 lines

Check return value of sb_getblk() is NULL. unlikely is addded here since it is called from a loop and we've been OK without the check until now.

---
 fs/ext3/inode.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
fs/ext3/inode.c +0 -0
index ef1c23a..a7ac778 100644
@@ -655,6 +655,12 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
 		 * parent to disk.
 		 */

fs/ext3/inode.c static int ext3_alloc_branch(handle_t *handle, struct inode *inode, · line 666

Quoted 10 lines
fs/ext3/inode.c +6 -0
 		bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
+		if (unlikely(!bh)) {
+			n--;
+			err = -ENOMEM;
+			goto failed;
+		}
+
 		branch[n].bh = bh;
 		lock_buffer(bh);
 		BUFFER_TRACE(bh, "call get_create_access");

Maybe EIO would be more proper error code, I guess.

Signature · 8 lines
Regards,
Namhyung Kim


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 21 lines · Namhyung Kim

2010-10-19 (화), 15:34 +0900, Namhyung Kim:

Quoted 20 lines

Check return value of sb_getblk() is NULL. unlikely is addded here since it is called from a loop and we've been OK without the check until now.

---
 fs/ext3/inode.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
fs/ext3/inode.c +3 -0
index ef1c23a..a7ac778 100644
@@ -655,6 +655,12 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
 		 * parent to disk.
 		 */
 		bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
+		if (unlikely(!bh)) {
+			n--;
+			err = -ENOMEM;
Quoted 8 lines

fs/ext3/inode.c static int ext3_alloc_branch(handle_t *handle, struct inode *inode, · line 666

Quoted 6 lines
fs/ext3/inode.c +3 -0
+			goto failed;
+		}
+
 		branch[n].bh = bh;
 		lock_buffer(bh);
 		BUFFER_TRACE(bh, "call get_create_access");

Maybe EIO would be more proper error code, I guess.

Hmm, for ext3, sb_getblk() cannot really realistically fail. Block
numbers are 32-bit so they can never be big enough to overflow pagecache index and grow_buffers() loops indefinitely if it cannot allocate buffers. But OK, EIO might be a reasonable return value and we can have the check there just in case sb_getblk() grows some other possiblility to fail.

Honza

Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html