Commit 647ebfd1 authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] FAT: simple error handling cleanup

From: René Scharfe <l.s.r@web.de>

the following patch converts the error handling paths in VFAT fs to use
goto, making it more consistent with other filesystem code. Shrinks the
resulting binary by 144 bytes in my build.
parent f82f633c
...@@ -866,24 +866,22 @@ int vfat_create(struct inode *dir,struct dentry* dentry,int mode, ...@@ -866,24 +866,22 @@ int vfat_create(struct inode *dir,struct dentry* dentry,int mode,
lock_kernel(); lock_kernel();
res = vfat_add_entry(dir, &dentry->d_name, 0, &sinfo, &bh, &de); res = vfat_add_entry(dir, &dentry->d_name, 0, &sinfo, &bh, &de);
if (res < 0) { if (res < 0)
unlock_kernel(); goto out;
return res;
}
inode = fat_build_inode(sb, de, sinfo.i_pos, &res); inode = fat_build_inode(sb, de, sinfo.i_pos, &res);
brelse(bh); brelse(bh);
if (!inode) { if (!inode)
unlock_kernel(); goto out;
return res; res = 0;
}
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
inode->i_version++; inode->i_version++;
dir->i_version++; dir->i_version++;
dentry->d_time = dentry->d_parent->d_inode->i_version; dentry->d_time = dentry->d_parent->d_inode->i_version;
d_instantiate(dentry,inode); d_instantiate(dentry,inode);
out:
unlock_kernel(); unlock_kernel();
return 0; return res;
} }
static void vfat_remove_entry(struct inode *dir,struct vfat_slot_info *sinfo, static void vfat_remove_entry(struct inode *dir,struct vfat_slot_info *sinfo,
...@@ -919,16 +917,13 @@ int vfat_rmdir(struct inode *dir,struct dentry* dentry) ...@@ -919,16 +917,13 @@ int vfat_rmdir(struct inode *dir,struct dentry* dentry)
lock_kernel(); lock_kernel();
res = fat_dir_empty(dentry->d_inode); res = fat_dir_empty(dentry->d_inode);
if (res) { if (res)
unlock_kernel(); goto out;
return res;
}
res = vfat_find(dir,&dentry->d_name,&sinfo, &bh, &de); res = vfat_find(dir,&dentry->d_name,&sinfo, &bh, &de);
if (res<0) { if (res < 0)
unlock_kernel(); goto out;
return res; res = 0;
}
dentry->d_inode->i_nlink = 0; dentry->d_inode->i_nlink = 0;
dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME; dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME;
fat_detach(dentry->d_inode); fat_detach(dentry->d_inode);
...@@ -936,8 +931,9 @@ int vfat_rmdir(struct inode *dir,struct dentry* dentry) ...@@ -936,8 +931,9 @@ int vfat_rmdir(struct inode *dir,struct dentry* dentry)
/* releases bh */ /* releases bh */
vfat_remove_entry(dir,&sinfo,bh,de); vfat_remove_entry(dir,&sinfo,bh,de);
dir->i_nlink--; dir->i_nlink--;
out:
unlock_kernel(); unlock_kernel();
return 0; return res;
} }
int vfat_unlink(struct inode *dir, struct dentry* dentry) int vfat_unlink(struct inode *dir, struct dentry* dentry)
...@@ -949,16 +945,15 @@ int vfat_unlink(struct inode *dir, struct dentry* dentry) ...@@ -949,16 +945,15 @@ int vfat_unlink(struct inode *dir, struct dentry* dentry)
lock_kernel(); lock_kernel();
res = vfat_find(dir,&dentry->d_name,&sinfo,&bh,&de); res = vfat_find(dir,&dentry->d_name,&sinfo,&bh,&de);
if (res < 0) { if (res < 0)
unlock_kernel(); goto out;
return res;
}
dentry->d_inode->i_nlink = 0; dentry->d_inode->i_nlink = 0;
dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME; dentry->d_inode->i_mtime = dentry->d_inode->i_atime = CURRENT_TIME;
fat_detach(dentry->d_inode); fat_detach(dentry->d_inode);
mark_inode_dirty(dentry->d_inode); mark_inode_dirty(dentry->d_inode);
/* releases bh */ /* releases bh */
vfat_remove_entry(dir,&sinfo,bh,de); vfat_remove_entry(dir,&sinfo,bh,de);
out:
unlock_kernel(); unlock_kernel();
return res; return res;
...@@ -976,13 +971,11 @@ int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode) ...@@ -976,13 +971,11 @@ int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode)
lock_kernel(); lock_kernel();
res = vfat_add_entry(dir, &dentry->d_name, 1, &sinfo, &bh, &de); res = vfat_add_entry(dir, &dentry->d_name, 1, &sinfo, &bh, &de);
if (res < 0) { if (res < 0)
unlock_kernel(); goto out;
return res;
}
inode = fat_build_inode(sb, de, sinfo.i_pos, &res); inode = fat_build_inode(sb, de, sinfo.i_pos, &res);
if (!inode) if (!inode)
goto out; goto out_brelse;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
inode->i_version++; inode->i_version++;
...@@ -994,8 +987,9 @@ int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode) ...@@ -994,8 +987,9 @@ int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode)
goto mkdir_failed; goto mkdir_failed;
dentry->d_time = dentry->d_parent->d_inode->i_version; dentry->d_time = dentry->d_parent->d_inode->i_version;
d_instantiate(dentry,inode); d_instantiate(dentry,inode);
out: out_brelse:
brelse(bh); brelse(bh);
out:
unlock_kernel(); unlock_kernel();
return res; return res;
...@@ -1008,8 +1002,7 @@ int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode) ...@@ -1008,8 +1002,7 @@ int vfat_mkdir(struct inode *dir,struct dentry* dentry,int mode)
vfat_remove_entry(dir,&sinfo,bh,de); vfat_remove_entry(dir,&sinfo,bh,de);
iput(inode); iput(inode);
dir->i_nlink--; dir->i_nlink--;
unlock_kernel(); goto out;
return res;
} }
int vfat_rename(struct inode *old_dir,struct dentry *old_dentry, int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
......
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