diff options
Diffstat (limited to 'fs/minix/namei.c')
-rw-r--r-- | fs/minix/namei.c | 100 |
1 files changed, 48 insertions, 52 deletions
diff --git a/fs/minix/namei.c b/fs/minix/namei.c index 39ebe10d6a8b..956d5183828d 100644 --- a/fs/minix/namei.c +++ b/fs/minix/namei.c @@ -36,33 +36,31 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, un static int minix_mknod(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev) { - int error; struct inode *inode; if (!old_valid_dev(rdev)) return -EINVAL; - inode = minix_new_inode(dir, mode, &error); + inode = minix_new_inode(dir, mode); + if (IS_ERR(inode)) + return PTR_ERR(inode); - if (inode) { - minix_set_inode(inode, rdev); - mark_inode_dirty(inode); - error = add_nondir(dentry, inode); - } - return error; + minix_set_inode(inode, rdev); + mark_inode_dirty(inode); + return add_nondir(dentry, inode); } static int minix_tmpfile(struct mnt_idmap *idmap, struct inode *dir, struct file *file, umode_t mode) { - int error; - struct inode *inode = minix_new_inode(dir, mode, &error); - if (inode) { - minix_set_inode(inode, 0); - mark_inode_dirty(inode); - d_tmpfile(file, inode); - } - return finish_open_simple(file, error); + struct inode *inode = minix_new_inode(dir, mode); + + if (IS_ERR(inode)) + return finish_open_simple(file, PTR_ERR(inode)); + minix_set_inode(inode, 0); + mark_inode_dirty(inode); + d_tmpfile(file, inode); + return finish_open_simple(file, 0); } static int minix_create(struct mnt_idmap *idmap, struct inode *dir, @@ -74,30 +72,25 @@ static int minix_create(struct mnt_idmap *idmap, struct inode *dir, static int minix_symlink(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, const char *symname) { - int err = -ENAMETOOLONG; int i = strlen(symname)+1; struct inode * inode; + int err; if (i > dir->i_sb->s_blocksize) - goto out; + return -ENAMETOOLONG; - inode = minix_new_inode(dir, S_IFLNK | 0777, &err); - if (!inode) - goto out; + inode = minix_new_inode(dir, S_IFLNK | 0777); + if (IS_ERR(inode)) + return PTR_ERR(inode); minix_set_inode(inode, 0); err = page_symlink(inode, symname, i); - if (err) - goto out_fail; - - err = add_nondir(dentry, inode); -out: - return err; - -out_fail: - inode_dec_link_count(inode); - iput(inode); - goto out; + if (unlikely(err)) { + inode_dec_link_count(inode); + iput(inode); + return err; + } + return add_nondir(dentry, inode); } static int minix_link(struct dentry * old_dentry, struct inode * dir, @@ -117,14 +110,12 @@ static int minix_mkdir(struct mnt_idmap *idmap, struct inode *dir, struct inode * inode; int err; - inode_inc_link_count(dir); - - inode = minix_new_inode(dir, S_IFDIR | mode, &err); - if (!inode) - goto out_dir; + inode = minix_new_inode(dir, S_IFDIR | mode); + if (IS_ERR(inode)) + return PTR_ERR(inode); + inode_inc_link_count(dir); minix_set_inode(inode, 0); - inode_inc_link_count(inode); err = minix_make_empty(inode, dir); @@ -143,30 +134,29 @@ out_fail: inode_dec_link_count(inode); inode_dec_link_count(inode); iput(inode); -out_dir: inode_dec_link_count(dir); goto out; } static int minix_unlink(struct inode * dir, struct dentry *dentry) { - int err = -ENOENT; struct inode * inode = d_inode(dentry); struct page * page; struct minix_dir_entry * de; + int err; de = minix_find_entry(dentry, &page); if (!de) - goto end_unlink; - + return -ENOENT; err = minix_delete_entry(de, page); - if (err) - goto end_unlink; + kunmap(page); + put_page(page); + if (err) + return err; inode->i_ctime = dir->i_ctime; inode_dec_link_count(inode); -end_unlink: - return err; + return 0; } static int minix_rmdir(struct inode * dir, struct dentry *dentry) @@ -223,7 +213,11 @@ static int minix_rename(struct mnt_idmap *idmap, new_de = minix_find_entry(new_dentry, &new_page); if (!new_de) goto out_dir; - minix_set_link(new_de, new_page, old_inode); + err = minix_set_link(new_de, new_page, old_inode); + kunmap(new_page); + put_page(new_page); + if (err) + goto out_dir; new_inode->i_ctime = current_time(new_inode); if (dir_de) drop_nlink(new_inode); @@ -236,15 +230,17 @@ static int minix_rename(struct mnt_idmap *idmap, inode_inc_link_count(new_dir); } - minix_delete_entry(old_de, old_page); + err = minix_delete_entry(old_de, old_page); + if (err) + goto out_dir; + mark_inode_dirty(old_inode); if (dir_de) { - minix_set_link(dir_de, dir_page, new_dir); - inode_dec_link_count(old_dir); + err = minix_set_link(dir_de, dir_page, new_dir); + if (!err) + inode_dec_link_count(old_dir); } - return 0; - out_dir: if (dir_de) { kunmap(dir_page); |