infra: fix readlink

This commit is contained in:
Thomas Schoebel-Theuer 2012-12-17 18:10:22 +01:00 committed by Thomas Schoebel-Theuer
parent e108777ff8
commit f7331fccf3
1 changed files with 12 additions and 11 deletions

View File

@ -173,7 +173,7 @@ char *mars_readlink(const char *newpath)
struct path path = {}; struct path path = {};
mm_segment_t oldfs; mm_segment_t oldfs;
struct inode *inode; struct inode *inode;
int status; int status = -ENOMEM;
if (unlikely(!res)) if (unlikely(!res))
goto done; goto done;
@ -184,31 +184,32 @@ char *mars_readlink(const char *newpath)
status = user_path_at(AT_FDCWD, newpath, 0, &path); status = user_path_at(AT_FDCWD, newpath, 0, &path);
if (unlikely(status < 0)) { if (unlikely(status < 0)) {
MARS_DBG("link '%s' does not exist, status = %d\n", newpath, status); MARS_DBG("link '%s' does not exist, status = %d\n", newpath, status);
goto err; goto done_fs;
} }
inode = path.dentry->d_inode; inode = path.dentry->d_inode;
if (unlikely(!inode)) { if (unlikely(!inode)) {
MARS_ERR("link '%s' has invalid inode\n", newpath); MARS_ERR("link '%s' has invalid inode\n", newpath);
goto err; status = -EINVAL;
goto done_put;
} }
status = inode->i_op->readlink(path.dentry, res, 1024); status = inode->i_op->readlink(path.dentry, res, 1024);
if (unlikely(status < 0)) { if (unlikely(status < 0)) {
MARS_ERR("cannot read link '%s', status = %d\n", newpath, status); MARS_ERR("cannot read link '%s', status = %d\n", newpath, status);
goto err;
} }
set_fs(oldfs); done_put:
path_put(&path);
done_fs:
set_fs(oldfs);
done: done:
return res; if (unlikely(status < 0)) {
err:
set_fs(oldfs);
brick_string_free(res); brick_string_free(res);
res = NULL; res = NULL;
goto done; }
return res;
} }
EXPORT_SYMBOL_GPL(mars_readlink); EXPORT_SYMBOL_GPL(mars_readlink);