summaryrefslogtreecommitdiffstats
path: root/fs/ubifs/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ubifs/dir.c')
-rw-r--r--fs/ubifs/dir.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 9d7fb88e172e..4e267cc21c77 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -214,7 +214,7 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
214 int err; 214 int err;
215 union ubifs_key key; 215 union ubifs_key key;
216 struct inode *inode = NULL; 216 struct inode *inode = NULL;
217 struct ubifs_dent_node *dent; 217 struct ubifs_dent_node *dent = NULL;
218 struct ubifs_info *c = dir->i_sb->s_fs_info; 218 struct ubifs_info *c = dir->i_sb->s_fs_info;
219 struct fscrypt_name nm; 219 struct fscrypt_name nm;
220 220
@@ -229,14 +229,14 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
229 return ERR_PTR(err); 229 return ERR_PTR(err);
230 230
231 if (fname_len(&nm) > UBIFS_MAX_NLEN) { 231 if (fname_len(&nm) > UBIFS_MAX_NLEN) {
232 err = -ENAMETOOLONG; 232 inode = ERR_PTR(-ENAMETOOLONG);
233 goto out_fname; 233 goto done;
234 } 234 }
235 235
236 dent = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); 236 dent = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
237 if (!dent) { 237 if (!dent) {
238 err = -ENOMEM; 238 inode = ERR_PTR(-ENOMEM);
239 goto out_fname; 239 goto done;
240 } 240 }
241 241
242 if (nm.hash) { 242 if (nm.hash) {
@@ -250,16 +250,16 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
250 } 250 }
251 251
252 if (err) { 252 if (err) {
253 if (err == -ENOENT) { 253 if (err == -ENOENT)
254 dbg_gen("not found"); 254 dbg_gen("not found");
255 goto done; 255 else
256 } 256 inode = ERR_PTR(err);
257 goto out_dent; 257 goto done;
258 } 258 }
259 259
260 if (dbg_check_name(c, dent, &nm)) { 260 if (dbg_check_name(c, dent, &nm)) {
261 err = -EINVAL; 261 inode = ERR_PTR(-EINVAL);
262 goto out_dent; 262 goto done;
263 } 263 }
264 264
265 inode = ubifs_iget(dir->i_sb, le64_to_cpu(dent->inum)); 265 inode = ubifs_iget(dir->i_sb, le64_to_cpu(dent->inum));
@@ -272,7 +272,7 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
272 ubifs_err(c, "dead directory entry '%pd', error %d", 272 ubifs_err(c, "dead directory entry '%pd', error %d",
273 dentry, err); 273 dentry, err);
274 ubifs_ro_mode(c, err); 274 ubifs_ro_mode(c, err);
275 goto out_dent; 275 goto done;
276 } 276 }
277 277
278 if (ubifs_crypt_is_encrypted(dir) && 278 if (ubifs_crypt_is_encrypted(dir) &&
@@ -280,27 +280,14 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
280 !fscrypt_has_permitted_context(dir, inode)) { 280 !fscrypt_has_permitted_context(dir, inode)) {
281 ubifs_warn(c, "Inconsistent encryption contexts: %lu/%lu", 281 ubifs_warn(c, "Inconsistent encryption contexts: %lu/%lu",
282 dir->i_ino, inode->i_ino); 282 dir->i_ino, inode->i_ino);
283 err = -EPERM; 283 iput(inode);
284 goto out_inode; 284 inode = ERR_PTR(-EPERM);
285 } 285 }
286 286
287done: 287done:
288 kfree(dent); 288 kfree(dent);
289 fscrypt_free_filename(&nm); 289 fscrypt_free_filename(&nm);
290 /* 290 return d_splice_alias(inode, dentry);
291 * Note, d_splice_alias() would be required instead if we supported
292 * NFS.
293 */
294 d_add(dentry, inode);
295 return NULL;
296
297out_inode:
298 iput(inode);
299out_dent:
300 kfree(dent);
301out_fname:
302 fscrypt_free_filename(&nm);
303 return ERR_PTR(err);
304} 291}
305 292
306static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode, 293static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,