diff options
author | Arnaldo Carvalho de Melo <acme@mandriva.com> | 2006-11-17 08:06:01 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:23:54 -0500 |
commit | f6685938f9181e95f814edfca287d4f04a925240 (patch) | |
tree | bda4df5ddf8bb3e34bbd7bf5a44268b3da0b6d4b /net | |
parent | 7174259e6ced15bebee202983511d8fc950e929f (diff) |
[TCP_IPV4]: Use kmemdup where appropriate
Also use a variable to avoid the longish tp->md5sig_info-> use
in tcp_v4_md5_do_add.
Code diff stats:
[acme@newtoy net-2.6.20]$ codiff /tmp/tcp_ipv4.o.before /tmp/tcp_ipv4.o.after
/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ipv4/tcp_ipv4.c:
tcp_v4_md5_do_add | -62
tcp_v4_syn_recv_sock | -32
tcp_v4_parse_md5_keys | -86
3 functions changed, 180 bytes removed
[acme@newtoy net-2.6.20]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 010dff442a11..b7d5522092eb 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -855,15 +855,18 @@ int tcp_v4_md5_do_add(struct sock *sk, __be32 addr, | |||
855 | struct tcp_sock *tp = tcp_sk(sk); | 855 | struct tcp_sock *tp = tcp_sk(sk); |
856 | struct tcp4_md5sig_key *keys; | 856 | struct tcp4_md5sig_key *keys; |
857 | 857 | ||
858 | key = (struct tcp4_md5sig_key *) tcp_v4_md5_do_lookup(sk, addr); | 858 | key = (struct tcp4_md5sig_key *)tcp_v4_md5_do_lookup(sk, addr); |
859 | if (key) { | 859 | if (key) { |
860 | /* Pre-existing entry - just update that one. */ | 860 | /* Pre-existing entry - just update that one. */ |
861 | kfree (key->key); | 861 | kfree(key->key); |
862 | key->key = newkey; | 862 | key->key = newkey; |
863 | key->keylen = newkeylen; | 863 | key->keylen = newkeylen; |
864 | } else { | 864 | } else { |
865 | struct tcp_md5sig_info *md5sig; | ||
866 | |||
865 | if (!tp->md5sig_info) { | 867 | if (!tp->md5sig_info) { |
866 | tp->md5sig_info = kzalloc(sizeof(*tp->md5sig_info), GFP_ATOMIC); | 868 | tp->md5sig_info = kzalloc(sizeof(*tp->md5sig_info), |
869 | GFP_ATOMIC); | ||
867 | if (!tp->md5sig_info) { | 870 | if (!tp->md5sig_info) { |
868 | kfree(newkey); | 871 | kfree(newkey); |
869 | return -ENOMEM; | 872 | return -ENOMEM; |
@@ -873,30 +876,31 @@ int tcp_v4_md5_do_add(struct sock *sk, __be32 addr, | |||
873 | kfree(newkey); | 876 | kfree(newkey); |
874 | return -ENOMEM; | 877 | return -ENOMEM; |
875 | } | 878 | } |
876 | if (tp->md5sig_info->alloced4 == tp->md5sig_info->entries4) { | 879 | md5sig = tp->md5sig_info; |
877 | keys = kmalloc((sizeof(struct tcp4_md5sig_key) * | 880 | |
878 | (tp->md5sig_info->entries4 + 1)), GFP_ATOMIC); | 881 | if (md5sig->alloced4 == md5sig->entries4) { |
882 | keys = kmalloc((sizeof(*keys) * | ||
883 | (md5sig->entries4 + 1)), GFP_ATOMIC); | ||
879 | if (!keys) { | 884 | if (!keys) { |
880 | kfree(newkey); | 885 | kfree(newkey); |
881 | tcp_free_md5sig_pool(); | 886 | tcp_free_md5sig_pool(); |
882 | return -ENOMEM; | 887 | return -ENOMEM; |
883 | } | 888 | } |
884 | 889 | ||
885 | if (tp->md5sig_info->entries4) | 890 | if (md5sig->entries4) |
886 | memcpy(keys, tp->md5sig_info->keys4, | 891 | memcpy(keys, md5sig->keys4, |
887 | (sizeof (struct tcp4_md5sig_key) * | 892 | sizeof(*keys) * md5sig->entries4); |
888 | tp->md5sig_info->entries4)); | ||
889 | 893 | ||
890 | /* Free old key list, and reference new one */ | 894 | /* Free old key list, and reference new one */ |
891 | if (tp->md5sig_info->keys4) | 895 | if (md5sig->keys4) |
892 | kfree(tp->md5sig_info->keys4); | 896 | kfree(md5sig->keys4); |
893 | tp->md5sig_info->keys4 = keys; | 897 | md5sig->keys4 = keys; |
894 | tp->md5sig_info->alloced4++; | 898 | md5sig->alloced4++; |
895 | } | 899 | } |
896 | tp->md5sig_info->entries4++; | 900 | md5sig->entries4++; |
897 | tp->md5sig_info->keys4[tp->md5sig_info->entries4 - 1].addr = addr; | 901 | md5sig->keys4[md5sig->entries4 - 1].addr = addr; |
898 | tp->md5sig_info->keys4[tp->md5sig_info->entries4 - 1].key = newkey; | 902 | md5sig->keys4[md5sig->entries4 - 1].key = newkey; |
899 | tp->md5sig_info->keys4[tp->md5sig_info->entries4 - 1].keylen = newkeylen; | 903 | md5sig->keys4[md5sig->entries4 - 1].keylen = newkeylen; |
900 | } | 904 | } |
901 | return 0; | 905 | return 0; |
902 | } | 906 | } |
@@ -998,10 +1002,9 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, char __user *optval, | |||
998 | 1002 | ||
999 | } | 1003 | } |
1000 | 1004 | ||
1001 | newkey = kmalloc(cmd.tcpm_keylen, GFP_KERNEL); | 1005 | newkey = kmemdup(cmd.tcpm_key, cmd.tcpm_keylen, GFP_KERNEL); |
1002 | if (!newkey) | 1006 | if (!newkey) |
1003 | return -ENOMEM; | 1007 | return -ENOMEM; |
1004 | memcpy(newkey, cmd.tcpm_key, cmd.tcpm_keylen); | ||
1005 | return tcp_v4_md5_do_add(sk, sin->sin_addr.s_addr, | 1008 | return tcp_v4_md5_do_add(sk, sin->sin_addr.s_addr, |
1006 | newkey, cmd.tcpm_keylen); | 1009 | newkey, cmd.tcpm_keylen); |
1007 | } | 1010 | } |
@@ -1494,12 +1497,10 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
1494 | * memory, then we end up not copying the key | 1497 | * memory, then we end up not copying the key |
1495 | * across. Shucks. | 1498 | * across. Shucks. |
1496 | */ | 1499 | */ |
1497 | char *newkey = kmalloc(key->keylen, GFP_ATOMIC); | 1500 | char *newkey = kmemdup(key->key, key->keylen, GFP_ATOMIC); |
1498 | if (newkey) { | 1501 | if (newkey != NULL) |
1499 | memcpy(newkey, key->key, key->keylen); | ||
1500 | tcp_v4_md5_do_add(newsk, inet_sk(sk)->daddr, | 1502 | tcp_v4_md5_do_add(newsk, inet_sk(sk)->daddr, |
1501 | newkey, key->keylen); | 1503 | newkey, key->keylen); |
1502 | } | ||
1503 | } | 1504 | } |
1504 | #endif | 1505 | #endif |
1505 | 1506 | ||