lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251208062100.3268777-24-chenxiaosong.chenxiaosong@linux.dev>
Date: Mon,  8 Dec 2025 14:20:53 +0800
From: chenxiaosong.chenxiaosong@...ux.dev
To: sfrench@...ba.org,
	smfrench@...il.com,
	linkinjeon@...nel.org,
	linkinjeon@...ba.org
Cc: linux-cifs@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	liuzhengyuan@...inos.cn,
	huhai@...inos.cn,
	liuyun01@...inos.cn,
	ChenXiaoSong <chenxiaosong@...inos.cn>
Subject: [PATCH 23/30] smb/client: use bsearch() to find target in mapping_table_ERRDOS array

From: ChenXiaoSong <chenxiaosong@...inos.cn>

The array currently has 39 elements. When searching for the last element,
the original loop-based search method requires 39 comparisons, while
binary search algorithm requires only 5 comparisons.

Signed-off-by: ChenXiaoSong <chenxiaosong@...inos.cn>
---
 fs/smb/client/netmisc.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 594a7fae0060..d7d1b9b4abcd 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -813,6 +813,8 @@ DEFINE_CMP_FUNC(smb_to_posix_error, smb_err);
 DEFINE_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatus_to_dos_num);
 /* search_in_nt_errs */
 DEFINE_SEARCH_FUNC(nt_err_code_struct, nt_errcode, nt_errs, nt_err_num);
+/* search_in_mapping_table_ERRDOS */
+DEFINE_SEARCH_FUNC(smb_to_posix_error, smb_err, mapping_table_ERRDOS, errdos_num);
 
 /*****************************************************************************
  Print an error message from the status code
@@ -861,6 +863,7 @@ map_smb_to_linux_error(char *buf, bool logErr)
 	int rc = -EIO;	/* if transport error smb error may not be set */
 	__u8 smberrclass;
 	__u16 smberrcode;
+	struct smb_to_posix_error *err_map;
 
 	/* BB if NT Status codes - map NT BB */
 
@@ -887,19 +890,9 @@ map_smb_to_linux_error(char *buf, bool logErr)
 	/* DOS class smb error codes - map DOS */
 	if (smberrclass == ERRDOS) {
 		/* 1 byte field no need to byte reverse */
-		for (i = 0;
-		     i <
-		     sizeof(mapping_table_ERRDOS) /
-		     sizeof(struct smb_to_posix_error); i++) {
-			if (mapping_table_ERRDOS[i].smb_err == 0)
-				break;
-			else if (mapping_table_ERRDOS[i].smb_err ==
-								smberrcode) {
-				rc = mapping_table_ERRDOS[i].posix_code;
-				break;
-			}
-			/* else try next error mapping one to see if match */
-		}
+		err_map = search_in_mapping_table_ERRDOS(smberrcode);
+		if (err_map)
+			rc = err_map->posix_code;
 	} else if (smberrclass == ERRSRV) {
 		/* server class of error codes */
 		for (i = 0;
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ