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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251208062100.3268777-12-chenxiaosong.chenxiaosong@linux.dev>
Date: Mon,  8 Dec 2025 14:20:41 +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 11/30] smb/client: introduce DEFINE_SEARCH_FUNC()

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

We are going to define 4 search functions, introduce this macro to
reduce duplicate code.

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

diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 32197a3a4e81..8a84f826d486 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -38,6 +38,22 @@ static int cmp_ ## __struct_name(const void *_a, const void *_b)	\
 	return 0;							\
 }
 
+/* Define a function for searching the target error map. */
+#define DEFINE_SEARCH_FUNC(__struct_name, __field, __array, __num)	\
+static struct __struct_name *search_in_ ## __array(__le32 error)	\
+{									\
+	struct __struct_name *err_map, key;				\
+									\
+	key = (struct __struct_name) {					\
+		.__field = error,					\
+	};								\
+	err_map = bsearch(&key, __array, __num,				\
+			  sizeof(struct __struct_name),			\
+			  cmp_ ## __struct_name);			\
+									\
+	return err_map;							\
+}
+
 struct smb_to_posix_error {
 	__u16 smb_err;
 	int posix_code;
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ