staging: zcache: don't limit number of pools per client
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / open.c
index 9daa1ce..d6c79a0 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -747,7 +747,6 @@ cleanup_all:
        f->f_path.dentry = NULL;
        f->f_path.mnt = NULL;
 cleanup_file:
-       put_filp(f);
        dput(dentry);
        mntput(mnt);
        return ERR_PTR(error);
@@ -765,6 +764,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
                        fput(res);
                        res = ERR_PTR(error);
                }
+       } else {
+               put_filp(f);
        }
        return res;
 }
@@ -823,13 +824,31 @@ struct file *nameidata_to_filp(struct nameidata *nd)
 
        /* Pick up the filp from the open intent */
        filp = nd->intent.open.file;
-       nd->intent.open.file = NULL;
 
        /* Has the filesystem initialised the file for us? */
-       if (filp->f_path.dentry == NULL) {
+       if (filp->f_path.dentry != NULL) {
+               nd->intent.open.file = NULL;
+       } else {
+               struct file *res;
+
                path_get(&nd->path);
-               filp = __dentry_open(nd->path.dentry, nd->path.mnt, filp,
-                                    NULL, cred);
+               res = do_dentry_open(nd->path.dentry, nd->path.mnt,
+                                    filp, NULL, cred);
+               if (!IS_ERR(res)) {
+                       int error;
+
+                       nd->intent.open.file = NULL;
+                       BUG_ON(res != filp);
+
+                       error = open_check_o_direct(filp);
+                       if (error) {
+                               fput(filp);
+                               filp = ERR_PTR(error);
+                       }
+               } else {
+                       /* Allow nd->intent.open.file to be recycled */
+                       filp = res;
+               }
        }
        return filp;
 }