Skip to content

Commit 6c1eb31

Browse files
ChenXiaoSongsmfrench
authored andcommitted
smb/client: reduce loop count in map_smb2_to_linux_error() by half
The smb2_error_map_table array currently has 1743 elements. When searching for the last element and calling smb2_print_status(), 3486 comparisons are needed. The loop in smb2_print_status() is unnecessary, smb2_print_status() can be removed, and only iterate over the array once, printing the message when the target status code is found. Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 7ad7859 commit 6c1eb31

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

fs/smb/client/smb2maperror.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,24 +2418,6 @@ static const struct status_to_posix_error smb2_error_map_table[] = {
24182418
{0, 0, NULL}
24192419
};
24202420

2421-
/*****************************************************************************
2422-
Print an error message from the status code
2423-
*****************************************************************************/
2424-
static void
2425-
smb2_print_status(__le32 status)
2426-
{
2427-
int idx = 0;
2428-
2429-
while (smb2_error_map_table[idx].status_string != NULL) {
2430-
if ((smb2_error_map_table[idx].smb2_status) == status) {
2431-
pr_notice("Status code returned 0x%08x %s\n", status,
2432-
smb2_error_map_table[idx].status_string);
2433-
}
2434-
idx++;
2435-
}
2436-
return;
2437-
}
2438-
24392421
int
24402422
map_smb2_to_linux_error(char *buf, bool log_err)
24412423
{
@@ -2452,16 +2434,16 @@ map_smb2_to_linux_error(char *buf, bool log_err)
24522434
return 0;
24532435
}
24542436

2455-
/* mask facility */
2456-
if (log_err && (smb2err != STATUS_MORE_PROCESSING_REQUIRED) &&
2457-
(smb2err != STATUS_END_OF_FILE))
2458-
smb2_print_status(smb2err);
2459-
else if (cifsFYI & CIFS_RC)
2460-
smb2_print_status(smb2err);
2437+
log_err = (log_err && (smb2err != STATUS_MORE_PROCESSING_REQUIRED) &&
2438+
(smb2err != STATUS_END_OF_FILE)) ||
2439+
(cifsFYI & CIFS_RC);
24612440

24622441
for (i = 0; i < sizeof(smb2_error_map_table) /
24632442
sizeof(struct status_to_posix_error); i++) {
24642443
if (smb2_error_map_table[i].smb2_status == smb2err) {
2444+
if (log_err)
2445+
pr_notice("Status code returned 0x%08x %s\n", smb2err,
2446+
smb2_error_map_table[i].status_string);
24652447
rc = smb2_error_map_table[i].posix_error;
24662448
break;
24672449
}

0 commit comments

Comments
 (0)