* [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
[not found] <cover.1360237025.git.dborkman@redhat.com>
@ 2013-02-07 11:41 ` Daniel Borkmann
2013-02-07 14:53 ` Neil Horman
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Daniel Borkmann @ 2013-02-07 11:41 UTC (permalink / raw)
To: davem; +Cc: vyasevich, linux-sctp, netdev
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>
---
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;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
2013-02-07 11:41 ` [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls Daniel Borkmann
@ 2013-02-07 14:53 ` Neil Horman
2013-02-07 15:06 ` Vlad Yasevich
2013-02-08 4:45 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Neil Horman @ 2013-02-07 14:53 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: davem, vyasevich, linux-sctp, netdev
On Thu, Feb 07, 2013 at 12:41:39PM +0100, 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>
> ---
> 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;
> }
> --
> 1.7.11.7
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
2013-02-07 11:41 ` [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls Daniel Borkmann
2013-02-07 14:53 ` Neil Horman
@ 2013-02-07 15:06 ` Vlad Yasevich
2013-02-08 4:45 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: Vlad Yasevich @ 2013-02-07 15:06 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: davem, linux-sctp, netdev
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;
> }
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls
2013-02-07 11:41 ` [PATCH net-next] net: sctp: sctp_auth_make_key_vector: remove duplicate ntohs calls Daniel Borkmann
2013-02-07 14:53 ` Neil Horman
2013-02-07 15:06 ` Vlad Yasevich
@ 2013-02-08 4:45 ` David Miller
2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2013-02-08 4:45 UTC (permalink / raw)
To: dborkman; +Cc: vyasevich, linux-sctp, netdev
From: Daniel Borkmann <dborkman@redhat.com>
Date: Thu, 7 Feb 2013 12:41:39 +0100
> 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>
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-02-08 4:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 14:53 ` Neil Horman
2013-02-07 15:06 ` Vlad Yasevich
2013-02-08 4:45 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).