Commit 3a7b6d0a authored by David Howells's avatar David Howells Committed by Steve French
Browse files

cifs: Don't need state locking in smb2_get_mid_entry()



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: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarPaulo Alcantara (Red Hat) <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
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 87fba18a
Loading
Loading
Loading
Loading
+20 −28
Original line number Diff line number Diff line
@@ -684,43 +684,35 @@ static int
smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
		   struct smb2_hdr *shdr, struct mid_q_entry **mid)
{
	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;
	}

	if (server->tcpStatus == CifsNeedNegotiate &&
	   shdr->Command != SMB2_NEGOTIATE) {
		spin_unlock(&server->srv_lock);
	case CifsNeedNegotiate:
		if (shdr->Command != SMB2_NEGOTIATE)
			return -EAGAIN;
		break;
	default:
		break;
	}
	spin_unlock(&server->srv_lock);

	spin_lock(&ses->ses_lock);
	if (ses->ses_status == SES_NEW) {
		if ((shdr->Command != SMB2_SESSION_SETUP) &&
		    (shdr->Command != SMB2_NEGOTIATE)) {
			spin_unlock(&ses->ses_lock);
	switch (READ_ONCE(ses->ses_status)) {
	case SES_NEW:
		if (shdr->Command != SMB2_SESSION_SETUP &&
		    shdr->Command != SMB2_NEGOTIATE)
			return -EAGAIN;
		}
			/* else ok - we are setting up session */
	}

	if (ses->ses_status == SES_EXITING) {
		if (shdr->Command != SMB2_LOGOFF) {
			spin_unlock(&ses->ses_lock);
		break;
	case SES_EXITING:
		if (shdr->Command != SMB2_LOGOFF)
			return -EAGAIN;
		}
		/* else ok - we are shutting down the session */
		break;
	default:
		break;
	}
	spin_unlock(&ses->ses_lock);

	*mid = smb2_mid_entry_alloc(shdr, server);
	if (*mid == NULL)