lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <bdb24f04-98a5-43ce-bef2-dcda4edd8618@web.de>
Date: Tue, 7 Oct 2025 15:50:33 +0200
From: Markus Elfring <Markus.Elfring@....de>
To: linux-cifs@...r.kernel.org, samba-technical@...ts.samba.org,
 Al Viro <viro@...iv.linux.org.uk>, Bharath SM <bharathsm@...rosoft.com>,
 Paul Aurich <paul@...krain42.org>, Paulo Alcantara <pc@...guebit.org>,
 Ronnie Sahlberg <ronniesahlberg@...il.com>,
 Shyam Prasad N <sprasad@...rosoft.com>, Steve French <sfrench@...ba.org>,
 Tom Talpey <tom@...pey.com>
Cc: LKML <linux-kernel@...r.kernel.org>, kernel-janitors@...r.kernel.org
Subject: [PATCH] smb: client: Use more common code in open_cached_dir()

From: Markus Elfring <elfring@...rs.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@...rs.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ