summaryrefslogtreecommitdiff
path: root/fs/ext4
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2014-06-11 12:46:16 -0600
committerTom Rini <trini@ti.com>2014-06-19 11:18:53 -0400
commitd018028055a21a28adef16b7f95422c426b46d60 (patch)
tree24546aa499a82610c0af24849a6239fc7cd09130 /fs/ext4
parent50babaf852e3b48680f7ea782a756043f64f8fe2 (diff)
fs: ext4: fix writing zero-length files
ext4fs_allocate_blocks() always allocates at least one block for a file. If the file size is zero, this causes total_remaining_blocks to underflow, which then causes an apparent hang while 2^32 blocks are allocated. To solve this, check that total_remaining_blocks is non-zero as part of the loop condition (i.e. before each loop) rather than at the end of the loop. Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/ext4_common.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 1c1172163c..33d69c9c71 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -1380,7 +1380,7 @@ void ext4fs_allocate_blocks(struct ext2_inode *file_inode,
unsigned int no_blks_reqd = 0;
/* allocation of direct blocks */
- for (i = 0; i < INDIRECT_BLOCKS; i++) {
+ for (i = 0; total_remaining_blocks && i < INDIRECT_BLOCKS; i++) {
direct_blockno = ext4fs_get_new_blk_no();
if (direct_blockno == -1) {
printf("no block left to assign\n");
@@ -1390,8 +1390,6 @@ void ext4fs_allocate_blocks(struct ext2_inode *file_inode,
debug("DB %ld: %u\n", direct_blockno, total_remaining_blocks);
total_remaining_blocks--;
- if (total_remaining_blocks == 0)
- break;
}
alloc_single_indirect_block(file_inode, &total_remaining_blocks,