Skip to content

Commit

Permalink
net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
Browse files Browse the repository at this point in the history
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: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Daniel Borkmann authored and David S. Miller committed Feb 8, 2013
1 parent 85bd179 commit 241448c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions net/sctp/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,30 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
struct sctp_auth_bytes *new;
__u32 len;
__u32 offset = 0;
__u16 random_len, hmacs_len, chunks_len = 0;

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

len = random_len + hmacs_len + chunks_len;

new = kmalloc(sizeof(struct sctp_auth_bytes) + len, gfp);
if (!new)
return NULL;

new->len = len;

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

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

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

return new;
}
Expand Down

0 comments on commit 241448c

Please sign in to comment.