Skip to content

Commit a12a07a

Browse files
ddisssmfrench
authored andcommitted
ksmbd: avoid duplicate negotiate ctx offset increments
Both pneg_ctxt and ctxt_size change in unison, with each adding the length of the previously added context, rounded up to an eight byte boundary. Drop pneg_ctxt increments and instead use the ctxt_size offset when passing output pointers to per-context helper functions. This slightly simplifies offset tracking and shaves off a few text bytes. Before (x86-64 gcc 7.5): text data bss dec hex filename 213234 8677 672 222583 36577 ksmbd.ko After: text data bss dec hex filename 213218 8677 672 222567 36567 ksmbd.ko Signed-off-by: David Disseldorp <ddiss@suse.de> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 34e8ccf commit a12a07a

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

fs/ksmbd/smb2pdu.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static void assemble_neg_contexts(struct ksmbd_conn *conn,
808808
struct smb2_negotiate_rsp *rsp,
809809
void *smb2_buf_len)
810810
{
811-
char *pneg_ctxt = (char *)rsp +
811+
char * const pneg_ctxt = (char *)rsp +
812812
le32_to_cpu(rsp->NegotiateContextOffset);
813813
int neg_ctxt_cnt = 1;
814814
int ctxt_size;
@@ -819,53 +819,47 @@ static void assemble_neg_contexts(struct ksmbd_conn *conn,
819819
conn->preauth_info->Preauth_HashId);
820820
inc_rfc1001_len(smb2_buf_len, AUTH_GSS_PADDING);
821821
ctxt_size = sizeof(struct smb2_preauth_neg_context);
822-
/* Round to 8 byte boundary */
823-
pneg_ctxt += round_up(sizeof(struct smb2_preauth_neg_context), 8);
824822

825823
if (conn->cipher_type) {
824+
/* Round to 8 byte boundary */
826825
ctxt_size = round_up(ctxt_size, 8);
827826
ksmbd_debug(SMB,
828827
"assemble SMB2_ENCRYPTION_CAPABILITIES context\n");
829-
build_encrypt_ctxt((struct smb2_encryption_neg_context *)pneg_ctxt,
828+
build_encrypt_ctxt((struct smb2_encryption_neg_context *)
829+
(pneg_ctxt + ctxt_size),
830830
conn->cipher_type);
831831
neg_ctxt_cnt++;
832832
ctxt_size += sizeof(struct smb2_encryption_neg_context) + 2;
833-
/* Round to 8 byte boundary */
834-
pneg_ctxt +=
835-
round_up(sizeof(struct smb2_encryption_neg_context) + 2,
836-
8);
837833
}
838834

839835
if (conn->compress_algorithm) {
840836
ctxt_size = round_up(ctxt_size, 8);
841837
ksmbd_debug(SMB,
842838
"assemble SMB2_COMPRESSION_CAPABILITIES context\n");
843839
/* Temporarily set to SMB3_COMPRESS_NONE */
844-
build_compression_ctxt((struct smb2_compression_capabilities_context *)pneg_ctxt,
840+
build_compression_ctxt((struct smb2_compression_capabilities_context *)
841+
(pneg_ctxt + ctxt_size),
845842
conn->compress_algorithm);
846843
neg_ctxt_cnt++;
847844
ctxt_size += sizeof(struct smb2_compression_capabilities_context) + 2;
848-
/* Round to 8 byte boundary */
849-
pneg_ctxt += round_up(sizeof(struct smb2_compression_capabilities_context) + 2,
850-
8);
851845
}
852846

853847
if (conn->posix_ext_supported) {
854848
ctxt_size = round_up(ctxt_size, 8);
855849
ksmbd_debug(SMB,
856850
"assemble SMB2_POSIX_EXTENSIONS_AVAILABLE context\n");
857-
build_posix_ctxt((struct smb2_posix_neg_context *)pneg_ctxt);
851+
build_posix_ctxt((struct smb2_posix_neg_context *)
852+
(pneg_ctxt + ctxt_size));
858853
neg_ctxt_cnt++;
859854
ctxt_size += sizeof(struct smb2_posix_neg_context);
860-
/* Round to 8 byte boundary */
861-
pneg_ctxt += round_up(sizeof(struct smb2_posix_neg_context), 8);
862855
}
863856

864857
if (conn->signing_negotiated) {
865858
ctxt_size = round_up(ctxt_size, 8);
866859
ksmbd_debug(SMB,
867860
"assemble SMB2_SIGNING_CAPABILITIES context\n");
868-
build_sign_cap_ctxt((struct smb2_signing_capabilities *)pneg_ctxt,
861+
build_sign_cap_ctxt((struct smb2_signing_capabilities *)
862+
(pneg_ctxt + ctxt_size),
869863
conn->signing_algorithm);
870864
neg_ctxt_cnt++;
871865
ctxt_size += sizeof(struct smb2_signing_capabilities) + 2;

0 commit comments

Comments
 (0)