Commit a87a717b authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] FAT: fat_build_inode() cleanup

Just use ERR_PTR() instead of getting the error code by additional
argument.
Signed-off-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8b59d996
......@@ -304,23 +304,25 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
}
struct inode *fat_build_inode(struct super_block *sb,
struct msdos_dir_entry *de, loff_t i_pos, int *res)
struct msdos_dir_entry *de, loff_t i_pos)
{
struct inode *inode;
*res = 0;
int err;
inode = fat_iget(sb, i_pos);
if (inode)
goto out;
inode = new_inode(sb);
*res = -ENOMEM;
if (!inode)
if (!inode) {
inode = ERR_PTR(-ENOMEM);
goto out;
}
inode->i_ino = iunique(sb, MSDOS_ROOT_INO);
inode->i_version = 1;
*res = fat_fill_inode(inode, de);
if (*res < 0) {
err = fat_fill_inode(inode, de);
if (err) {
iput(inode);
inode = NULL;
inode = ERR_PTR(err);
goto out;
}
fat_attach(inode, i_pos);
......@@ -643,39 +645,35 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
static struct dentry *fat_get_parent(struct dentry *child)
{
struct buffer_head *bh=NULL;
struct msdos_dir_entry *de = NULL;
struct dentry *parent = NULL;
int res;
loff_t i_pos = 0;
struct buffer_head *bh;
struct msdos_dir_entry *de;
loff_t i_pos;
struct dentry *parent;
struct inode *inode;
int err;
lock_kernel();
res = fat_scan(child->d_inode, MSDOS_DOTDOT, &bh, &de, &i_pos);
if (res < 0)
err = fat_scan(child->d_inode, MSDOS_DOTDOT, &bh, &de, &i_pos);
if (err) {
parent = ERR_PTR(err);
goto out;
inode = fat_build_inode(child->d_sb, de, i_pos, &res);
if (res)
}
inode = fat_build_inode(child->d_sb, de, i_pos);
brelse(bh);
if (IS_ERR(inode)) {
parent = ERR_PTR(PTR_ERR(inode));
goto out;
if (!inode)
res = -EACCES;
else {
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
res = -ENOMEM;
}
}
out:
if(bh)
brelse(bh);
parent = d_alloc_anon(inode);
if (!parent) {
iput(inode);
parent = ERR_PTR(-ENOMEM);
}
out:
unlock_kernel();
if (res)
return ERR_PTR(res);
else
return parent;
return parent;
}
static struct export_operations fat_export_ops = {
......
......@@ -236,9 +236,11 @@ static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
goto add;
if (res < 0)
goto out;
inode = fat_build_inode(sb, de, i_pos, &res);
if (res)
inode = fat_build_inode(sb, de, i_pos);
if (IS_ERR(inode)) {
res = PTR_ERR(inode);
goto out;
}
add:
res = 0;
dentry = d_splice_alias(inode, dentry);
......@@ -314,11 +316,11 @@ static int msdos_create(struct inode *dir, struct dentry *dentry, int mode,
unlock_kernel();
return res;
}
inode = fat_build_inode(dir->i_sb, de, i_pos, &res);
inode = fat_build_inode(dir->i_sb, de, i_pos);
brelse(bh);
if (!inode) {
if (IS_ERR(inode)) {
unlock_kernel();
return res;
return PTR_ERR(inode);
}
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
......@@ -392,9 +394,10 @@ static int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode)
res = msdos_add_entry(dir, msdos_name, &bh, &de, &i_pos, 1, is_hid);
if (res)
goto out_unlock;
inode = fat_build_inode(dir->i_sb, de, i_pos, &res);
if (!inode) {
inode = fat_build_inode(dir->i_sb, de, i_pos);
if (IS_ERR(inode)) {
brelse(bh);
res = PTR_ERR(inode);
goto out_unlock;
}
res = 0;
......
......@@ -757,11 +757,11 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
table++;
goto error;
}
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos, &err);
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
brelse(sinfo.bh);
if (err) {
if (IS_ERR(inode)) {
unlock_kernel();
return ERR_PTR(err);
return ERR_PTR(PTR_ERR(inode));
}
alias = d_find_alias(inode);
if (alias) {
......@@ -798,10 +798,12 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, int mode,
res = vfat_add_entry(dir, &dentry->d_name, 0, &sinfo);
if (res < 0)
goto out;
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos, &res);
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
brelse(sinfo.bh);
if (!inode)
if (IS_ERR(inode)) {
res = PTR_ERR(inode);
goto out;
}
res = 0;
inode->i_version++;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
......@@ -883,9 +885,11 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
res = vfat_add_entry(dir, &dentry->d_name, 1, &sinfo);
if (res < 0)
goto out;
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos, &res);
if (!inode)
inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
if (IS_ERR(inode)) {
res = PTR_ERR(inode);
goto out_brelse;
}
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
inode->i_version++;
......@@ -967,7 +971,6 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
}
new_dir->i_version++;
/* releases old_bh */
err = fat_remove_entries(old_dir, &old_sinfo); /* and releases bh */
old_sinfo.bh = NULL;
if (err)
......
......@@ -394,7 +394,7 @@ extern void fat_attach(struct inode *inode, loff_t i_pos);
extern void fat_detach(struct inode *inode);
extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos);
extern struct inode *fat_build_inode(struct super_block *sb,
struct msdos_dir_entry *de, loff_t i_pos, int *res);
struct msdos_dir_entry *de, loff_t i_pos);
extern int fat_sync_inode(struct inode *inode);
extern int fat_fill_super(struct super_block *sb, void *data, int silent,
struct inode_operations *fs_dir_inode_ops, int isvfat);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment