Skip to content

Commit cd69f8f

Browse files
Thadeu Lima de Souza Cascardotytso
authored andcommitted
ext4: ext4_search_dir should return a proper error
ext4_search_dir currently returns -1 in case of a failure, while it returns 0 when the name is not found. In such failure cases, it should return an error code instead. This becomes even more important when ext4_find_inline_entry returns an error code as well in the next commit. -EFSCORRUPTED seems appropriate as such error code as these failures would be caused by unexpected record lengths and is in line with other instances of ext4_check_dir_entry failures. In the case of ext4_dx_find_entry, the current use of ERR_BAD_DX_DIR was left as is to reduce the risk of regressions. Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com> Link: https://patch.msgid.link/20240821152324.3621860-2-cascardo@igalia.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 7d2b488 commit cd69f8f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

fs/ext4/namei.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ static bool ext4_match(struct inode *parent,
14821482
}
14831483

14841484
/*
1485-
* Returns 0 if not found, -1 on failure, and 1 on success
1485+
* Returns 0 if not found, -EFSCORRUPTED on failure, and 1 on success
14861486
*/
14871487
int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
14881488
struct inode *dir, struct ext4_filename *fname,
@@ -1503,15 +1503,15 @@ int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
15031503
* a full check */
15041504
if (ext4_check_dir_entry(dir, NULL, de, bh, search_buf,
15051505
buf_size, offset))
1506-
return -1;
1506+
return -EFSCORRUPTED;
15071507
*res_dir = de;
15081508
return 1;
15091509
}
15101510
/* prevent looping on a bad block */
15111511
de_len = ext4_rec_len_from_disk(de->rec_len,
15121512
dir->i_sb->s_blocksize);
15131513
if (de_len <= 0)
1514-
return -1;
1514+
return -EFSCORRUPTED;
15151515
offset += de_len;
15161516
de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
15171517
}
@@ -1663,8 +1663,10 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
16631663
goto cleanup_and_exit;
16641664
} else {
16651665
brelse(bh);
1666-
if (i < 0)
1666+
if (i < 0) {
1667+
ret = ERR_PTR(i);
16671668
goto cleanup_and_exit;
1669+
}
16681670
}
16691671
next:
16701672
if (++block >= nblocks)
@@ -1758,7 +1760,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
17581760
if (retval == 1)
17591761
goto success;
17601762
brelse(bh);
1761-
if (retval == -1) {
1763+
if (retval < 0) {
17621764
bh = ERR_PTR(ERR_BAD_DX_DIR);
17631765
goto errout;
17641766
}

0 commit comments

Comments
 (0)