Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	Al Viro <viro@zeniv.linux.org.uk>,
	Bharath SM <bharathsm@microsoft.com>,
	Paul Aurich <paul@darkrain42.org>,
	Paulo Alcantara <pc@manguebit.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Steve French <sfrench@samba.org>, Tom Talpey <tom@talpey.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] smb: client: Use more common code in open_cached_dir()
Date: Tue, 7 Oct 2025 15:50:33 +0200	[thread overview]
Message-ID: <bdb24f04-98a5-43ce-bef2-dcda4edd8618@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 7 Oct 2025 15:34:56 +0200

Use two additional labels so that another bit of common code can be better
reused at the end of this function implementation.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/smb/client/cached_dir.c | 42 ++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index b36f9f9340f0..d3ab0467b0d9 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -184,9 +184,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	spin_lock(&cfids->cfid_list_lock);
 	cfid = find_or_create_cached_dir(cfids, path, lookup_only, tcon->max_cached_dirs);
 	if (cfid == NULL) {
-		spin_unlock(&cfids->cfid_list_lock);
-		kfree(utf16_path);
-		return -ENOENT;
+		rc = -ENOENT;
+		goto free_unlock_list;
 	}
 	/*
 	 * Return cached fid if it is valid (has a lease and has a time).
@@ -195,10 +194,9 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	 */
 	if (is_valid_cached_dir(cfid)) {
 		cfid->last_access_time = jiffies;
-		spin_unlock(&cfids->cfid_list_lock);
 		*ret_cfid = cfid;
-		kfree(utf16_path);
-		return 0;
+		rc = 0;
+		goto free_unlock_list;
 	}
 	spin_unlock(&cfids->cfid_list_lock);
 
@@ -331,30 +329,25 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 
 
 	if (o_rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) {
-		spin_unlock(&cfids->cfid_list_lock);
 		rc = -EINVAL;
-		goto oshr_free;
+		goto unlock_list;
 	}
 
 	rc = smb2_parse_contexts(server, rsp_iov,
 				 &oparms.fid->epoch,
 				 oparms.fid->lease_key,
 				 &oplock, NULL, NULL);
-	if (rc) {
-		spin_unlock(&cfids->cfid_list_lock);
-		goto oshr_free;
-	}
+	if (rc)
+		goto unlock_list;
 
 	rc = -EINVAL;
-	if (!(oplock & SMB2_LEASE_READ_CACHING_HE)) {
-		spin_unlock(&cfids->cfid_list_lock);
-		goto oshr_free;
-	}
+	if (!(oplock & SMB2_LEASE_READ_CACHING_HE))
+		goto unlock_list;
+
 	qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
-	if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info)) {
-		spin_unlock(&cfids->cfid_list_lock);
-		goto oshr_free;
-	}
+	if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))
+		goto unlock_list;
+
 	if (!smb2_validate_and_copy_iov(
 				le16_to_cpu(qi_rsp->OutputBufferOffset),
 				sizeof(struct smb2_file_all_info),
@@ -364,10 +357,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 
 	cfid->time = jiffies;
 	cfid->last_access_time = jiffies;
-	spin_unlock(&cfids->cfid_list_lock);
 	/* At this point the directory handle is fully cached */
 	rc = 0;
-
+unlock_list:
+	spin_unlock(&cfids->cfid_list_lock);
 oshr_free:
 	SMB2_open_free(&rqst[0]);
 	SMB2_query_info_free(&rqst[1]);
@@ -404,6 +397,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 		goto replay_again;
 
 	return rc;
+
+free_unlock_list:
+	spin_unlock(&cfids->cfid_list_lock);
+	kfree(utf16_path);
+	return rc;
 }
 
 int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
-- 
2.51.0


                 reply	other threads:[~2025-10-07 13:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bdb24f04-98a5-43ce-bef2-dcda4edd8618@web.de \
    --to=markus.elfring@web.de \
    --cc=bharathsm@microsoft.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@darkrain42.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).