Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 241448c2 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller
Browse files

net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls



Instead of calling 3 times ntohs(random->param_hdr.length), 2 times
ntohs(hmacs->param_hdr.length), and 3 times ntohs(chunks->param_hdr.length)
within the same function, we only call each once and store it in a
variable.

Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
Acked-by: default avatarVlad Yasevich <vyasevich@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 85bd1798
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -200,10 +200,14 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
	struct sctp_auth_bytes *new;
	struct sctp_auth_bytes *new;
	__u32	len;
	__u32	len;
	__u32	offset = 0;
	__u32	offset = 0;
	__u16	random_len, hmacs_len, chunks_len = 0;


	len = ntohs(random->param_hdr.length) + ntohs(hmacs->param_hdr.length);
	random_len = ntohs(random->param_hdr.length);
	hmacs_len = ntohs(hmacs->param_hdr.length);
	if (chunks)
	if (chunks)
		len += ntohs(chunks->param_hdr.length);
		chunks_len = ntohs(chunks->param_hdr.length);

	len = random_len + hmacs_len + chunks_len;


	new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
	new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
	if (!new)
	if (!new)
@@ -211,16 +215,15 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(


	new->len = len;
	new->len = len;


	memcpy(new->data, random, ntohs(random->param_hdr.length));
	memcpy(new->data, random, random_len);
	offset += ntohs(random->param_hdr.length);
	offset += random_len;


	if (chunks) {
	if (chunks) {
		memcpy(new->data + offset, chunks,
		memcpy(new->data + offset, chunks, chunks_len);
			ntohs(chunks->param_hdr.length));
		offset += chunks_len;
		offset += ntohs(chunks->param_hdr.length);
	}
	}


	memcpy(new->data + offset, hmacs, ntohs(hmacs->param_hdr.length));
	memcpy(new->data + offset, hmacs, hmacs_len);


	return new;
	return new;
}
}