Wrapfs: decrement nd_path on follow_link error
authorErez Zadok <ezk@cs.sunysb.edu>
Fri, 26 Feb 2010 08:18:04 +0000 (03:18 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Dec 2016 03:11:28 +0000 (22:11 -0500)
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/wrapfs/inode.c

index ca6f0d2a748559b9853a9ed485802421eeed86d2..d4476e821166b28f2b01c097e4d6aeddf3b94cb0 100644 (file)
@@ -375,7 +375,7 @@ static void *wrapfs_follow_link(struct dentry *dentry, struct nameidata *nd)
        /* This is freed by the put_link method assuming a successful call. */
        buf = kmalloc(len, GFP_KERNEL);
        if (!buf) {
-               err = -ENOMEM;
+               buf = ERR_PTR(-ENOMEM);
                goto out;
        }
 
@@ -386,22 +386,22 @@ static void *wrapfs_follow_link(struct dentry *dentry, struct nameidata *nd)
        set_fs(old_fs);
        if (err < 0) {
                kfree(buf);
-               buf = NULL;
-               goto out;
+               buf = ERR_PTR(err);
+       } else {
+               buf[err] = '\0';
        }
-       buf[err] = 0;
-       nd_set_link(nd, buf);
-       err = 0;
-
 out:
-       return ERR_PTR(err);
+       nd_set_link(nd, buf);
+       return NULL;
 }
 
 /* this @nd *IS* still used */
 static void wrapfs_put_link(struct dentry *dentry, struct nameidata *nd,
                            void *cookie)
 {
-       kfree(nd_get_link(nd));
+       char *buf = nd_get_link(nd);
+       if (!IS_ERR(buf))       /* free the char* */
+               kfree(buf);
 }
 
 static int wrapfs_permission(struct inode *inode, int mask)