[PATCH 26/30] smb/client: sort mapping_table_ERRSRV array

chenxiaosong.chenxiaosong@linux.dev posted 30 patches 1 week, 4 days ago
[PATCH 26/30] smb/client: sort mapping_table_ERRSRV array
Posted by chenxiaosong.chenxiaosong@linux.dev 1 week, 4 days ago
From: ChenXiaoSong <chenxiaosong@kylinos.cn>

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

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

diff --git a/fs/smb/client/netmisc.c b/fs/smb/client/netmisc.c
index 553d2a33b6de..4b5c049d69b9 100644
--- a/fs/smb/client/netmisc.c
+++ b/fs/smb/client/netmisc.c
@@ -103,7 +103,7 @@ static struct smb_to_posix_error mapping_table_ERRDOS[] = {
 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[] = {
+static struct smb_to_posix_error mapping_table_ERRSRV[] = {
 	{ERRerror, -EIO},
 	{ERRbadpw, -EACCES},  /* was EPERM */
 	{ERRbadtype, -EREMOTE},
@@ -148,6 +148,9 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
 	{0, 0}
 };
 
+static unsigned int errsrv_num = sizeof(mapping_table_ERRSRV) /
+				 sizeof(struct smb_to_posix_error);
+
 /*
  * Convert a string containing text IPv4 or IPv6 address to binary form.
  *
@@ -1077,6 +1080,8 @@ void smb_init_maperror(void)
 	     cmp_nt_err_code_struct, NULL);
 	sort(mapping_table_ERRDOS, errdos_num,
 	     sizeof(struct smb_to_posix_error), cmp_smb_to_posix_error, NULL);
+	sort(mapping_table_ERRSRV, errsrv_num,
+	     sizeof(struct smb_to_posix_error), cmp_smb_to_posix_error, NULL);
 }
 
 #if IS_ENABLED(CONFIG_SMB_KUNIT_TESTS)
-- 
2.43.0