diff options
-rw-r--r-- | fs/ext2/inode.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 6363ac66fafa..c3881e56662e 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c | |||
@@ -495,6 +495,10 @@ static int ext2_alloc_branch(struct inode *inode, | |||
495 | * parent to disk. | 495 | * parent to disk. |
496 | */ | 496 | */ |
497 | bh = sb_getblk(inode->i_sb, new_blocks[n-1]); | 497 | bh = sb_getblk(inode->i_sb, new_blocks[n-1]); |
498 | if (unlikely(!bh)) { | ||
499 | err = -ENOMEM; | ||
500 | goto failed; | ||
501 | } | ||
498 | branch[n].bh = bh; | 502 | branch[n].bh = bh; |
499 | lock_buffer(bh); | 503 | lock_buffer(bh); |
500 | memset(bh->b_data, 0, blocksize); | 504 | memset(bh->b_data, 0, blocksize); |
@@ -523,6 +527,14 @@ static int ext2_alloc_branch(struct inode *inode, | |||
523 | } | 527 | } |
524 | *blks = num; | 528 | *blks = num; |
525 | return err; | 529 | return err; |
530 | |||
531 | failed: | ||
532 | for (i = 1; i < n; i++) | ||
533 | bforget(branch[i].bh); | ||
534 | for (i = 0; i < indirect_blks; i++) | ||
535 | ext2_free_blocks(inode, new_blocks[i], 1); | ||
536 | ext2_free_blocks(inode, new_blocks[i], num); | ||
537 | return err; | ||
526 | } | 538 | } |
527 | 539 | ||
528 | /** | 540 | /** |