Skip to content

Commit

Permalink
exfat: add missing brelse() calls on error paths
Browse files Browse the repository at this point in the history
If the second exfat_get_dentry() call fails then we need to release
"old_bh" before returning.  There is a similar bug in exfat_move_file().

Fixes: 5f2aa07 ("exfat: add inode operations")
Reported-by: Markus Elfring <Markus.Elfring@web.de>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
  • Loading branch information
Dan Carpenter authored and Namjae Jeon committed Jun 29, 2020
1 parent 4ba6ccd commit e8dd3cd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions fs/exfat/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,10 +1077,14 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,

epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh,
&sector_old);
if (!epold)
return -EIO;
epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh,
&sector_new);
if (!epold || !epnew)
if (!epnew) {
brelse(old_bh);
return -EIO;
}

memcpy(epnew, epold, DENTRY_SIZE);
exfat_update_bh(sb, new_bh, sync);
Expand Down Expand Up @@ -1161,10 +1165,14 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,

epmov = exfat_get_dentry(sb, p_olddir, oldentry + 1, &mov_bh,
&sector_mov);
if (!epmov)
return -EIO;
epnew = exfat_get_dentry(sb, p_newdir, newentry + 1, &new_bh,
&sector_new);
if (!epmov || !epnew)
if (!epnew) {
brelse(mov_bh);
return -EIO;
}

memcpy(epnew, epmov, DENTRY_SIZE);
exfat_update_bh(sb, new_bh, IS_DIRSYNC(inode));
Expand Down

0 comments on commit e8dd3cd

Please sign in to comment.