aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/ialloc.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2008-08-18 07:44:48 -0400
committerJan Kara <jack@suse.cz>2008-08-19 05:05:05 -0400
commit97e1cfb08616987878f91a46cefdd7fc5fa3dba1 (patch)
tree58442dfca90b9184a09c2b1ab1d7252a4100e296 /fs/udf/ialloc.c
parentdb0badc58e948b810c7a75cfcc48845e2949ee37 (diff)
udf: Fix error paths in udf_new_inode()
I case we failed to allocate memory for inode when creating it, we did not properly free block already allocated for this inode. Move memory allocation before the block allocation which fixes this issue (thanks for the idea go to Ingo Oeser <ioe-lkml@rameria.de>). Also remove a few superfluous initializations already done in udf_alloc_inode(). Reviewed-by: Ingo Oeser <ioe-lkml@rameria.de> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/udf/ialloc.c')
-rw-r--r--fs/udf/ialloc.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c
index c4943c8988c..a4f2b3ce45b 100644
--- a/fs/udf/ialloc.c
+++ b/fs/udf/ialloc.c
@@ -76,11 +76,24 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
76 *err = -ENOSPC; 76 *err = -ENOSPC;
77 77
78 iinfo = UDF_I(inode); 78 iinfo = UDF_I(inode);
79 iinfo->i_unique = 0; 79 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
80 iinfo->i_lenExtents = 0; 80 iinfo->i_efe = 1;
81 iinfo->i_next_alloc_block = 0; 81 if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
82 iinfo->i_next_alloc_goal = 0; 82 sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
83 iinfo->i_strat4096 = 0; 83 iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
84 sizeof(struct extendedFileEntry),
85 GFP_KERNEL);
86 } else {
87 iinfo->i_efe = 0;
88 iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
89 sizeof(struct fileEntry),
90 GFP_KERNEL);
91 }
92 if (!iinfo->i_ext.i_data) {
93 iput(inode);
94 *err = -ENOMEM;
95 return NULL;
96 }
84 97
85 block = udf_new_block(dir->i_sb, NULL, 98 block = udf_new_block(dir->i_sb, NULL,
86 dinfo->i_location.partitionReferenceNum, 99 dinfo->i_location.partitionReferenceNum,
@@ -130,24 +143,6 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
130 iinfo->i_lenEAttr = 0; 143 iinfo->i_lenEAttr = 0;
131 iinfo->i_lenAlloc = 0; 144 iinfo->i_lenAlloc = 0;
132 iinfo->i_use = 0; 145 iinfo->i_use = 0;
133 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
134 iinfo->i_efe = 1;
135 if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
136 sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
137 iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
138 sizeof(struct extendedFileEntry),
139 GFP_KERNEL);
140 } else {
141 iinfo->i_efe = 0;
142 iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
143 sizeof(struct fileEntry),
144 GFP_KERNEL);
145 }
146 if (!iinfo->i_ext.i_data) {
147 iput(inode);
148 *err = -ENOMEM;
149 return NULL;
150 }
151 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB)) 146 if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
152 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; 147 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
153 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD)) 148 else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))