Skip to content

Commit 772d592

Browse files
haryvensmfrench
authored andcommitted
smb/client: refactor ntstatus_to_dos() to return mapping entry
Refactor ntstatus_to_dos() to return a pointer to the mapping entry instead of using output parameters. This allows callers to access all fields of the entry directly. In map_smb_to_linux_error(), integrate the printing logic directly to avoid redundant lookups previously performed by cifs_print_status(), which is now removed. Signed-off-by: Huiwen He <hehuiwen@kylinos.cn> Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent c825f6b commit 772d592

1 file changed

Lines changed: 19 additions & 32 deletions

File tree

fs/smb/client/smb1maperror.c

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -116,41 +116,19 @@ static const struct ntstatus_to_dos_err ntstatus_to_dos_map[] = {
116116
{0, 0, 0, NULL}
117117
};
118118

119-
/*****************************************************************************
120-
Print an error message from the status code
121-
*****************************************************************************/
122-
static void
123-
cifs_print_status(__u32 status_code)
124-
{
125-
int idx = 0;
126-
127-
while (ntstatus_to_dos_map[idx].nt_errstr) {
128-
if (ntstatus_to_dos_map[idx].ntstatus == status_code) {
129-
pr_notice("Status code returned 0x%08x %s\n",
130-
status_code, ntstatus_to_dos_map[idx].nt_errstr);
131-
return;
132-
}
133-
idx++;
134-
}
135-
return;
136-
}
137-
138-
139-
static void
140-
ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode)
119+
static const struct ntstatus_to_dos_err *
120+
ntstatus_to_dos(__u32 ntstatus)
141121
{
142122
int i;
143123

144124
/* Check nt_errstr to allow mapping of NT_STATUS_OK (0) */
145125
for (i = 0; ntstatus_to_dos_map[i].nt_errstr; i++) {
146126
if (ntstatus == ntstatus_to_dos_map[i].ntstatus) {
147-
*eclass = ntstatus_to_dos_map[i].dos_class;
148-
*ecode = ntstatus_to_dos_map[i].dos_code;
149-
return;
127+
return &ntstatus_to_dos_map[i];
150128
}
151129
}
152-
*eclass = ERRHRD;
153-
*ecode = ERRgeneral;
130+
131+
return NULL;
154132
}
155133

156134
int
@@ -172,11 +150,20 @@ map_smb_to_linux_error(char *buf, bool logErr)
172150
/* translate the newer STATUS codes to old style SMB errors
173151
* and then to POSIX errors */
174152
__u32 err = le32_to_cpu(smb->Status.CifsError);
175-
if (logErr && (err != (NT_STATUS_MORE_PROCESSING_REQUIRED)))
176-
cifs_print_status(err);
177-
else if (cifsFYI & CIFS_RC)
178-
cifs_print_status(err);
179-
ntstatus_to_dos(err, &smberrclass, &smberrcode);
153+
const struct ntstatus_to_dos_err *map = ntstatus_to_dos(err);
154+
155+
if (map) {
156+
if ((logErr && err != NT_STATUS_MORE_PROCESSING_REQUIRED) ||
157+
(cifsFYI & CIFS_RC))
158+
pr_notice("Status code returned 0x%08x %s\n",
159+
map->ntstatus, map->nt_errstr);
160+
161+
smberrclass = map->dos_class;
162+
smberrcode = map->dos_code;
163+
} else {
164+
smberrclass = ERRHRD;
165+
smberrcode = ERRgeneral;
166+
}
180167
} else {
181168
smberrclass = smb->Status.DosError.ErrorClass;
182169
smberrcode = le16_to_cpu(smb->Status.DosError.Error);

0 commit comments

Comments
 (0)