Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / fs / ext4 / file.c
index 6659e21..fa2208b 100644 (file)
@@ -329,7 +329,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
        struct super_block *sb = inode->i_sb;
        struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
        struct vfsmount *mnt = filp->f_path.mnt;
-       struct inode *dir = filp->f_path.dentry->d_parent->d_inode;
+       struct dentry *dir;
        struct path path;
        char buf[64], *cp;
        int ret;
@@ -373,14 +373,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
                if (ext4_encryption_info(inode) == NULL)
                        return -ENOKEY;
        }
-       if (ext4_encrypted_inode(dir) &&
-           !ext4_is_child_context_consistent_with_parent(dir, inode)) {
+
+       dir = dget_parent(file_dentry(filp));
+       if (ext4_encrypted_inode(d_inode(dir)) &&
+           !ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) {
                ext4_warning(inode->i_sb,
                             "Inconsistent encryption contexts: %lu/%lu\n",
-                            (unsigned long) dir->i_ino,
+                            (unsigned long) d_inode(dir)->i_ino,
                             (unsigned long) inode->i_ino);
+               dput(dir);
                return -EPERM;
        }
+       dput(dir);
        /*
         * Set up the jbd2_inode if we are opening the inode for
         * writing and the journal is present
@@ -428,8 +432,8 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,
        lastoff = startoff;
        endoff = (loff_t)end_blk << blkbits;
 
-       index = startoff >> PAGE_CACHE_SHIFT;
-       end = endoff >> PAGE_CACHE_SHIFT;
+       index = startoff >> PAGE_SHIFT;
+       end = endoff >> PAGE_SHIFT;
 
        pagevec_init(&pvec, 0);
        do {