fs: yaffs2: Add null pointer check before dereferencing inode

In yaffs_rename(), d_entry->d_inode can be NULL if the
target directory doesn't exist or if there is any race
condition such as target directory being deleted while
renaming another directory to target directory name.
Avoid dereferencing d_inode in such cases.

CRs-Fixed: 360748
Change-Id: If95b4992f1056fea78f2e1bd54253cd5c8aac93d
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
This commit is contained in:
Sujit Reddy Thumma 2012-06-29 13:50:22 +05:30 committed by Stephen Boyd
parent 61e6f4af43
commit 4da81b3375
1 changed files with 10 additions and 2 deletions

View File

@ -497,8 +497,16 @@ static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (ret_val == YAFFS_OK) {
if (target) {
drop_nlink(new_dentry->d_inode);
mark_inode_dirty(new_dentry->d_inode);
/*
* We have identified target to be a
* valid directory earlier. If it is
* not the case throw a warning.
*/
WARN_ON(!new_dentry->d_inode);
if (new_dentry->d_inode) {
drop_nlink(new_dentry->d_inode);
mark_inode_dirty(new_dentry->d_inode);
}
}
update_dir_time(old_dir);