Merge tag 'irqchip-4.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm...
[linux] / fs / open.c
index 4c65ede..d98e192 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -724,16 +724,6 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
        return ksys_fchown(fd, user, group);
 }
 
-int open_check_o_direct(struct file *f)
-{
-       /* NB: we're sure to have correct a_ops only after f_op->open */
-       if (f->f_flags & O_DIRECT) {
-               if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO)
-                       return -EINVAL;
-       }
-       return 0;
-}
-
 static int do_dentry_open(struct file *f,
                          struct inode *inode,
                          int (*open)(struct inode *, struct file *))
@@ -749,7 +739,7 @@ static int do_dentry_open(struct file *f,
        f->f_wb_err = filemap_sample_wb_err(f->f_mapping);
 
        if (unlikely(f->f_flags & O_PATH)) {
-               f->f_mode = FMODE_PATH;
+               f->f_mode = FMODE_PATH | FMODE_OPENED;
                f->f_op = &empty_fops;
                return 0;
        }
@@ -793,6 +783,7 @@ static int do_dentry_open(struct file *f,
                if (error)
                        goto cleanup_all;
        }
+       f->f_mode |= FMODE_OPENED;
        if ((f->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
                i_readcount_inc(inode);
        if ((f->f_mode & FMODE_READ) &&
@@ -807,6 +798,11 @@ static int do_dentry_open(struct file *f,
 
        file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);
 
+       /* NB: we're sure to have correct a_ops only after f_op->open */
+       if (f->f_flags & O_DIRECT) {
+               if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO)
+                       return -EINVAL;
+       }
        return 0;
 
 cleanup_all:
@@ -847,18 +843,12 @@ cleanup_file:
  * Returns zero on success or -errno if the open failed.
  */
 int finish_open(struct file *file, struct dentry *dentry,
-               int (*open)(struct inode *, struct file *),
-               int *opened)
+               int (*open)(struct inode *, struct file *))
 {
-       int error;
-       BUG_ON(*opened & FILE_OPENED); /* once it's opened, it's opened */
+       BUG_ON(file->f_mode & FMODE_OPENED); /* once it's opened, it's opened */
 
        file->f_path.dentry = dentry;
-       error = do_dentry_open(file, d_backing_inode(dentry), open);
-       if (!error)
-               *opened |= FILE_OPENED;
-
-       return error;
+       return do_dentry_open(file, d_backing_inode(dentry), open);
 }
 EXPORT_SYMBOL(finish_open);
 
@@ -873,13 +863,13 @@ EXPORT_SYMBOL(finish_open);
  * NB: unlike finish_open() this function does consume the dentry reference and
  * the caller need not dput() it.
  *
- * Returns "1" which must be the return value of ->atomic_open() after having
+ * Returns "0" which must be the return value of ->atomic_open() after having
  * called this function.
  */
 int finish_no_open(struct file *file, struct dentry *dentry)
 {
        file->f_path.dentry = dentry;
-       return 1;
+       return 0;
 }
 EXPORT_SYMBOL(finish_no_open);
 
@@ -920,15 +910,8 @@ struct file *dentry_open(const struct path *path, int flags,
        f = alloc_empty_file(flags, cred);
        if (!IS_ERR(f)) {
                error = vfs_open(path, f);
-               if (!error) {
-                       /* from now on we need fput() to dispose of f */
-                       error = open_check_o_direct(f);
-                       if (error) {
-                               fput(f);
-                               f = ERR_PTR(error);
-                       }
-               } else { 
-                       put_filp(f);
+               if (error) {
+                       fput(f);
                        f = ERR_PTR(error);
                }
        }