From: Vlad Yasevich <vyasevich@gmail.com>
To: Daniel Borkmann <dborkman@redhat.com>
Cc: davem@davemloft.net, linux-sctp@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
Date: Thu, 07 Feb 2013 15:06:37 +0000 [thread overview]
Message-ID: <5113C2FD.4060103@gmail.com> (raw)
In-Reply-To: <c029f55f4d0bde790f77f62d623f4d1e387c4c0b.1360237025.git.dborkman@redhat.com>
On 02/07/2013 06:41 AM, Daniel Borkmann wrote:
> 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: Vlad Yasevich <vyasevich@gmail.com>
-vlad
> ---
> net/sctp/auth.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/net/sctp/auth.c b/net/sctp/auth.c
> index 159b9bc..94a12de 100644
> --- a/net/sctp/auth.c
> +++ b/net/sctp/auth.c
> @@ -200,10 +200,14 @@ 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)
> @@ -211,16 +215,15 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
>
> 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;
> }
>
WARNING: multiple messages have this Message-ID (diff)
From: Vlad Yasevich <vyasevich@gmail.com>
To: Daniel Borkmann <dborkman@redhat.com>
Cc: davem@davemloft.net, linux-sctp@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
Date: Thu, 07 Feb 2013 10:06:37 -0500 [thread overview]
Message-ID: <5113C2FD.4060103@gmail.com> (raw)
In-Reply-To: <c029f55f4d0bde790f77f62d623f4d1e387c4c0b.1360237025.git.dborkman@redhat.com>
On 02/07/2013 06:41 AM, Daniel Borkmann wrote:
> 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: Vlad Yasevich <vyasevich@gmail.com>
-vlad
> ---
> net/sctp/auth.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/net/sctp/auth.c b/net/sctp/auth.c
> index 159b9bc..94a12de 100644
> --- a/net/sctp/auth.c
> +++ b/net/sctp/auth.c
> @@ -200,10 +200,14 @@ 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)
> @@ -211,16 +215,15 @@ static struct sctp_auth_bytes *sctp_auth_make_key_vector(
>
> 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;
> }
>
next prev parent reply other threads:[~2013-02-07 15:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1360237025.git.dborkman@redhat.com>
2013-02-07 11:41 ` [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls Daniel Borkmann
2013-02-07 11:41 ` Daniel Borkmann
2013-02-07 14:53 ` Neil Horman
2013-02-07 14:53 ` Neil Horman
2013-02-07 15:06 ` Vlad Yasevich [this message]
2013-02-07 15:06 ` Vlad Yasevich
2013-02-08 4:45 ` David Miller
2013-02-08 4:45 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5113C2FD.4060103@gmail.com \
--to=vyasevich@gmail.com \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=linux-sctp@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.