diff --git a/fs/bfs/file.c b/fs/bfs/file.c index d33d6bde992b..39a2c6eec09a 100644 --- a/fs/bfs/file.c +++ b/fs/bfs/file.c @@ -40,6 +40,10 @@ static int bfs_move_block(unsigned long from, unsigned long to, if (!bh) return -EIO; new = sb_getblk(sb, to); + if (!new) { + brelse(bh); + return -EIO; + } memcpy(new->b_data, bh->b_data, bh->b_size); mark_buffer_dirty(new); bforget(bh); @@ -51,14 +55,17 @@ static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned long end, unsigned long where) { unsigned long i; + int err; dprintf("%08lx-%08lx->%08lx\n", start, end, where); - for (i = start; i <= end; i++) - if(bfs_move_block(i, where + i, sb)) { - dprintf("failed to move block %08lx -> %08lx\n", i, + for (i = 0; i <= end - start; i++) { + err = bfs_move_block(start + i, where + i, sb); + if (err) { + dprintf("failed to move block %08lx -> %08lx\n", start + i, where + i); - return -EIO; + return err; } + } return 0; }