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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250831123602.14037-32-pali@kernel.org>
Date: Sun, 31 Aug 2025 14:35:58 +0200
From: Pali Rohár <pali@...nel.org>
To: Steve French <sfrench@...ba.org>,
	Paulo Alcantara <pc@...guebit.com>,
	ronnie sahlberg <ronniesahlberg@...il.com>
Cc: linux-cifs@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 31/35] cifs: Deduplicate smb2_unlink() and smb2_rmdir() into one common function

These two functions smb2_unlink() and smb2_rmdir() share lot of common
logic. Deduplicate them into one common static function smb2_remove().

No functional change. All logic and handling stay same.

Signed-off-by: Pali Rohár <pali@...nel.org>
---
 fs/smb/client/smb2inode.c | 57 +++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c
index a3b1ed53a860..0dd4a77dfb64 100644
--- a/fs/smb/client/smb2inode.c
+++ b/fs/smb/client/smb2inode.c
@@ -1332,43 +1332,54 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name,
 		cifs_i->cifsAttrs = dosattrs;
 }
 
-int
-smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
-	   struct cifs_sb_info *cifs_sb)
+static int
+smb2_remove(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
+	    struct cifs_sb_info *cifs_sb, struct dentry *dentry, bool is_dir)
 {
 	struct cifs_open_parms oparms;
+	int op_flags;
+	int op;
+	int rc;
 
-	drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
-	oparms = CIFS_OPARMS(cifs_sb, tcon, name, DELETE,
-			     FILE_OPEN, CREATE_NOT_FILE | OPEN_REPARSE_POINT, ACL_NO_MODE);
-	return smb2_compound_op(xid, tcon, cifs_sb,
-				name, &oparms, NULL,
-				&(int){SMB2_OP_RMDIR}, 1,
-				NULL, NULL, NULL, NULL);
-}
-
-int
-smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
-	    struct cifs_sb_info *cifs_sb, struct dentry *dentry)
-{
-	struct cifs_open_parms oparms;
+	if (is_dir)
+		drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
 
+	if (is_dir) {
+		op = SMB2_OP_RMDIR;
+		op_flags = CREATE_NOT_FILE;
+	} else {
+		op = SMB2_OP_DELETE;
+		op_flags = CREATE_NOT_DIR;
+	}
 	oparms = CIFS_OPARMS(cifs_sb, tcon, name,
 			     DELETE, FILE_OPEN,
-			     CREATE_NOT_DIR | OPEN_REPARSE_POINT,
+			     OPEN_REPARSE_POINT | op_flags,
 			     ACL_NO_MODE);
-	int rc = smb2_compound_op(xid, tcon, cifs_sb, name, &oparms,
-				  NULL, &(int){SMB2_OP_DELETE}, 1,
-				  NULL, NULL, NULL, dentry);
-	if (rc == -EINVAL) {
+	rc = smb2_compound_op(xid, tcon, cifs_sb, name, &oparms,
+			      NULL, &op, 1, NULL, NULL, NULL, dentry);
+	if (rc == -EINVAL && dentry) {
 		cifs_dbg(FYI, "invalid lease key, resending request without lease");
 		rc = smb2_compound_op(xid, tcon, cifs_sb, name, &oparms,
-				      NULL, &(int){SMB2_OP_DELETE}, 1,
+				      NULL, &op, 1,
 				      NULL, NULL, NULL, NULL);
 	}
 	return rc;
 }
 
+int
+smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
+	   struct cifs_sb_info *cifs_sb)
+{
+	return smb2_remove(xid, tcon, name, cifs_sb, NULL, true /* is_dir */);
+}
+
+int
+smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
+	    struct cifs_sb_info *cifs_sb, struct dentry *dentry)
+{
+	return smb2_remove(xid, tcon, name, cifs_sb, dentry, false /* is_dir */);
+}
+
 static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
 			      const char *from_name, const char *to_name,
 			      struct cifs_sb_info *cifs_sb,
-- 
2.20.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ