Blob Blame History Raw
From: Ronnie Sahlberg <lsahlber@redhat.com>
Date: Mon, 2 Nov 2020 09:36:24 +1000
Subject: [PATCH] cifs: rename dup_vol to smb3_fs_context_dup and move it into
 fs_context.c
Git-commit: 837e3a1bbfdc105216972c83f693e96969c62351
References: bsc#1192606
Patch-mainline: v5.11-rc1

Continue restructuring needed for support of new mount API

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Acked-by: Enzo Matsumiya <ematsumiya@suse.de>
---
 fs/cifs/dfs_cache.c  | 60 +-------------------------------------------
 fs/cifs/fs_context.c | 41 ++++++++++++++++++++++++++++++
 fs/cifs/fs_context.h |  3 ++-
 3 files changed, 44 insertions(+), 60 deletions(-)

--- a/fs/cifs/dfs_cache.c
+++ b/fs/cifs/dfs_cache.c
@@ -1140,64 +1140,6 @@ out_unlock:
 	return rc;
 }
 
-static int dup_vol(struct smb3_fs_context *ctx, struct smb3_fs_context *new)
-{
-	memcpy(new, ctx, sizeof(*new));
-
-	if (ctx->username) {
-		new->username = kstrndup(ctx->username, strlen(ctx->username),
-					 GFP_KERNEL);
-		if (!new->username)
-			return -ENOMEM;
-	}
-	if (ctx->password) {
-		new->password = kstrndup(ctx->password, strlen(ctx->password),
-					 GFP_KERNEL);
-		if (!new->password)
-			goto err_free_username;
-	}
-	if (ctx->UNC) {
-		cifs_dbg(FYI, "%s: ctx->UNC: %s\n", __func__, ctx->UNC);
-		new->UNC = kstrndup(ctx->UNC, strlen(ctx->UNC), GFP_KERNEL);
-		if (!new->UNC)
-			goto err_free_password;
-	}
-	if (ctx->domainname) {
-		new->domainname = kstrndup(ctx->domainname,
-					   strlen(ctx->domainname), GFP_KERNEL);
-		if (!new->domainname)
-			goto err_free_unc;
-	}
-	if (ctx->iocharset) {
-		new->iocharset = kstrndup(ctx->iocharset,
-					  strlen(ctx->iocharset), GFP_KERNEL);
-		if (!new->iocharset)
-			goto err_free_domainname;
-	}
-	if (ctx->prepath) {
-		cifs_dbg(FYI, "%s: ctx->prepath: %s\n", __func__, ctx->prepath);
-		new->prepath = kstrndup(ctx->prepath, strlen(ctx->prepath),
-					GFP_KERNEL);
-		if (!new->prepath)
-			goto err_free_iocharset;
-	}
-
-	return 0;
-
-err_free_iocharset:
-	kfree(new->iocharset);
-err_free_domainname:
-	kfree(new->domainname);
-err_free_unc:
-	kfree(new->UNC);
-err_free_password:
-	kzfree(new->password);
-err_free_username:
-	kfree(new->username);
-	kfree(new);
-	return -ENOMEM;
-}
-
 /**
  * dfs_cache_add_vol - add a cifs volume during mount() that will be handled by
  * DFS cache refresh worker.
@@ -1228,7 +1170,7 @@ int dfs_cache_add_vol(char *mntdata, str
 		goto err_free_vi;
 	}
 
-	rc = dup_vol(ctx, &vi->ctx);
+	rc = smb3_fs_context_dup(&vi->ctx, ctx);
 	if (rc)
 		goto err_free_fullpath;
 
--- a/fs/cifs/fs_context.c
+++ b/fs/cifs/fs_context.c
@@ -7,6 +7,7 @@
  */
 
 #include "cifsglob.h"
+#include "cifsproto.h"
 #include "cifs_debug.h"
 #include "fs_context.h"
 
@@ -219,3 +220,43 @@ cifs_parse_cache_flavor(char *value, str
 	}
 	return 0;
 }
+
+#define DUP_CTX_STR(field)						\
+do {									\
+	if (ctx->field) {						\
+		new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC);	\
+		if (new_ctx->field == NULL) {				\
+			cifs_cleanup_volume_info_contents(new_ctx);	\
+			return -ENOMEM;					\
+		}							\
+	}								\
+} while (0)
+
+int
+smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
+{
+	int rc = 0;
+
+	memcpy(new_ctx, ctx, sizeof(*ctx));
+	new_ctx->prepath = NULL;
+	new_ctx->local_nls = NULL;
+	new_ctx->nodename = NULL;
+	new_ctx->username = NULL;
+	new_ctx->password = NULL;
+	new_ctx->domainname = NULL;
+	new_ctx->UNC = NULL;
+	new_ctx->iocharset = NULL;
+
+	/*
+	 * Make sure to stay in sync with cifs_cleanup_volume_info_contents()
+	 */
+	DUP_CTX_STR(prepath);
+	DUP_CTX_STR(username);
+	DUP_CTX_STR(password);
+	DUP_CTX_STR(UNC);
+	DUP_CTX_STR(domainname);
+	DUP_CTX_STR(nodename);
+	DUP_CTX_STR(iocharset);
+
+	return rc;
+}
--- a/fs/cifs/fs_context.h
+++ b/fs/cifs/fs_context.h
@@ -152,6 +152,7 @@ struct smb3_fs_context {
 	bool rootfs:1; /* if it's a SMB root file system */
 };
 
-int cifs_parse_security_flavors(char *value, struct smb3_fs_context *ctx);
+extern int cifs_parse_security_flavors(char *value, struct smb3_fs_context *ctx);
+extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx);
 
 #endif