There's no need to get ->srv_lock or ->ses_lock in smb2_get_mid_entry() as
all that happens of relevance (to the lock) inside the locked sections is
the reading of one status value in each.
Replace the locking with READ_ONCE() and use a switch instead of a chain of
if-statements.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Steve French <sfrench@samba.org>
cc: Paulo Alcantara <pc@manguebit.org>
cc: Shyam Prasad N <sprasad@microsoft.com>
cc: Tom Talpey <tom@talpey.com>
cc: linux-cifs@vger.kernel.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
---
fs/smb/client/smb2transport.c | 46 +++++++++++++++--------------------
1 file changed, 19 insertions(+), 27 deletions(-)
diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c
index 7c60584a8544..7194082bb5ac 100644
--- a/fs/smb/client/smb2transport.c
+++ b/fs/smb/client/smb2transport.c
@@ -769,43 +769,35 @@ static int
smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
struct smb_message *smb)
{
- spin_lock(&server->srv_lock);
- if (server->tcpStatus == CifsExiting) {
- spin_unlock(&server->srv_lock);
+ switch (READ_ONCE(server->tcpStatus)) {
+ case CifsExiting:
return -ENOENT;
- }
-
- if (server->tcpStatus == CifsNeedReconnect) {
- spin_unlock(&server->srv_lock);
+ case CifsNeedReconnect:
cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
return -EAGAIN;
+ case CifsNeedNegotiate:
+ if (smb->command_id != SMB2_NEGOTIATE)
+ return -EAGAIN;
+ break;
+ default:
+ break;
}
- if (server->tcpStatus == CifsNeedNegotiate &&
- smb->command_id != SMB2_NEGOTIATE) {
- spin_unlock(&server->srv_lock);
- return -EAGAIN;
- }
- spin_unlock(&server->srv_lock);
-
- spin_lock(&ses->ses_lock);
- if (ses->ses_status == SES_NEW) {
+ switch (READ_ONCE(ses->ses_status)) {
+ case SES_NEW:
if (smb->command_id != SMB2_SESSION_SETUP &&
- smb->command_id != SMB2_NEGOTIATE) {
- spin_unlock(&ses->ses_lock);
+ smb->command_id != SMB2_NEGOTIATE)
return -EAGAIN;
- }
- /* else ok - we are setting up session */
- }
-
- if (ses->ses_status == SES_EXITING) {
- if (smb->command_id != SMB2_LOGOFF) {
- spin_unlock(&ses->ses_lock);
+ /* else ok - we are setting up session */
+ break;
+ case SES_EXITING:
+ if (smb->command_id != SMB2_LOGOFF)
return -EAGAIN;
- }
/* else ok - we are shutting down the session */
+ break;
+ default:
+ break;
}
- spin_unlock(&ses->ses_lock);
smb2_init_mid(smb, server);