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-22-chenxiaosong.chenxiaosong@linux.dev>
Date: Mon,  8 Dec 2025 14:20:51 +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 21/30] smb/client: sort mapping_table_ERRDOS array

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

Sort the array in ascending order, and then we can use binary search
algorithm to quickly find the target DOS class smb error code.

The array is sorted only once when cifs.ko is loaded.

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

diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 239e5287d4d6..594a7fae0060 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -59,7 +59,7 @@ struct smb_to_posix_error {
 	int posix_code;
 };
 
-static const struct smb_to_posix_error mapping_table_ERRDOS[] = {
+static struct smb_to_posix_error mapping_table_ERRDOS[] = {
 	{ERRbadfunc, -EINVAL},
 	{ERRbadfile, -ENOENT},
 	{ERRbadpath, -ENOTDIR},
@@ -101,6 +101,9 @@ static const struct smb_to_posix_error mapping_table_ERRDOS[] = {
 	{0, 0}
 };
 
+static unsigned int errdos_num = sizeof(mapping_table_ERRDOS) /
+				 sizeof(struct smb_to_posix_error);
+
 static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
 	{ERRerror, -EIO},
 	{ERRbadpw, -EACCES},  /* was EPERM */
@@ -803,6 +806,8 @@ static unsigned int ntstatus_to_dos_num = sizeof(ntstatus_to_dos_map) /
 DEFINE_CMP_FUNC(ntstatus_to_dos, ntstatus);
 /* cmp_nt_err_code_struct */
 DEFINE_CMP_FUNC(nt_err_code_struct, nt_errcode);
+/* cmp_smb_to_posix_error */
+DEFINE_CMP_FUNC(smb_to_posix_error, smb_err);
 
 /* search_in_ntstatus_to_dos_map */
 DEFINE_SEARCH_FUNC(ntstatus_to_dos, ntstatus, ntstatus_to_dos_map, ntstatus_to_dos_num);
@@ -1078,6 +1083,8 @@ void smb_init_maperror(void)
 	     sizeof(struct ntstatus_to_dos), cmp_ntstatus_to_dos, NULL);
 	sort(nt_errs, nt_err_num, sizeof(struct nt_err_code_struct),
 	     cmp_nt_err_code_struct, NULL);
+	sort(mapping_table_ERRDOS, errdos_num,
+	     sizeof(struct smb_to_posix_error), cmp_smb_to_posix_error, NULL);
 }
 
 #if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ