and after mount option parsing we fill it */
        char *domainName;
        char *password;
-       char *workstation_name;
+       char workstation_name[CIFS_MAX_WORKSTATION_LEN];
        struct session_key auth_key;
        struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
        enum securityEnum sectype; /* what security flavor was specified? */
        return fl->fl_end == OFFSET_MAX ? 0 : fl->fl_end - fl->fl_start + 1;
 }
 
+static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses)
+{
+       if (WARN_ON_ONCE(!ses || !ses->server))
+               return 0;
+       /*
+        * Make workstation name no more than 15 chars when using insecure dialects as some legacy
+        * servers do require it during NTLMSSP.
+        */
+       if (ses->server->dialect <= SMB20_PROT_ID)
+               return min_t(size_t, sizeof(ses->workstation_name), RFC1001_NAME_LEN_WITH_NULL);
+       return sizeof(ses->workstation_name);
+}
+
 #endif /* _CIFS_GLOB_H */
 
                }
        }
 
-       ctx->workstation_name = kstrdup(ses->workstation_name, GFP_KERNEL);
-       if (!ctx->workstation_name) {
-               cifs_dbg(FYI, "Unable to allocate memory for workstation_name\n");
-               rc = -ENOMEM;
-               kfree(ctx->username);
-               ctx->username = NULL;
-               kfree_sensitive(ctx->password);
-               ctx->password = NULL;
-               kfree(ctx->domainname);
-               ctx->domainname = NULL;
-               goto out_key_put;
-       }
+       strscpy(ctx->workstation_name, ses->workstation_name, sizeof(ctx->workstation_name));
 
 out_key_put:
        up_read(&key->sem);
                if (!ses->domainName)
                        goto get_ses_fail;
        }
-       if (ctx->workstation_name) {
-               ses->workstation_name = kstrdup(ctx->workstation_name,
-                                               GFP_KERNEL);
-               if (!ses->workstation_name)
-                       goto get_ses_fail;
-       }
+
+       strscpy(ses->workstation_name, ctx->workstation_name, sizeof(ses->workstation_name));
+
        if (ctx->domainauto)
                ses->domainAuto = ctx->domainauto;
        ses->cred_uid = ctx->cred_uid;
 
        new_ctx->password = NULL;
        new_ctx->server_hostname = NULL;
        new_ctx->domainname = NULL;
-       new_ctx->workstation_name = NULL;
        new_ctx->UNC = NULL;
        new_ctx->source = NULL;
        new_ctx->iocharset = NULL;
        DUP_CTX_STR(UNC);
        DUP_CTX_STR(source);
        DUP_CTX_STR(domainname);
-       DUP_CTX_STR(workstation_name);
        DUP_CTX_STR(nodename);
        DUP_CTX_STR(iocharset);
 
                cifs_errorf(fc, "can not change domainname during remount\n");
                return -EINVAL;
        }
-       if (new_ctx->workstation_name &&
-           (!old_ctx->workstation_name || strcmp(new_ctx->workstation_name, old_ctx->workstation_name))) {
+       if (strcmp(new_ctx->workstation_name, old_ctx->workstation_name)) {
                cifs_errorf(fc, "can not change workstation_name during remount\n");
                return -EINVAL;
        }
        STEAL_STRING(cifs_sb, ctx, username);
        STEAL_STRING(cifs_sb, ctx, password);
        STEAL_STRING(cifs_sb, ctx, domainname);
-       STEAL_STRING(cifs_sb, ctx, workstation_name);
        STEAL_STRING(cifs_sb, ctx, nodename);
        STEAL_STRING(cifs_sb, ctx, iocharset);
 
 
 int smb3_init_fs_context(struct fs_context *fc)
 {
-       int rc;
        struct smb3_fs_context *ctx;
        char *nodename = utsname()->nodename;
        int i;
 
        ctx = kzalloc(sizeof(struct smb3_fs_context), GFP_KERNEL);
-       if (unlikely(!ctx)) {
-               rc = -ENOMEM;
-               goto err_exit;
-       }
+       if (unlikely(!ctx))
+               return -ENOMEM;
 
-       ctx->workstation_name = kstrdup(nodename, GFP_KERNEL);
-       if (unlikely(!ctx->workstation_name)) {
-               rc = -ENOMEM;
-               goto err_exit;
-       }
+       strscpy(ctx->workstation_name, nodename, sizeof(ctx->workstation_name));
 
        /*
         * does not have to be perfect mapping since field is
        fc->fs_private = ctx;
        fc->ops = &smb3_fs_context_ops;
        return 0;
-
-err_exit:
-       if (ctx) {
-               kfree(ctx->workstation_name);
-               kfree(ctx);
-       }
-
-       return rc;
 }
 
 void
        ctx->source = NULL;
        kfree(ctx->domainname);
        ctx->domainname = NULL;
-       kfree(ctx->workstation_name);
-       ctx->workstation_name = NULL;
        kfree(ctx->nodename);
        ctx->nodename = NULL;
        kfree(ctx->iocharset);
 
        char *server_hostname;
        char *UNC;
        char *nodename;
-       char *workstation_name;
+       char workstation_name[CIFS_MAX_WORKSTATION_LEN];
        char *iocharset;  /* local code page for mapping to and from Unicode */
        char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
        char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
 
        kfree_sensitive(buf_to_free->password);
        kfree(buf_to_free->user_name);
        kfree(buf_to_free->domainName);
-       kfree(buf_to_free->workstation_name);
        kfree_sensitive(buf_to_free->auth_key.response);
        kfree(buf_to_free->iface_list);
        kfree_sensitive(buf_to_free);
 
        else
                sz += sizeof(__le16);
 
-       if (ses->workstation_name)
+       if (ses->workstation_name[0])
                sz += sizeof(__le16) * strnlen(ses->workstation_name,
-                       CIFS_MAX_WORKSTATION_LEN);
+                                              ntlmssp_workstation_name_size(ses));
        else
                sz += sizeof(__le16);
 
 
        cifs_security_buffer_from_str(&sec_blob->WorkstationName,
                                      ses->workstation_name,
-                                     CIFS_MAX_WORKSTATION_LEN,
+                                     ntlmssp_workstation_name_size(ses),
                                      *pbuffer, &tmp,
                                      nls_cp);