Skip to content

Commit

Permalink
ext4: fix coverity warning on error path of filename setup
Browse files Browse the repository at this point in the history
Fix the following coverity warning reported by Dan Carpenter:

fs/ext4/namei.c:1311 ext4_fname_setup_ci_filename()
	  warn: 'cf_name->len' unsigned <= 0

Fixes: 3ae7256 ("ext4: optimize case-insensitive lookups")
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
  • Loading branch information
Gabriel Krisman Bertazi authored and Theodore Ts'o committed Jul 2, 2019
1 parent 78e9605 commit 96fcaf8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,8 @@ int ext4_ci_compare(const struct inode *parent, const struct qstr *name,
void ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
struct fscrypt_str *cf_name)
{
int len;

if (!IS_CASEFOLDED(dir)) {
cf_name->name = NULL;
return;
Expand All @@ -1319,13 +1321,16 @@ void ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
if (!cf_name->name)
return;

cf_name->len = utf8_casefold(EXT4_SB(dir->i_sb)->s_encoding,
iname, cf_name->name,
EXT4_NAME_LEN);
if (cf_name->len <= 0) {
len = utf8_casefold(EXT4_SB(dir->i_sb)->s_encoding,
iname, cf_name->name,
EXT4_NAME_LEN);
if (len <= 0) {
kfree(cf_name->name);
cf_name->name = NULL;
return;
}
cf_name->len = (unsigned) len;

}
#endif

Expand Down

0 comments on commit 96fcaf8

Please sign in to comment.