From: ChenXiaoSong <chenxiaosong@kylinos.cn>
We are going to define 4 search functions, introduce this macro to
reduce duplicate code.
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.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