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:52:52 +0000 (22:52 -0500)
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/wrapfs/inode.c

index d9d23a4527da4482392d55f928d4540136ce5e95..e39869831b67ac57dccc840415b72044f4ad3d04 100644 (file)
@@ -378,7 +378,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;
        }
 
@@ -389,22 +389,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)