diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2015-05-02 13:32:22 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2015-05-10 22:19:45 -0400 |
commit | 680baacbca69d18a6d7315374ad83d05ac9c0977 (patch) | |
tree | a69822ef5234d4a308b780ff51c5d9b77bd3a89b | |
parent | 46afd6f61cc33ae4b3a2aed4bb454d11d4114c27 (diff) |
new ->follow_link() and ->put_link() calling conventions
a) instead of storing the symlink body (via nd_set_link()) and returning
an opaque pointer later passed to ->put_link(), ->follow_link() _stores_
that opaque pointer (into void * passed by address by caller) and returns
the symlink body. Returning ERR_PTR() on error, NULL on jump (procfs magic
symlinks) and pointer to symlink body for normal symlinks. Stored pointer
is ignored in all cases except the last one.
Storing NULL for opaque pointer (or not storing it at all) means no call
of ->put_link().
b) the body used to be passed to ->put_link() implicitly (via nameidata).
Now only the opaque pointer is. In the cases when we used the symlink body
to free stuff, ->follow_link() now should store it as opaque pointer in addition
to returning it.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | Documentation/filesystems/Locking | 4 | ||||
-rw-r--r-- | Documentation/filesystems/vfs.txt | 4 | ||||
-rw-r--r-- | drivers/staging/lustre/lustre/llite/symlink.c | 11 | ||||
-rw-r--r-- | fs/9p/vfs_inode.c | 13 | ||||
-rw-r--r-- | fs/9p/vfs_inode_dotl.c | 7 | ||||
-rw-r--r-- | fs/autofs4/symlink.c | 5 | ||||
-rw-r--r-- | fs/befs/linuxvfs.c | 35 | ||||
-rw-r--r-- | fs/cifs/cifsfs.h | 2 | ||||
-rw-r--r-- | fs/cifs/link.c | 28 | ||||
-rw-r--r-- | fs/configfs/symlink.c | 28 | ||||
-rw-r--r-- | fs/ecryptfs/inode.c | 8 | ||||
-rw-r--r-- | fs/ext4/symlink.c | 9 | ||||
-rw-r--r-- | fs/f2fs/namei.c | 18 | ||||
-rw-r--r-- | fs/fuse/dir.c | 19 | ||||
-rw-r--r-- | fs/gfs2/inode.c | 10 | ||||
-rw-r--r-- | fs/hostfs/hostfs_kern.c | 15 | ||||
-rw-r--r-- | fs/hppfs/hppfs.c | 9 | ||||
-rw-r--r-- | fs/kernfs/symlink.c | 22 | ||||
-rw-r--r-- | fs/libfs.c | 12 | ||||
-rw-r--r-- | fs/namei.c | 66 | ||||
-rw-r--r-- | fs/nfs/symlink.c | 19 | ||||
-rw-r--r-- | fs/overlayfs/inode.c | 18 | ||||
-rw-r--r-- | fs/proc/base.c | 2 | ||||
-rw-r--r-- | fs/proc/inode.c | 9 | ||||
-rw-r--r-- | fs/proc/namespaces.c | 2 | ||||
-rw-r--r-- | fs/proc/self.c | 24 | ||||
-rw-r--r-- | fs/proc/thread_self.c | 22 | ||||
-rw-r--r-- | fs/xfs/xfs_iops.c | 10 | ||||
-rw-r--r-- | include/linux/fs.h | 12 | ||||
-rw-r--r-- | include/linux/namei.h | 2 | ||||
-rw-r--r-- | mm/shmem.c | 23 |
31 files changed, 195 insertions, 273 deletions
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index 0a926e2ba3ab..7fa6c4ac858c 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking | |||
@@ -50,8 +50,8 @@ prototypes: | |||
50 | int (*rename2) (struct inode *, struct dentry *, | 50 | int (*rename2) (struct inode *, struct dentry *, |
51 | struct inode *, struct dentry *, unsigned int); | 51 | struct inode *, struct dentry *, unsigned int); |
52 | int (*readlink) (struct dentry *, char __user *,int); | 52 | int (*readlink) (struct dentry *, char __user *,int); |
53 | void * (*follow_link) (struct dentry *, struct nameidata *); | 53 | const char *(*follow_link) (struct dentry *, void **, struct nameidata *); |
54 | void (*put_link) (struct dentry *, struct nameidata *, void *); | 54 | void (*put_link) (struct dentry *, void *); |
55 | void (*truncate) (struct inode *); | 55 | void (*truncate) (struct inode *); |
56 | int (*permission) (struct inode *, int, unsigned int); | 56 | int (*permission) (struct inode *, int, unsigned int); |
57 | int (*get_acl)(struct inode *, int); | 57 | int (*get_acl)(struct inode *, int); |
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index 5d833b32bbcd..1c6b03ac2e5a 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt | |||
@@ -350,8 +350,8 @@ struct inode_operations { | |||
350 | int (*rename2) (struct inode *, struct dentry *, | 350 | int (*rename2) (struct inode *, struct dentry *, |
351 | struct inode *, struct dentry *, unsigned int); | 351 | struct inode *, struct dentry *, unsigned int); |
352 | int (*readlink) (struct dentry *, char __user *,int); | 352 | int (*readlink) (struct dentry *, char __user *,int); |
353 | void * (*follow_link) (struct dentry *, struct nameidata *); | 353 | const char *(*follow_link) (struct dentry *, void **, struct nameidata *); |
354 | void (*put_link) (struct dentry *, struct nameidata *, void *); | 354 | void (*put_link) (struct dentry *, void *); |
355 | int (*permission) (struct inode *, int); | 355 | int (*permission) (struct inode *, int); |
356 | int (*get_acl)(struct inode *, int); | 356 | int (*get_acl)(struct inode *, int); |
357 | int (*setattr) (struct dentry *, struct iattr *); | 357 | int (*setattr) (struct dentry *, struct iattr *); |
diff --git a/drivers/staging/lustre/lustre/llite/symlink.c b/drivers/staging/lustre/lustre/llite/symlink.c index 3711e671a4df..e488cb3bb25d 100644 --- a/drivers/staging/lustre/lustre/llite/symlink.c +++ b/drivers/staging/lustre/lustre/llite/symlink.c | |||
@@ -118,7 +118,7 @@ failed: | |||
118 | return rc; | 118 | return rc; |
119 | } | 119 | } |
120 | 120 | ||
121 | static void *ll_follow_link(struct dentry *dentry, struct nameidata *nd) | 121 | static const char *ll_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
122 | { | 122 | { |
123 | struct inode *inode = d_inode(dentry); | 123 | struct inode *inode = d_inode(dentry); |
124 | struct ptlrpc_request *request = NULL; | 124 | struct ptlrpc_request *request = NULL; |
@@ -140,18 +140,17 @@ static void *ll_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
140 | } | 140 | } |
141 | if (rc) { | 141 | if (rc) { |
142 | ptlrpc_req_finished(request); | 142 | ptlrpc_req_finished(request); |
143 | request = NULL; | 143 | return ERR_PTR(rc); |
144 | symname = ERR_PTR(rc); | ||
145 | } | 144 | } |
146 | 145 | ||
147 | nd_set_link(nd, symname); | ||
148 | /* symname may contain a pointer to the request message buffer, | 146 | /* symname may contain a pointer to the request message buffer, |
149 | * we delay request releasing until ll_put_link then. | 147 | * we delay request releasing until ll_put_link then. |
150 | */ | 148 | */ |
151 | return request; | 149 | *cookie = request; |
150 | return symname; | ||
152 | } | 151 | } |
153 | 152 | ||
154 | static void ll_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie) | 153 | static void ll_put_link(struct dentry *dentry, void *cookie) |
155 | { | 154 | { |
156 | ptlrpc_req_finished(cookie); | 155 | ptlrpc_req_finished(cookie); |
157 | } | 156 | } |
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 0ba11712b388..7cc70a39a1d8 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c | |||
@@ -1230,11 +1230,12 @@ ino_t v9fs_qid2ino(struct p9_qid *qid) | |||
1230 | * | 1230 | * |
1231 | */ | 1231 | */ |
1232 | 1232 | ||
1233 | static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) | 1233 | static const char *v9fs_vfs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
1234 | { | 1234 | { |
1235 | struct v9fs_session_info *v9ses = v9fs_dentry2v9ses(dentry); | 1235 | struct v9fs_session_info *v9ses = v9fs_dentry2v9ses(dentry); |
1236 | struct p9_fid *fid = v9fs_fid_lookup(dentry); | 1236 | struct p9_fid *fid = v9fs_fid_lookup(dentry); |
1237 | struct p9_wstat *st; | 1237 | struct p9_wstat *st; |
1238 | char *res; | ||
1238 | 1239 | ||
1239 | p9_debug(P9_DEBUG_VFS, "%pd\n", dentry); | 1240 | p9_debug(P9_DEBUG_VFS, "%pd\n", dentry); |
1240 | 1241 | ||
@@ -1253,14 +1254,14 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
1253 | kfree(st); | 1254 | kfree(st); |
1254 | return ERR_PTR(-EINVAL); | 1255 | return ERR_PTR(-EINVAL); |
1255 | } | 1256 | } |
1256 | if (strlen(st->extension) >= PATH_MAX) | 1257 | res = st->extension; |
1257 | st->extension[PATH_MAX - 1] = '\0'; | ||
1258 | |||
1259 | nd_set_link(nd, st->extension); | ||
1260 | st->extension = NULL; | 1258 | st->extension = NULL; |
1259 | if (strlen(res) >= PATH_MAX) | ||
1260 | res[PATH_MAX - 1] = '\0'; | ||
1261 | |||
1261 | p9stat_free(st); | 1262 | p9stat_free(st); |
1262 | kfree(st); | 1263 | kfree(st); |
1263 | return NULL; | 1264 | return *cookie = res; |
1264 | } | 1265 | } |
1265 | 1266 | ||
1266 | /** | 1267 | /** |
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c index bc2a91f2b910..ae062ffa0f1f 100644 --- a/fs/9p/vfs_inode_dotl.c +++ b/fs/9p/vfs_inode_dotl.c | |||
@@ -909,8 +909,8 @@ error: | |||
909 | * | 909 | * |
910 | */ | 910 | */ |
911 | 911 | ||
912 | static void * | 912 | static const char * |
913 | v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) | 913 | v9fs_vfs_follow_link_dotl(struct dentry *dentry, void **cookie, struct nameidata *nd) |
914 | { | 914 | { |
915 | struct p9_fid *fid = v9fs_fid_lookup(dentry); | 915 | struct p9_fid *fid = v9fs_fid_lookup(dentry); |
916 | char *target; | 916 | char *target; |
@@ -923,8 +923,7 @@ v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) | |||
923 | retval = p9_client_readlink(fid, &target); | 923 | retval = p9_client_readlink(fid, &target); |
924 | if (retval) | 924 | if (retval) |
925 | return ERR_PTR(retval); | 925 | return ERR_PTR(retval); |
926 | nd_set_link(nd, target); | 926 | return *cookie = target; |
927 | return NULL; | ||
928 | } | 927 | } |
929 | 928 | ||
930 | int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) | 929 | int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode) |
diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c index de58cc7b8076..9c6a07739c9b 100644 --- a/fs/autofs4/symlink.c +++ b/fs/autofs4/symlink.c | |||
@@ -12,14 +12,13 @@ | |||
12 | 12 | ||
13 | #include "autofs_i.h" | 13 | #include "autofs_i.h" |
14 | 14 | ||
15 | static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) | 15 | static const char *autofs4_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
16 | { | 16 | { |
17 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 17 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
18 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | 18 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
19 | if (ino && !autofs4_oz_mode(sbi)) | 19 | if (ino && !autofs4_oz_mode(sbi)) |
20 | ino->last_used = jiffies; | 20 | ino->last_used = jiffies; |
21 | nd_set_link(nd, d_inode(dentry)->i_private); | 21 | return d_inode(dentry)->i_private; |
22 | return NULL; | ||
23 | } | 22 | } |
24 | 23 | ||
25 | const struct inode_operations autofs4_symlink_inode_operations = { | 24 | const struct inode_operations autofs4_symlink_inode_operations = { |
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index 172e306d68a7..3a1aefb86a11 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c | |||
@@ -42,7 +42,7 @@ static struct inode *befs_iget(struct super_block *, unsigned long); | |||
42 | static struct inode *befs_alloc_inode(struct super_block *sb); | 42 | static struct inode *befs_alloc_inode(struct super_block *sb); |
43 | static void befs_destroy_inode(struct inode *inode); | 43 | static void befs_destroy_inode(struct inode *inode); |
44 | static void befs_destroy_inodecache(void); | 44 | static void befs_destroy_inodecache(void); |
45 | static void *befs_follow_link(struct dentry *, struct nameidata *); | 45 | static const char *befs_follow_link(struct dentry *, void **, struct nameidata *nd); |
46 | static int befs_utf2nls(struct super_block *sb, const char *in, int in_len, | 46 | static int befs_utf2nls(struct super_block *sb, const char *in, int in_len, |
47 | char **out, int *out_len); | 47 | char **out, int *out_len); |
48 | static int befs_nls2utf(struct super_block *sb, const char *in, int in_len, | 48 | static int befs_nls2utf(struct super_block *sb, const char *in, int in_len, |
@@ -463,8 +463,8 @@ befs_destroy_inodecache(void) | |||
463 | * The data stream become link name. Unless the LONG_SYMLINK | 463 | * The data stream become link name. Unless the LONG_SYMLINK |
464 | * flag is set. | 464 | * flag is set. |
465 | */ | 465 | */ |
466 | static void * | 466 | static const char * |
467 | befs_follow_link(struct dentry *dentry, struct nameidata *nd) | 467 | befs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
468 | { | 468 | { |
469 | struct super_block *sb = dentry->d_sb; | 469 | struct super_block *sb = dentry->d_sb; |
470 | struct befs_inode_info *befs_ino = BEFS_I(d_inode(dentry)); | 470 | struct befs_inode_info *befs_ino = BEFS_I(d_inode(dentry)); |
@@ -474,23 +474,20 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
474 | 474 | ||
475 | if (len == 0) { | 475 | if (len == 0) { |
476 | befs_error(sb, "Long symlink with illegal length"); | 476 | befs_error(sb, "Long symlink with illegal length"); |
477 | link = ERR_PTR(-EIO); | 477 | return ERR_PTR(-EIO); |
478 | } else { | ||
479 | befs_debug(sb, "Follow long symlink"); | ||
480 | |||
481 | link = kmalloc(len, GFP_NOFS); | ||
482 | if (!link) { | ||
483 | link = ERR_PTR(-ENOMEM); | ||
484 | } else if (befs_read_lsymlink(sb, data, link, len) != len) { | ||
485 | kfree(link); | ||
486 | befs_error(sb, "Failed to read entire long symlink"); | ||
487 | link = ERR_PTR(-EIO); | ||
488 | } else { | ||
489 | link[len - 1] = '\0'; | ||
490 | } | ||
491 | } | 478 | } |
492 | nd_set_link(nd, link); | 479 | befs_debug(sb, "Follow long symlink"); |
493 | return NULL; | 480 | |
481 | link = kmalloc(len, GFP_NOFS); | ||
482 | if (!link) | ||
483 | return ERR_PTR(-ENOMEM); | ||
484 | if (befs_read_lsymlink(sb, data, link, len) != len) { | ||
485 | kfree(link); | ||
486 | befs_error(sb, "Failed to read entire long symlink"); | ||
487 | return ERR_PTR(-EIO); | ||
488 | } | ||
489 | link[len - 1] = '\0'; | ||
490 | return *cookie = link; | ||
494 | } | 491 | } |
495 | 492 | ||
496 | /* | 493 | /* |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index 252f5c15806b..61012da7e9d8 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -120,7 +120,7 @@ extern struct vfsmount *cifs_dfs_d_automount(struct path *path); | |||
120 | #endif | 120 | #endif |
121 | 121 | ||
122 | /* Functions related to symlinks */ | 122 | /* Functions related to symlinks */ |
123 | extern void *cifs_follow_link(struct dentry *direntry, struct nameidata *nd); | 123 | extern const char *cifs_follow_link(struct dentry *direntry, void **cookie, struct nameidata *nd); |
124 | extern int cifs_readlink(struct dentry *direntry, char __user *buffer, | 124 | extern int cifs_readlink(struct dentry *direntry, char __user *buffer, |
125 | int buflen); | 125 | int buflen); |
126 | extern int cifs_symlink(struct inode *inode, struct dentry *direntry, | 126 | extern int cifs_symlink(struct inode *inode, struct dentry *direntry, |
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 252e672d5604..4a439c2c0c7f 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -626,8 +626,8 @@ cifs_hl_exit: | |||
626 | return rc; | 626 | return rc; |
627 | } | 627 | } |
628 | 628 | ||
629 | void * | 629 | const char * |
630 | cifs_follow_link(struct dentry *direntry, struct nameidata *nd) | 630 | cifs_follow_link(struct dentry *direntry, void **cookie, struct nameidata *nd) |
631 | { | 631 | { |
632 | struct inode *inode = d_inode(direntry); | 632 | struct inode *inode = d_inode(direntry); |
633 | int rc = -ENOMEM; | 633 | int rc = -ENOMEM; |
@@ -643,16 +643,18 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) | |||
643 | 643 | ||
644 | tlink = cifs_sb_tlink(cifs_sb); | 644 | tlink = cifs_sb_tlink(cifs_sb); |
645 | if (IS_ERR(tlink)) { | 645 | if (IS_ERR(tlink)) { |
646 | rc = PTR_ERR(tlink); | 646 | free_xid(xid); |
647 | tlink = NULL; | 647 | return ERR_CAST(tlink); |
648 | goto out; | ||
649 | } | 648 | } |
650 | tcon = tlink_tcon(tlink); | 649 | tcon = tlink_tcon(tlink); |
651 | server = tcon->ses->server; | 650 | server = tcon->ses->server; |
652 | 651 | ||
653 | full_path = build_path_from_dentry(direntry); | 652 | full_path = build_path_from_dentry(direntry); |
654 | if (!full_path) | 653 | if (!full_path) { |
655 | goto out; | 654 | free_xid(xid); |
655 | cifs_put_tlink(tlink); | ||
656 | return ERR_PTR(-ENOMEM); | ||
657 | } | ||
656 | 658 | ||
657 | cifs_dbg(FYI, "Full path: %s inode = 0x%p\n", full_path, inode); | 659 | cifs_dbg(FYI, "Full path: %s inode = 0x%p\n", full_path, inode); |
658 | 660 | ||
@@ -670,17 +672,13 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) | |||
670 | &target_path, cifs_sb); | 672 | &target_path, cifs_sb); |
671 | 673 | ||
672 | kfree(full_path); | 674 | kfree(full_path); |
673 | out: | 675 | free_xid(xid); |
676 | cifs_put_tlink(tlink); | ||
674 | if (rc != 0) { | 677 | if (rc != 0) { |
675 | kfree(target_path); | 678 | kfree(target_path); |
676 | target_path = ERR_PTR(rc); | 679 | return ERR_PTR(rc); |
677 | } | 680 | } |
678 | 681 | return *cookie = target_path; | |
679 | free_xid(xid); | ||
680 | if (tlink) | ||
681 | cifs_put_tlink(tlink); | ||
682 | nd_set_link(nd, target_path); | ||
683 | return NULL; | ||
684 | } | 682 | } |
685 | 683 | ||
686 | int | 684 | int |
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c index cc9f2546ea4a..fac8e8517f33 100644 --- a/fs/configfs/symlink.c +++ b/fs/configfs/symlink.c | |||
@@ -279,30 +279,26 @@ static int configfs_getlink(struct dentry *dentry, char * path) | |||
279 | 279 | ||
280 | } | 280 | } |
281 | 281 | ||
282 | static void *configfs_follow_link(struct dentry *dentry, struct nameidata *nd) | 282 | static const char *configfs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
283 | { | 283 | { |
284 | int error = -ENOMEM; | ||
285 | unsigned long page = get_zeroed_page(GFP_KERNEL); | 284 | unsigned long page = get_zeroed_page(GFP_KERNEL); |
285 | int error; | ||
286 | 286 | ||
287 | if (page) { | 287 | if (!page) |
288 | error = configfs_getlink(dentry, (char *)page); | 288 | return ERR_PTR(-ENOMEM); |
289 | if (!error) { | 289 | |
290 | nd_set_link(nd, (char *)page); | 290 | error = configfs_getlink(dentry, (char *)page); |
291 | return (void *)page; | 291 | if (!error) { |
292 | } | 292 | return *cookie = (void *)page; |
293 | } | 293 | } |
294 | 294 | ||
295 | nd_set_link(nd, ERR_PTR(error)); | 295 | free_page(page); |
296 | return NULL; | 296 | return ERR_PTR(error); |
297 | } | 297 | } |
298 | 298 | ||
299 | static void configfs_put_link(struct dentry *dentry, struct nameidata *nd, | 299 | static void configfs_put_link(struct dentry *dentry, void *cookie) |
300 | void *cookie) | ||
301 | { | 300 | { |
302 | if (cookie) { | 301 | free_page((unsigned long)cookie); |
303 | unsigned long page = (unsigned long)cookie; | ||
304 | free_page(page); | ||
305 | } | ||
306 | } | 302 | } |
307 | 303 | ||
308 | const struct inode_operations configfs_symlink_inode_operations = { | 304 | const struct inode_operations configfs_symlink_inode_operations = { |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index fc850b55db67..cdb9d6c4532d 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -675,18 +675,16 @@ out: | |||
675 | return rc ? ERR_PTR(rc) : buf; | 675 | return rc ? ERR_PTR(rc) : buf; |
676 | } | 676 | } |
677 | 677 | ||
678 | static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd) | 678 | static const char *ecryptfs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
679 | { | 679 | { |
680 | size_t len; | 680 | size_t len; |
681 | char *buf = ecryptfs_readlink_lower(dentry, &len); | 681 | char *buf = ecryptfs_readlink_lower(dentry, &len); |
682 | if (IS_ERR(buf)) | 682 | if (IS_ERR(buf)) |
683 | goto out; | 683 | return buf; |
684 | fsstack_copy_attr_atime(d_inode(dentry), | 684 | fsstack_copy_attr_atime(d_inode(dentry), |
685 | d_inode(ecryptfs_dentry_to_lower(dentry))); | 685 | d_inode(ecryptfs_dentry_to_lower(dentry))); |
686 | buf[len] = '\0'; | 686 | buf[len] = '\0'; |
687 | out: | 687 | return *cookie = buf; |
688 | nd_set_link(nd, buf); | ||
689 | return NULL; | ||
690 | } | 688 | } |
691 | 689 | ||
692 | /** | 690 | /** |
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c index 4264fb1e341a..afec475aaf5c 100644 --- a/fs/ext4/symlink.c +++ b/fs/ext4/symlink.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include "xattr.h" | 23 | #include "xattr.h" |
24 | 24 | ||
25 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | 25 | #ifdef CONFIG_EXT4_FS_ENCRYPTION |
26 | static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd) | 26 | static const char *ext4_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
27 | { | 27 | { |
28 | struct page *cpage = NULL; | 28 | struct page *cpage = NULL; |
29 | char *caddr, *paddr = NULL; | 29 | char *caddr, *paddr = NULL; |
@@ -37,7 +37,7 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
37 | 37 | ||
38 | ctx = ext4_get_fname_crypto_ctx(inode, inode->i_sb->s_blocksize); | 38 | ctx = ext4_get_fname_crypto_ctx(inode, inode->i_sb->s_blocksize); |
39 | if (IS_ERR(ctx)) | 39 | if (IS_ERR(ctx)) |
40 | return ctx; | 40 | return ERR_CAST(ctx); |
41 | 41 | ||
42 | if (ext4_inode_is_fast_symlink(inode)) { | 42 | if (ext4_inode_is_fast_symlink(inode)) { |
43 | caddr = (char *) EXT4_I(inode)->i_data; | 43 | caddr = (char *) EXT4_I(inode)->i_data; |
@@ -46,7 +46,7 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
46 | cpage = read_mapping_page(inode->i_mapping, 0, NULL); | 46 | cpage = read_mapping_page(inode->i_mapping, 0, NULL); |
47 | if (IS_ERR(cpage)) { | 47 | if (IS_ERR(cpage)) { |
48 | ext4_put_fname_crypto_ctx(&ctx); | 48 | ext4_put_fname_crypto_ctx(&ctx); |
49 | return cpage; | 49 | return ERR_CAST(cpage); |
50 | } | 50 | } |
51 | caddr = kmap(cpage); | 51 | caddr = kmap(cpage); |
52 | caddr[size] = 0; | 52 | caddr[size] = 0; |
@@ -77,13 +77,12 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
77 | /* Null-terminate the name */ | 77 | /* Null-terminate the name */ |
78 | if (res <= plen) | 78 | if (res <= plen) |
79 | paddr[res] = '\0'; | 79 | paddr[res] = '\0'; |
80 | nd_set_link(nd, paddr); | ||
81 | ext4_put_fname_crypto_ctx(&ctx); | 80 | ext4_put_fname_crypto_ctx(&ctx); |
82 | if (cpage) { | 81 | if (cpage) { |
83 | kunmap(cpage); | 82 | kunmap(cpage); |
84 | page_cache_release(cpage); | 83 | page_cache_release(cpage); |
85 | } | 84 | } |
86 | return NULL; | 85 | return *cookie = paddr; |
87 | errout: | 86 | errout: |
88 | ext4_put_fname_crypto_ctx(&ctx); | 87 | ext4_put_fname_crypto_ctx(&ctx); |
89 | if (cpage) { | 88 | if (cpage) { |
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 658e8079aaf9..d2947937515e 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c | |||
@@ -296,19 +296,15 @@ fail: | |||
296 | return err; | 296 | return err; |
297 | } | 297 | } |
298 | 298 | ||
299 | static void *f2fs_follow_link(struct dentry *dentry, struct nameidata *nd) | 299 | static const char *f2fs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
300 | { | 300 | { |
301 | struct page *page = page_follow_link_light(dentry, nd); | 301 | const char *link = page_follow_link_light(dentry, cookie, nd); |
302 | 302 | if (!IS_ERR(link) && !*link) { | |
303 | if (IS_ERR_OR_NULL(page)) | 303 | /* this is broken symlink case */ |
304 | return page; | 304 | page_put_link(dentry, *cookie); |
305 | 305 | link = ERR_PTR(-ENOENT); | |
306 | /* this is broken symlink case */ | ||
307 | if (*nd_get_link(nd) == 0) { | ||
308 | page_put_link(dentry, nd, page); | ||
309 | return ERR_PTR(-ENOENT); | ||
310 | } | 306 | } |
311 | return page; | 307 | return link; |
312 | } | 308 | } |
313 | 309 | ||
314 | static int f2fs_symlink(struct inode *dir, struct dentry *dentry, | 310 | static int f2fs_symlink(struct inode *dir, struct dentry *dentry, |
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 0572bca49f15..f9cb260375cf 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -1365,7 +1365,7 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx) | |||
1365 | return err; | 1365 | return err; |
1366 | } | 1366 | } |
1367 | 1367 | ||
1368 | static char *read_link(struct dentry *dentry) | 1368 | static const char *fuse_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
1369 | { | 1369 | { |
1370 | struct inode *inode = d_inode(dentry); | 1370 | struct inode *inode = d_inode(dentry); |
1371 | struct fuse_conn *fc = get_fuse_conn(inode); | 1371 | struct fuse_conn *fc = get_fuse_conn(inode); |
@@ -1389,26 +1389,15 @@ static char *read_link(struct dentry *dentry) | |||
1389 | link = ERR_PTR(ret); | 1389 | link = ERR_PTR(ret); |
1390 | } else { | 1390 | } else { |
1391 | link[ret] = '\0'; | 1391 | link[ret] = '\0'; |
1392 | *cookie = link; | ||
1392 | } | 1393 | } |
1393 | fuse_invalidate_atime(inode); | 1394 | fuse_invalidate_atime(inode); |
1394 | return link; | 1395 | return link; |
1395 | } | 1396 | } |
1396 | 1397 | ||
1397 | static void free_link(char *link) | 1398 | static void fuse_put_link(struct dentry *dentry, void *cookie) |
1398 | { | 1399 | { |
1399 | if (!IS_ERR(link)) | 1400 | free_page((unsigned long) cookie); |
1400 | free_page((unsigned long) link); | ||
1401 | } | ||
1402 | |||
1403 | static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd) | ||
1404 | { | ||
1405 | nd_set_link(nd, read_link(dentry)); | ||
1406 | return NULL; | ||
1407 | } | ||
1408 | |||
1409 | static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c) | ||
1410 | { | ||
1411 | free_link(nd_get_link(nd)); | ||
1412 | } | 1401 | } |
1413 | 1402 | ||
1414 | static int fuse_dir_open(struct inode *inode, struct file *file) | 1403 | static int fuse_dir_open(struct inode *inode, struct file *file) |
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 1b3ca7a2e3fc..f59390aebffb 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -1548,7 +1548,7 @@ out: | |||
1548 | * Returns: 0 on success or error code | 1548 | * Returns: 0 on success or error code |
1549 | */ | 1549 | */ |
1550 | 1550 | ||
1551 | static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) | 1551 | static const char *gfs2_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
1552 | { | 1552 | { |
1553 | struct gfs2_inode *ip = GFS2_I(d_inode(dentry)); | 1553 | struct gfs2_inode *ip = GFS2_I(d_inode(dentry)); |
1554 | struct gfs2_holder i_gh; | 1554 | struct gfs2_holder i_gh; |
@@ -1561,8 +1561,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
1561 | error = gfs2_glock_nq(&i_gh); | 1561 | error = gfs2_glock_nq(&i_gh); |
1562 | if (error) { | 1562 | if (error) { |
1563 | gfs2_holder_uninit(&i_gh); | 1563 | gfs2_holder_uninit(&i_gh); |
1564 | nd_set_link(nd, ERR_PTR(error)); | 1564 | return ERR_PTR(error); |
1565 | return NULL; | ||
1566 | } | 1565 | } |
1567 | 1566 | ||
1568 | size = (unsigned int)i_size_read(&ip->i_inode); | 1567 | size = (unsigned int)i_size_read(&ip->i_inode); |
@@ -1586,8 +1585,9 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
1586 | brelse(dibh); | 1585 | brelse(dibh); |
1587 | out: | 1586 | out: |
1588 | gfs2_glock_dq_uninit(&i_gh); | 1587 | gfs2_glock_dq_uninit(&i_gh); |
1589 | nd_set_link(nd, buf); | 1588 | if (!IS_ERR(buf)) |
1590 | return NULL; | 1589 | *cookie = buf; |
1590 | return buf; | ||
1591 | } | 1591 | } |
1592 | 1592 | ||
1593 | /** | 1593 | /** |
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index ef263174acd2..f650ed661fab 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c | |||
@@ -892,7 +892,7 @@ static const struct inode_operations hostfs_dir_iops = { | |||
892 | .setattr = hostfs_setattr, | 892 | .setattr = hostfs_setattr, |
893 | }; | 893 | }; |
894 | 894 | ||
895 | static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd) | 895 | static const char *hostfs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
896 | { | 896 | { |
897 | char *link = __getname(); | 897 | char *link = __getname(); |
898 | if (link) { | 898 | if (link) { |
@@ -906,21 +906,18 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
906 | } | 906 | } |
907 | if (err < 0) { | 907 | if (err < 0) { |
908 | __putname(link); | 908 | __putname(link); |
909 | link = ERR_PTR(err); | 909 | return ERR_PTR(err); |
910 | } | 910 | } |
911 | } else { | 911 | } else { |
912 | link = ERR_PTR(-ENOMEM); | 912 | return ERR_PTR(-ENOMEM); |
913 | } | 913 | } |
914 | 914 | ||
915 | nd_set_link(nd, link); | 915 | return *cookie = link; |
916 | return NULL; | ||
917 | } | 916 | } |
918 | 917 | ||
919 | static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie) | 918 | static void hostfs_put_link(struct dentry *dentry, void *cookie) |
920 | { | 919 | { |
921 | char *s = nd_get_link(nd); | 920 | __putname(cookie); |
922 | if (!IS_ERR(s)) | ||
923 | __putname(s); | ||
924 | } | 921 | } |
925 | 922 | ||
926 | static const struct inode_operations hostfs_link_iops = { | 923 | static const struct inode_operations hostfs_link_iops = { |
diff --git a/fs/hppfs/hppfs.c b/fs/hppfs/hppfs.c index fa2bd5366ecf..b8f24d3b04ee 100644 --- a/fs/hppfs/hppfs.c +++ b/fs/hppfs/hppfs.c | |||
@@ -642,20 +642,19 @@ static int hppfs_readlink(struct dentry *dentry, char __user *buffer, | |||
642 | buflen); | 642 | buflen); |
643 | } | 643 | } |
644 | 644 | ||
645 | static void *hppfs_follow_link(struct dentry *dentry, struct nameidata *nd) | 645 | static const char *hppfs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
646 | { | 646 | { |
647 | struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry; | 647 | struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry; |
648 | 648 | ||
649 | return d_inode(proc_dentry)->i_op->follow_link(proc_dentry, nd); | 649 | return d_inode(proc_dentry)->i_op->follow_link(proc_dentry, cookie, nd); |
650 | } | 650 | } |
651 | 651 | ||
652 | static void hppfs_put_link(struct dentry *dentry, struct nameidata *nd, | 652 | static void hppfs_put_link(struct dentry *dentry, void *cookie) |
653 | void *cookie) | ||
654 | { | 653 | { |
655 | struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry; | 654 | struct dentry *proc_dentry = HPPFS_I(d_inode(dentry))->proc_dentry; |
656 | 655 | ||
657 | if (d_inode(proc_dentry)->i_op->put_link) | 656 | if (d_inode(proc_dentry)->i_op->put_link) |
658 | d_inode(proc_dentry)->i_op->put_link(proc_dentry, nd, cookie); | 657 | d_inode(proc_dentry)->i_op->put_link(proc_dentry, cookie); |
659 | } | 658 | } |
660 | 659 | ||
661 | static const struct inode_operations hppfs_dir_iops = { | 660 | static const struct inode_operations hppfs_dir_iops = { |
diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c index 8a198898e39a..3c7e799974a2 100644 --- a/fs/kernfs/symlink.c +++ b/fs/kernfs/symlink.c | |||
@@ -112,25 +112,23 @@ static int kernfs_getlink(struct dentry *dentry, char *path) | |||
112 | return error; | 112 | return error; |
113 | } | 113 | } |
114 | 114 | ||
115 | static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd) | 115 | static const char *kernfs_iop_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
116 | { | 116 | { |
117 | int error = -ENOMEM; | 117 | int error = -ENOMEM; |
118 | unsigned long page = get_zeroed_page(GFP_KERNEL); | 118 | unsigned long page = get_zeroed_page(GFP_KERNEL); |
119 | if (page) { | 119 | if (!page) |
120 | error = kernfs_getlink(dentry, (char *) page); | 120 | return ERR_PTR(-ENOMEM); |
121 | if (error < 0) | 121 | error = kernfs_getlink(dentry, (char *)page); |
122 | free_page((unsigned long)page); | 122 | if (unlikely(error < 0)) { |
123 | free_page((unsigned long)page); | ||
124 | return ERR_PTR(error); | ||
123 | } | 125 | } |
124 | nd_set_link(nd, error ? ERR_PTR(error) : (char *)page); | 126 | return *cookie = (char *)page; |
125 | return NULL; | ||
126 | } | 127 | } |
127 | 128 | ||
128 | static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd, | 129 | static void kernfs_iop_put_link(struct dentry *dentry, void *cookie) |
129 | void *cookie) | ||
130 | { | 130 | { |
131 | char *page = nd_get_link(nd); | 131 | free_page((unsigned long)cookie); |
132 | if (!IS_ERR(page)) | ||
133 | free_page((unsigned long)page); | ||
134 | } | 132 | } |
135 | 133 | ||
136 | const struct inode_operations kernfs_symlink_iops = { | 134 | const struct inode_operations kernfs_symlink_iops = { |
diff --git a/fs/libfs.c b/fs/libfs.c index 72e4e015455f..0c83fde20dbd 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -1024,12 +1024,9 @@ int noop_fsync(struct file *file, loff_t start, loff_t end, int datasync) | |||
1024 | } | 1024 | } |
1025 | EXPORT_SYMBOL(noop_fsync); | 1025 | EXPORT_SYMBOL(noop_fsync); |
1026 | 1026 | ||
1027 | void kfree_put_link(struct dentry *dentry, struct nameidata *nd, | 1027 | void kfree_put_link(struct dentry *dentry, void *cookie) |
1028 | void *cookie) | ||
1029 | { | 1028 | { |
1030 | char *s = nd_get_link(nd); | 1029 | kfree(cookie); |
1031 | if (!IS_ERR(s)) | ||
1032 | kfree(s); | ||
1033 | } | 1030 | } |
1034 | EXPORT_SYMBOL(kfree_put_link); | 1031 | EXPORT_SYMBOL(kfree_put_link); |
1035 | 1032 | ||
@@ -1094,10 +1091,9 @@ simple_nosetlease(struct file *filp, long arg, struct file_lock **flp, | |||
1094 | } | 1091 | } |
1095 | EXPORT_SYMBOL(simple_nosetlease); | 1092 | EXPORT_SYMBOL(simple_nosetlease); |
1096 | 1093 | ||
1097 | void *simple_follow_link(struct dentry *dentry, struct nameidata *nd) | 1094 | const char *simple_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
1098 | { | 1095 | { |
1099 | nd_set_link(nd, d_inode(dentry)->i_link); | 1096 | return d_inode(dentry)->i_link; |
1100 | return NULL; | ||
1101 | } | 1097 | } |
1102 | EXPORT_SYMBOL(simple_follow_link); | 1098 | EXPORT_SYMBOL(simple_follow_link); |
1103 | 1099 | ||
diff --git a/fs/namei.c b/fs/namei.c index ab2bcbdbd683..aeca44877371 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -502,7 +502,6 @@ struct nameidata { | |||
502 | int last_type; | 502 | int last_type; |
503 | unsigned depth; | 503 | unsigned depth; |
504 | struct file *base; | 504 | struct file *base; |
505 | char *saved_names[MAX_NESTED_LINKS + 1]; | ||
506 | }; | 505 | }; |
507 | 506 | ||
508 | /* | 507 | /* |
@@ -713,23 +712,11 @@ void nd_jump_link(struct nameidata *nd, struct path *path) | |||
713 | nd->flags |= LOOKUP_JUMPED; | 712 | nd->flags |= LOOKUP_JUMPED; |
714 | } | 713 | } |
715 | 714 | ||
716 | void nd_set_link(struct nameidata *nd, char *path) | ||
717 | { | ||
718 | nd->saved_names[nd->depth] = path; | ||
719 | } | ||
720 | EXPORT_SYMBOL(nd_set_link); | ||
721 | |||
722 | char *nd_get_link(struct nameidata *nd) | ||
723 | { | ||
724 | return nd->saved_names[nd->depth]; | ||
725 | } | ||
726 | EXPORT_SYMBOL(nd_get_link); | ||
727 | |||
728 | static inline void put_link(struct nameidata *nd, struct path *link, void *cookie) | 715 | static inline void put_link(struct nameidata *nd, struct path *link, void *cookie) |
729 | { | 716 | { |
730 | struct inode *inode = link->dentry->d_inode; | 717 | struct inode *inode = link->dentry->d_inode; |
731 | if (inode->i_op->put_link) | 718 | if (cookie && inode->i_op->put_link) |
732 | inode->i_op->put_link(link->dentry, nd, cookie); | 719 | inode->i_op->put_link(link->dentry, cookie); |
733 | path_put(link); | 720 | path_put(link); |
734 | } | 721 | } |
735 | 722 | ||
@@ -854,7 +841,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p) | |||
854 | { | 841 | { |
855 | struct dentry *dentry = link->dentry; | 842 | struct dentry *dentry = link->dentry; |
856 | int error; | 843 | int error; |
857 | char *s; | 844 | const char *s; |
858 | 845 | ||
859 | BUG_ON(nd->flags & LOOKUP_RCU); | 846 | BUG_ON(nd->flags & LOOKUP_RCU); |
860 | 847 | ||
@@ -869,26 +856,20 @@ follow_link(struct path *link, struct nameidata *nd, void **p) | |||
869 | current->total_link_count++; | 856 | current->total_link_count++; |
870 | 857 | ||
871 | touch_atime(link); | 858 | touch_atime(link); |
872 | nd_set_link(nd, NULL); | ||
873 | 859 | ||
874 | error = security_inode_follow_link(dentry); | 860 | error = security_inode_follow_link(dentry); |
875 | if (error) | 861 | if (error) |
876 | goto out_put_nd_path; | 862 | goto out_put_nd_path; |
877 | 863 | ||
878 | nd->last_type = LAST_BIND; | 864 | nd->last_type = LAST_BIND; |
879 | *p = dentry->d_inode->i_op->follow_link(dentry, nd); | 865 | *p = NULL; |
880 | error = PTR_ERR(*p); | 866 | s = dentry->d_inode->i_op->follow_link(dentry, p, nd); |
881 | if (IS_ERR(*p)) | 867 | error = PTR_ERR(s); |
868 | if (IS_ERR(s)) | ||
882 | goto out_put_nd_path; | 869 | goto out_put_nd_path; |
883 | 870 | ||
884 | error = 0; | 871 | error = 0; |
885 | s = nd_get_link(nd); | ||
886 | if (s) { | 872 | if (s) { |
887 | if (unlikely(IS_ERR(s))) { | ||
888 | path_put(&nd->path); | ||
889 | put_link(nd, link, *p); | ||
890 | return PTR_ERR(s); | ||
891 | } | ||
892 | if (*s == '/') { | 873 | if (*s == '/') { |
893 | if (!nd->root.mnt) | 874 | if (!nd->root.mnt) |
894 | set_root(nd); | 875 | set_root(nd); |
@@ -906,7 +887,6 @@ follow_link(struct path *link, struct nameidata *nd, void **p) | |||
906 | return error; | 887 | return error; |
907 | 888 | ||
908 | out_put_nd_path: | 889 | out_put_nd_path: |
909 | *p = NULL; | ||
910 | path_put(&nd->path); | 890 | path_put(&nd->path); |
911 | path_put(link); | 891 | path_put(link); |
912 | return error; | 892 | return error; |
@@ -4430,18 +4410,15 @@ EXPORT_SYMBOL(readlink_copy); | |||
4430 | */ | 4410 | */ |
4431 | int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen) | 4411 | int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen) |
4432 | { | 4412 | { |
4433 | struct nameidata nd; | ||
4434 | void *cookie; | 4413 | void *cookie; |
4414 | const char *link = dentry->d_inode->i_op->follow_link(dentry, &cookie, NULL); | ||
4435 | int res; | 4415 | int res; |
4436 | 4416 | ||
4437 | nd.depth = 0; | 4417 | if (IS_ERR(link)) |
4438 | cookie = dentry->d_inode->i_op->follow_link(dentry, &nd); | 4418 | return PTR_ERR(link); |
4439 | if (IS_ERR(cookie)) | 4419 | res = readlink_copy(buffer, buflen, link); |
4440 | return PTR_ERR(cookie); | 4420 | if (cookie && dentry->d_inode->i_op->put_link) |
4441 | 4421 | dentry->d_inode->i_op->put_link(dentry, cookie); | |
4442 | res = readlink_copy(buffer, buflen, nd_get_link(&nd)); | ||
4443 | if (dentry->d_inode->i_op->put_link) | ||
4444 | dentry->d_inode->i_op->put_link(dentry, &nd, cookie); | ||
4445 | return res; | 4422 | return res; |
4446 | } | 4423 | } |
4447 | EXPORT_SYMBOL(generic_readlink); | 4424 | EXPORT_SYMBOL(generic_readlink); |
@@ -4473,22 +4450,21 @@ int page_readlink(struct dentry *dentry, char __user *buffer, int buflen) | |||
4473 | } | 4450 | } |
4474 | EXPORT_SYMBOL(page_readlink); | 4451 | EXPORT_SYMBOL(page_readlink); |
4475 | 4452 | ||
4476 | void *page_follow_link_light(struct dentry *dentry, struct nameidata *nd) | 4453 | const char *page_follow_link_light(struct dentry *dentry, void **cookie, struct nameidata *nd) |
4477 | { | 4454 | { |
4478 | struct page *page = NULL; | 4455 | struct page *page = NULL; |
4479 | nd_set_link(nd, page_getlink(dentry, &page)); | 4456 | char *res = page_getlink(dentry, &page); |
4480 | return page; | 4457 | if (!IS_ERR(res)) |
4458 | *cookie = page; | ||
4459 | return res; | ||
4481 | } | 4460 | } |
4482 | EXPORT_SYMBOL(page_follow_link_light); | 4461 | EXPORT_SYMBOL(page_follow_link_light); |
4483 | 4462 | ||
4484 | void page_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie) | 4463 | void page_put_link(struct dentry *dentry, void *cookie) |
4485 | { | 4464 | { |
4486 | struct page *page = cookie; | 4465 | struct page *page = cookie; |
4487 | 4466 | kunmap(page); | |
4488 | if (page) { | 4467 | page_cache_release(page); |
4489 | kunmap(page); | ||
4490 | page_cache_release(page); | ||
4491 | } | ||
4492 | } | 4468 | } |
4493 | EXPORT_SYMBOL(page_put_link); | 4469 | EXPORT_SYMBOL(page_put_link); |
4494 | 4470 | ||
diff --git a/fs/nfs/symlink.c b/fs/nfs/symlink.c index 2d56200655fe..c992b200ae7e 100644 --- a/fs/nfs/symlink.c +++ b/fs/nfs/symlink.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/stat.h> | 20 | #include <linux/stat.h> |
21 | #include <linux/mm.h> | 21 | #include <linux/mm.h> |
22 | #include <linux/string.h> | 22 | #include <linux/string.h> |
23 | #include <linux/namei.h> | ||
24 | 23 | ||
25 | /* Symlink caching in the page cache is even more simplistic | 24 | /* Symlink caching in the page cache is even more simplistic |
26 | * and straight-forward than readdir caching. | 25 | * and straight-forward than readdir caching. |
@@ -43,7 +42,7 @@ error: | |||
43 | return -EIO; | 42 | return -EIO; |
44 | } | 43 | } |
45 | 44 | ||
46 | static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd) | 45 | static const char *nfs_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
47 | { | 46 | { |
48 | struct inode *inode = d_inode(dentry); | 47 | struct inode *inode = d_inode(dentry); |
49 | struct page *page; | 48 | struct page *page; |
@@ -51,19 +50,13 @@ static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
51 | 50 | ||
52 | err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping)); | 51 | err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping)); |
53 | if (err) | 52 | if (err) |
54 | goto read_failed; | 53 | return err; |
55 | page = read_cache_page(&inode->i_data, 0, | 54 | page = read_cache_page(&inode->i_data, 0, |
56 | (filler_t *)nfs_symlink_filler, inode); | 55 | (filler_t *)nfs_symlink_filler, inode); |
57 | if (IS_ERR(page)) { | 56 | if (IS_ERR(page)) |
58 | err = page; | 57 | return ERR_CAST(page); |
59 | goto read_failed; | 58 | *cookie = page; |
60 | } | 59 | return kmap(page); |
61 | nd_set_link(nd, kmap(page)); | ||
62 | return page; | ||
63 | |||
64 | read_failed: | ||
65 | nd_set_link(nd, err); | ||
66 | return NULL; | ||
67 | } | 60 | } |
68 | 61 | ||
69 | /* | 62 | /* |
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 1b4b9c5e51b7..235ad42afb57 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c | |||
@@ -140,12 +140,12 @@ struct ovl_link_data { | |||
140 | void *cookie; | 140 | void *cookie; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd) | 143 | static const char *ovl_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
144 | { | 144 | { |
145 | void *ret; | ||
146 | struct dentry *realdentry; | 145 | struct dentry *realdentry; |
147 | struct inode *realinode; | 146 | struct inode *realinode; |
148 | struct ovl_link_data *data = NULL; | 147 | struct ovl_link_data *data = NULL; |
148 | const char *ret; | ||
149 | 149 | ||
150 | realdentry = ovl_dentry_real(dentry); | 150 | realdentry = ovl_dentry_real(dentry); |
151 | realinode = realdentry->d_inode; | 151 | realinode = realdentry->d_inode; |
@@ -160,19 +160,21 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd) | |||
160 | data->realdentry = realdentry; | 160 | data->realdentry = realdentry; |
161 | } | 161 | } |
162 | 162 | ||
163 | ret = realinode->i_op->follow_link(realdentry, nd); | 163 | ret = realinode->i_op->follow_link(realdentry, cookie, nd); |
164 | if (IS_ERR(ret)) { | 164 | if (IS_ERR_OR_NULL(ret)) { |
165 | kfree(data); | 165 | kfree(data); |
166 | return ret; | 166 | return ret; |
167 | } | 167 | } |
168 | 168 | ||
169 | if (data) | 169 | if (data) |
170 | data->cookie = ret; | 170 | data->cookie = *cookie; |
171 | 171 | ||
172 | return data; | 172 | *cookie = data; |
173 | |||
174 | return ret; | ||
173 | } | 175 | } |
174 | 176 | ||
175 | static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c) | 177 | static void ovl_put_link(struct dentry *dentry, void *c) |
176 | { | 178 | { |
177 | struct inode *realinode; | 179 | struct inode *realinode; |
178 | struct ovl_link_data *data = c; | 180 | struct ovl_link_data *data = c; |
@@ -181,7 +183,7 @@ static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c) | |||
181 | return; | 183 | return; |
182 | 184 | ||
183 | realinode = data->realdentry->d_inode; | 185 | realinode = data->realdentry->d_inode; |
184 | realinode->i_op->put_link(data->realdentry, nd, data->cookie); | 186 | realinode->i_op->put_link(data->realdentry, data->cookie); |
185 | kfree(data); | 187 | kfree(data); |
186 | } | 188 | } |
187 | 189 | ||
diff --git a/fs/proc/base.c b/fs/proc/base.c index 093ca14f5701..52652f86b187 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -1380,7 +1380,7 @@ static int proc_exe_link(struct dentry *dentry, struct path *exe_path) | |||
1380 | return -ENOENT; | 1380 | return -ENOENT; |
1381 | } | 1381 | } |
1382 | 1382 | ||
1383 | static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) | 1383 | static const char *proc_pid_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
1384 | { | 1384 | { |
1385 | struct inode *inode = d_inode(dentry); | 1385 | struct inode *inode = d_inode(dentry); |
1386 | struct path path; | 1386 | struct path path; |
diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 8272aaba1bb0..acd51d75387d 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <linux/mount.h> | 24 | #include <linux/mount.h> |
25 | #include <linux/magic.h> | 25 | #include <linux/magic.h> |
26 | #include <linux/namei.h> | ||
27 | 26 | ||
28 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
29 | 28 | ||
@@ -394,16 +393,16 @@ static const struct file_operations proc_reg_file_ops_no_compat = { | |||
394 | }; | 393 | }; |
395 | #endif | 394 | #endif |
396 | 395 | ||
397 | static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd) | 396 | static const char *proc_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
398 | { | 397 | { |
399 | struct proc_dir_entry *pde = PDE(d_inode(dentry)); | 398 | struct proc_dir_entry *pde = PDE(d_inode(dentry)); |
400 | if (unlikely(!use_pde(pde))) | 399 | if (unlikely(!use_pde(pde))) |
401 | return ERR_PTR(-EINVAL); | 400 | return ERR_PTR(-EINVAL); |
402 | nd_set_link(nd, pde->data); | 401 | *cookie = pde; |
403 | return pde; | 402 | return pde->data; |
404 | } | 403 | } |
405 | 404 | ||
406 | static void proc_put_link(struct dentry *dentry, struct nameidata *nd, void *p) | 405 | static void proc_put_link(struct dentry *dentry, void *p) |
407 | { | 406 | { |
408 | unuse_pde(p); | 407 | unuse_pde(p); |
409 | } | 408 | } |
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index e512642dbbdc..10d24dd096e8 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c | |||
@@ -30,7 +30,7 @@ static const struct proc_ns_operations *ns_entries[] = { | |||
30 | &mntns_operations, | 30 | &mntns_operations, |
31 | }; | 31 | }; |
32 | 32 | ||
33 | static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd) | 33 | static const char *proc_ns_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
34 | { | 34 | { |
35 | struct inode *inode = d_inode(dentry); | 35 | struct inode *inode = d_inode(dentry); |
36 | const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; | 36 | const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops; |
diff --git a/fs/proc/self.c b/fs/proc/self.c index 6195b4a7c3b1..ad333946b53a 100644 --- a/fs/proc/self.c +++ b/fs/proc/self.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #include <linux/sched.h> | 1 | #include <linux/sched.h> |
2 | #include <linux/namei.h> | ||
3 | #include <linux/slab.h> | 2 | #include <linux/slab.h> |
4 | #include <linux/pid_namespace.h> | 3 | #include <linux/pid_namespace.h> |
5 | #include "internal.h" | 4 | #include "internal.h" |
@@ -19,21 +18,20 @@ static int proc_self_readlink(struct dentry *dentry, char __user *buffer, | |||
19 | return readlink_copy(buffer, buflen, tmp); | 18 | return readlink_copy(buffer, buflen, tmp); |
20 | } | 19 | } |
21 | 20 | ||
22 | static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd) | 21 | static const char *proc_self_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
23 | { | 22 | { |
24 | struct pid_namespace *ns = dentry->d_sb->s_fs_info; | 23 | struct pid_namespace *ns = dentry->d_sb->s_fs_info; |
25 | pid_t tgid = task_tgid_nr_ns(current, ns); | 24 | pid_t tgid = task_tgid_nr_ns(current, ns); |
26 | char *name = ERR_PTR(-ENOENT); | 25 | char *name; |
27 | if (tgid) { | 26 | |
28 | /* 11 for max length of signed int in decimal + NULL term */ | 27 | if (!tgid) |
29 | name = kmalloc(12, GFP_KERNEL); | 28 | return ERR_PTR(-ENOENT); |
30 | if (!name) | 29 | /* 11 for max length of signed int in decimal + NULL term */ |
31 | name = ERR_PTR(-ENOMEM); | 30 | name = kmalloc(12, GFP_KERNEL); |
32 | else | 31 | if (!name) |
33 | sprintf(name, "%d", tgid); | 32 | return ERR_PTR(-ENOMEM); |
34 | } | 33 | sprintf(name, "%d", tgid); |
35 | nd_set_link(nd, name); | 34 | return *cookie = name; |
36 | return NULL; | ||
37 | } | 35 | } |
38 | 36 | ||
39 | static const struct inode_operations proc_self_inode_operations = { | 37 | static const struct inode_operations proc_self_inode_operations = { |
diff --git a/fs/proc/thread_self.c b/fs/proc/thread_self.c index a8371993b4fb..85c96e0d7aaa 100644 --- a/fs/proc/thread_self.c +++ b/fs/proc/thread_self.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #include <linux/sched.h> | 1 | #include <linux/sched.h> |
2 | #include <linux/namei.h> | ||
3 | #include <linux/slab.h> | 2 | #include <linux/slab.h> |
4 | #include <linux/pid_namespace.h> | 3 | #include <linux/pid_namespace.h> |
5 | #include "internal.h" | 4 | #include "internal.h" |
@@ -20,21 +19,20 @@ static int proc_thread_self_readlink(struct dentry *dentry, char __user *buffer, | |||
20 | return readlink_copy(buffer, buflen, tmp); | 19 | return readlink_copy(buffer, buflen, tmp); |
21 | } | 20 | } |
22 | 21 | ||
23 | static void *proc_thread_self_follow_link(struct dentry *dentry, struct nameidata *nd) | 22 | static const char *proc_thread_self_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
24 | { | 23 | { |
25 | struct pid_namespace *ns = dentry->d_sb->s_fs_info; | 24 | struct pid_namespace *ns = dentry->d_sb->s_fs_info; |
26 | pid_t tgid = task_tgid_nr_ns(current, ns); | 25 | pid_t tgid = task_tgid_nr_ns(current, ns); |
27 | pid_t pid = task_pid_nr_ns(current, ns); | 26 | pid_t pid = task_pid_nr_ns(current, ns); |
28 | char *name = ERR_PTR(-ENOENT); | 27 | char *name; |
29 | if (pid) { | 28 | |
30 | name = kmalloc(PROC_NUMBUF + 6 + PROC_NUMBUF, GFP_KERNEL); | 29 | if (!pid) |
31 | if (!name) | 30 | return ERR_PTR(-ENOENT); |
32 | name = ERR_PTR(-ENOMEM); | 31 | name = kmalloc(PROC_NUMBUF + 6 + PROC_NUMBUF, GFP_KERNEL); |
33 | else | 32 | if (!name) |
34 | sprintf(name, "%d/task/%d", tgid, pid); | 33 | return ERR_PTR(-ENOMEM); |
35 | } | 34 | sprintf(name, "%d/task/%d", tgid, pid); |
36 | nd_set_link(nd, name); | 35 | return *cookie = name; |
37 | return NULL; | ||
38 | } | 36 | } |
39 | 37 | ||
40 | static const struct inode_operations proc_thread_self_inode_operations = { | 38 | static const struct inode_operations proc_thread_self_inode_operations = { |
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index f4cd7204e236..26c4dcb1ef56 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c | |||
@@ -41,7 +41,6 @@ | |||
41 | 41 | ||
42 | #include <linux/capability.h> | 42 | #include <linux/capability.h> |
43 | #include <linux/xattr.h> | 43 | #include <linux/xattr.h> |
44 | #include <linux/namei.h> | ||
45 | #include <linux/posix_acl.h> | 44 | #include <linux/posix_acl.h> |
46 | #include <linux/security.h> | 45 | #include <linux/security.h> |
47 | #include <linux/fiemap.h> | 46 | #include <linux/fiemap.h> |
@@ -414,9 +413,10 @@ xfs_vn_rename( | |||
414 | * we need to be very careful about how much stack we use. | 413 | * we need to be very careful about how much stack we use. |
415 | * uio is kmalloced for this reason... | 414 | * uio is kmalloced for this reason... |
416 | */ | 415 | */ |
417 | STATIC void * | 416 | STATIC const char * |
418 | xfs_vn_follow_link( | 417 | xfs_vn_follow_link( |
419 | struct dentry *dentry, | 418 | struct dentry *dentry, |
419 | void **cookie, | ||
420 | struct nameidata *nd) | 420 | struct nameidata *nd) |
421 | { | 421 | { |
422 | char *link; | 422 | char *link; |
@@ -430,14 +430,12 @@ xfs_vn_follow_link( | |||
430 | if (unlikely(error)) | 430 | if (unlikely(error)) |
431 | goto out_kfree; | 431 | goto out_kfree; |
432 | 432 | ||
433 | nd_set_link(nd, link); | 433 | return *cookie = link; |
434 | return NULL; | ||
435 | 434 | ||
436 | out_kfree: | 435 | out_kfree: |
437 | kfree(link); | 436 | kfree(link); |
438 | out_err: | 437 | out_err: |
439 | nd_set_link(nd, ERR_PTR(error)); | 438 | return ERR_PTR(error); |
440 | return NULL; | ||
441 | } | 439 | } |
442 | 440 | ||
443 | STATIC int | 441 | STATIC int |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 0ac758fcff00..9ab934113a28 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1608,12 +1608,12 @@ struct file_operations { | |||
1608 | 1608 | ||
1609 | struct inode_operations { | 1609 | struct inode_operations { |
1610 | struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int); | 1610 | struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int); |
1611 | void * (*follow_link) (struct dentry *, struct nameidata *); | 1611 | const char * (*follow_link) (struct dentry *, void **, struct nameidata *); |
1612 | int (*permission) (struct inode *, int); | 1612 | int (*permission) (struct inode *, int); |
1613 | struct posix_acl * (*get_acl)(struct inode *, int); | 1613 | struct posix_acl * (*get_acl)(struct inode *, int); |
1614 | 1614 | ||
1615 | int (*readlink) (struct dentry *, char __user *,int); | 1615 | int (*readlink) (struct dentry *, char __user *,int); |
1616 | void (*put_link) (struct dentry *, struct nameidata *, void *); | 1616 | void (*put_link) (struct dentry *, void *); |
1617 | 1617 | ||
1618 | int (*create) (struct inode *,struct dentry *, umode_t, bool); | 1618 | int (*create) (struct inode *,struct dentry *, umode_t, bool); |
1619 | int (*link) (struct dentry *,struct inode *,struct dentry *); | 1619 | int (*link) (struct dentry *,struct inode *,struct dentry *); |
@@ -2705,13 +2705,13 @@ extern const struct file_operations generic_ro_fops; | |||
2705 | 2705 | ||
2706 | extern int readlink_copy(char __user *, int, const char *); | 2706 | extern int readlink_copy(char __user *, int, const char *); |
2707 | extern int page_readlink(struct dentry *, char __user *, int); | 2707 | extern int page_readlink(struct dentry *, char __user *, int); |
2708 | extern void *page_follow_link_light(struct dentry *, struct nameidata *); | 2708 | extern const char *page_follow_link_light(struct dentry *, void **, struct nameidata *); |
2709 | extern void page_put_link(struct dentry *, struct nameidata *, void *); | 2709 | extern void page_put_link(struct dentry *, void *); |
2710 | extern int __page_symlink(struct inode *inode, const char *symname, int len, | 2710 | extern int __page_symlink(struct inode *inode, const char *symname, int len, |
2711 | int nofs); | 2711 | int nofs); |
2712 | extern int page_symlink(struct inode *inode, const char *symname, int len); | 2712 | extern int page_symlink(struct inode *inode, const char *symname, int len); |
2713 | extern const struct inode_operations page_symlink_inode_operations; | 2713 | extern const struct inode_operations page_symlink_inode_operations; |
2714 | extern void kfree_put_link(struct dentry *, struct nameidata *, void *); | 2714 | extern void kfree_put_link(struct dentry *, void *); |
2715 | extern int generic_readlink(struct dentry *, char __user *, int); | 2715 | extern int generic_readlink(struct dentry *, char __user *, int); |
2716 | extern void generic_fillattr(struct inode *, struct kstat *); | 2716 | extern void generic_fillattr(struct inode *, struct kstat *); |
2717 | int vfs_getattr_nosec(struct path *path, struct kstat *stat); | 2717 | int vfs_getattr_nosec(struct path *path, struct kstat *stat); |
@@ -2722,7 +2722,7 @@ void __inode_sub_bytes(struct inode *inode, loff_t bytes); | |||
2722 | void inode_sub_bytes(struct inode *inode, loff_t bytes); | 2722 | void inode_sub_bytes(struct inode *inode, loff_t bytes); |
2723 | loff_t inode_get_bytes(struct inode *inode); | 2723 | loff_t inode_get_bytes(struct inode *inode); |
2724 | void inode_set_bytes(struct inode *inode, loff_t bytes); | 2724 | void inode_set_bytes(struct inode *inode, loff_t bytes); |
2725 | void *simple_follow_link(struct dentry *, struct nameidata *); | 2725 | const char *simple_follow_link(struct dentry *, void **, struct nameidata *); |
2726 | extern const struct inode_operations simple_symlink_inode_operations; | 2726 | extern const struct inode_operations simple_symlink_inode_operations; |
2727 | 2727 | ||
2728 | extern int iterate_dir(struct file *, struct dir_context *); | 2728 | extern int iterate_dir(struct file *, struct dir_context *); |
diff --git a/include/linux/namei.h b/include/linux/namei.h index c8990779f0c3..a5d5bed2c0e1 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h | |||
@@ -71,8 +71,6 @@ extern struct dentry *lock_rename(struct dentry *, struct dentry *); | |||
71 | extern void unlock_rename(struct dentry *, struct dentry *); | 71 | extern void unlock_rename(struct dentry *, struct dentry *); |
72 | 72 | ||
73 | extern void nd_jump_link(struct nameidata *nd, struct path *path); | 73 | extern void nd_jump_link(struct nameidata *nd, struct path *path); |
74 | extern void nd_set_link(struct nameidata *nd, char *path); | ||
75 | extern char *nd_get_link(struct nameidata *nd); | ||
76 | 74 | ||
77 | static inline void nd_terminate_link(void *name, size_t len, size_t maxlen) | 75 | static inline void nd_terminate_link(void *name, size_t len, size_t maxlen) |
78 | { | 76 | { |
diff --git a/mm/shmem.c b/mm/shmem.c index 7f6e2f889122..d1693dcb4285 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -2475,24 +2475,23 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s | |||
2475 | return 0; | 2475 | return 0; |
2476 | } | 2476 | } |
2477 | 2477 | ||
2478 | static void *shmem_follow_link(struct dentry *dentry, struct nameidata *nd) | 2478 | static const char *shmem_follow_link(struct dentry *dentry, void **cookie, struct nameidata *nd) |
2479 | { | 2479 | { |
2480 | struct page *page = NULL; | 2480 | struct page *page = NULL; |
2481 | int error = shmem_getpage(d_inode(dentry), 0, &page, SGP_READ, NULL); | 2481 | int error = shmem_getpage(d_inode(dentry), 0, &page, SGP_READ, NULL); |
2482 | nd_set_link(nd, error ? ERR_PTR(error) : kmap(page)); | 2482 | if (error) |
2483 | if (page) | 2483 | return ERR_PTR(error); |
2484 | unlock_page(page); | 2484 | unlock_page(page); |
2485 | return page; | 2485 | *cookie = page; |
2486 | return kmap(page); | ||
2486 | } | 2487 | } |
2487 | 2488 | ||
2488 | static void shmem_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie) | 2489 | static void shmem_put_link(struct dentry *dentry, void *cookie) |
2489 | { | 2490 | { |
2490 | if (!IS_ERR(nd_get_link(nd))) { | 2491 | struct page *page = cookie; |
2491 | struct page *page = cookie; | 2492 | kunmap(page); |
2492 | kunmap(page); | 2493 | mark_page_accessed(page); |
2493 | mark_page_accessed(page); | 2494 | page_cache_release(page); |
2494 | page_cache_release(page); | ||
2495 | } | ||
2496 | } | 2495 | } |
2497 | 2496 | ||
2498 | #ifdef CONFIG_TMPFS_XATTR | 2497 | #ifdef CONFIG_TMPFS_XATTR |