@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
324324/**
325325 * ecryptfs_lookup_interpose - Dentry interposition for a lookup
326326 */
327- static int ecryptfs_lookup_interpose (struct dentry * dentry ,
328- struct dentry * lower_dentry ,
329- struct inode * dir_inode )
327+ static struct dentry * ecryptfs_lookup_interpose (struct dentry * dentry ,
328+ struct dentry * lower_dentry )
330329{
331330 struct inode * inode , * lower_inode = d_inode (lower_dentry );
332331 struct ecryptfs_dentry_info * dentry_info ;
@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
339338 "to allocate ecryptfs_dentry_info struct\n" ,
340339 __func__ );
341340 dput (lower_dentry );
342- return - ENOMEM ;
341+ return ERR_PTR ( - ENOMEM ) ;
343342 }
344343
345344 lower_mnt = mntget (ecryptfs_dentry_to_lower_mnt (dentry -> d_parent ));
346- fsstack_copy_attr_atime (dir_inode , d_inode (lower_dentry -> d_parent ));
345+ fsstack_copy_attr_atime (d_inode (dentry -> d_parent ),
346+ d_inode (lower_dentry -> d_parent ));
347347 BUG_ON (!d_count (lower_dentry ));
348348
349349 ecryptfs_set_dentry_private (dentry , dentry_info );
@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
353353 if (d_really_is_negative (lower_dentry )) {
354354 /* We want to add because we couldn't find in lower */
355355 d_add (dentry , NULL );
356- return 0 ;
356+ return NULL ;
357357 }
358- inode = __ecryptfs_get_inode (lower_inode , dir_inode -> i_sb );
358+ inode = __ecryptfs_get_inode (lower_inode , dentry -> d_sb );
359359 if (IS_ERR (inode )) {
360360 printk (KERN_ERR "%s: Error interposing; rc = [%ld]\n" ,
361361 __func__ , PTR_ERR (inode ));
362- return PTR_ERR (inode );
362+ return ERR_CAST (inode );
363363 }
364364 if (S_ISREG (inode -> i_mode )) {
365365 rc = ecryptfs_i_size_read (dentry , inode );
366366 if (rc ) {
367367 make_bad_inode (inode );
368- return rc ;
368+ return ERR_PTR ( rc ) ;
369369 }
370370 }
371371
372372 if (inode -> i_state & I_NEW )
373373 unlock_new_inode (inode );
374- d_add (dentry , inode );
375-
376- return rc ;
374+ return d_splice_alias (inode , dentry );
377375}
378376
379377/**
@@ -390,55 +388,42 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
390388 unsigned int flags )
391389{
392390 char * encrypted_and_encoded_name = NULL ;
393- size_t encrypted_and_encoded_name_size ;
394- struct ecryptfs_mount_crypt_stat * mount_crypt_stat = NULL ;
391+ struct ecryptfs_mount_crypt_stat * mount_crypt_stat ;
395392 struct dentry * lower_dir_dentry , * lower_dentry ;
393+ const char * name = ecryptfs_dentry -> d_name .name ;
394+ size_t len = ecryptfs_dentry -> d_name .len ;
395+ struct dentry * res ;
396396 int rc = 0 ;
397397
398398 lower_dir_dentry = ecryptfs_dentry_to_lower (ecryptfs_dentry -> d_parent );
399- lower_dentry = lookup_one_len_unlocked (ecryptfs_dentry -> d_name .name ,
400- lower_dir_dentry ,
401- ecryptfs_dentry -> d_name .len );
402- if (IS_ERR (lower_dentry )) {
403- rc = PTR_ERR (lower_dentry );
404- ecryptfs_printk (KERN_DEBUG , "%s: lookup_one_len() returned "
405- "[%d] on lower_dentry = [%pd]\n" , __func__ , rc ,
406- ecryptfs_dentry );
407- goto out ;
408- }
409- if (d_really_is_positive (lower_dentry ))
410- goto interpose ;
399+
411400 mount_crypt_stat = & ecryptfs_superblock_to_private (
412401 ecryptfs_dentry -> d_sb )-> mount_crypt_stat ;
413- if (!(mount_crypt_stat
414- && (mount_crypt_stat -> flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES )))
415- goto interpose ;
416- dput (lower_dentry );
417- rc = ecryptfs_encrypt_and_encode_filename (
418- & encrypted_and_encoded_name , & encrypted_and_encoded_name_size ,
419- mount_crypt_stat , ecryptfs_dentry -> d_name .name ,
420- ecryptfs_dentry -> d_name .len );
421- if (rc ) {
422- printk (KERN_ERR "%s: Error attempting to encrypt and encode "
423- "filename; rc = [%d]\n" , __func__ , rc );
424- goto out ;
402+ if (mount_crypt_stat
403+ && (mount_crypt_stat -> flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES )) {
404+ rc = ecryptfs_encrypt_and_encode_filename (
405+ & encrypted_and_encoded_name , & len ,
406+ mount_crypt_stat , name , len );
407+ if (rc ) {
408+ printk (KERN_ERR "%s: Error attempting to encrypt and encode "
409+ "filename; rc = [%d]\n" , __func__ , rc );
410+ return ERR_PTR (rc );
411+ }
412+ name = encrypted_and_encoded_name ;
425413 }
426- lower_dentry = lookup_one_len_unlocked (encrypted_and_encoded_name ,
427- lower_dir_dentry ,
428- encrypted_and_encoded_name_size );
414+
415+ lower_dentry = lookup_one_len_unlocked (name , lower_dir_dentry , len );
429416 if (IS_ERR (lower_dentry )) {
430- rc = PTR_ERR (lower_dentry );
431417 ecryptfs_printk (KERN_DEBUG , "%s: lookup_one_len() returned "
432- "[%d] on lower_dentry = [%s]\n" , __func__ , rc ,
433- encrypted_and_encoded_name );
434- goto out ;
418+ "[%ld] on lower_dentry = [%s]\n" , __func__ ,
419+ PTR_ERR (lower_dentry ),
420+ name );
421+ res = ERR_CAST (lower_dentry );
422+ } else {
423+ res = ecryptfs_lookup_interpose (ecryptfs_dentry , lower_dentry );
435424 }
436- interpose :
437- rc = ecryptfs_lookup_interpose (ecryptfs_dentry , lower_dentry ,
438- ecryptfs_dir_inode );
439- out :
440425 kfree (encrypted_and_encoded_name );
441- return ERR_PTR ( rc ) ;
426+ return res ;
442427}
443428
444429static int ecryptfs_link (struct dentry * old_dentry , struct inode * dir ,
0 commit comments