aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/ccids
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2007-09-26 10:24:28 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:52:41 -0400
commit2e86908f7dfb71b67ca4739d9a6c678b83b01078 (patch)
tree34000d4935057601e86b448698ff5fa55910b852 /net/dccp/ccids
parent08831700cc65f85a497d6b32b1c83ca84d71de4a (diff)
[CCID3]: Move NULL-protection into function
This moves several instances of testing against NULL into the function which is used to de-reference the CCID-private data. Committer note: Made the BUG_ON depend on having CONFIG_IP_DCCP_CCID3_DEBUG, as it is too much to have this on production code. Also made sure that the macro is used only after checking if sk_state is not LISTEN, to make it equivalent to what we had before. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Diffstat (limited to 'net/dccp/ccids')
-rw-r--r--net/dccp/ccids/ccid3.c35
-rw-r--r--net/dccp/ccids/ccid3.h20
2 files changed, 24 insertions, 31 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 0bb338be9dd7..a4099398bcc8 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -302,8 +302,6 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
302 ktime_t now = ktime_get_real(); 302 ktime_t now = ktime_get_real();
303 s64 delay; 303 s64 delay;
304 304
305 BUG_ON(hctx == NULL);
306
307 /* 305 /*
308 * This function is called only for Data and DataAck packets. Sending 306 * This function is called only for Data and DataAck packets. Sending
309 * zero-sized Data(Ack)s is theoretically possible, but for congestion 307 * zero-sized Data(Ack)s is theoretically possible, but for congestion
@@ -383,8 +381,6 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more,
383 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 381 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
384 struct dccp_tx_hist_entry *packet; 382 struct dccp_tx_hist_entry *packet;
385 383
386 BUG_ON(hctx == NULL);
387
388 ccid3_hc_tx_update_s(hctx, len); 384 ccid3_hc_tx_update_s(hctx, len);
389 385
390 packet = dccp_tx_hist_entry_new(ccid3_tx_hist, GFP_ATOMIC); 386 packet = dccp_tx_hist_entry_new(ccid3_tx_hist, GFP_ATOMIC);
@@ -409,8 +405,6 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
409 unsigned long t_nfb; 405 unsigned long t_nfb;
410 u32 pinv, r_sample; 406 u32 pinv, r_sample;
411 407
412 BUG_ON(hctx == NULL);
413
414 /* we are only interested in ACKs */ 408 /* we are only interested in ACKs */
415 if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || 409 if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK ||
416 DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) 410 DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK))
@@ -551,8 +545,6 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
551 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 545 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
552 struct ccid3_options_received *opt_recv; 546 struct ccid3_options_received *opt_recv;
553 547
554 BUG_ON(hctx == NULL);
555
556 opt_recv = &hctx->ccid3hctx_options_received; 548 opt_recv = &hctx->ccid3hctx_options_received;
557 549
558 if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { 550 if (opt_recv->ccid3or_seqno != dp->dccps_gsr) {
@@ -626,8 +618,6 @@ static void ccid3_hc_tx_exit(struct sock *sk)
626{ 618{
627 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 619 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
628 620
629 BUG_ON(hctx == NULL);
630
631 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); 621 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM);
632 sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); 622 sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
633 623
@@ -637,14 +627,13 @@ static void ccid3_hc_tx_exit(struct sock *sk)
637 627
638static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) 628static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
639{ 629{
640 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 630 struct ccid3_hc_tx_sock *hctx;
641 631
642 /* Listen socks doesn't have a private CCID block */ 632 /* Listen socks doesn't have a private CCID block */
643 if (sk->sk_state == DCCP_LISTEN) 633 if (sk->sk_state == DCCP_LISTEN)
644 return; 634 return;
645 635
646 BUG_ON(hctx == NULL); 636 hctx = ccid3_hc_tx_sk(sk);
647
648 info->tcpi_rto = hctx->ccid3hctx_t_rto; 637 info->tcpi_rto = hctx->ccid3hctx_t_rto;
649 info->tcpi_rtt = hctx->ccid3hctx_rtt; 638 info->tcpi_rtt = hctx->ccid3hctx_rtt;
650} 639}
@@ -652,13 +641,14 @@ static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
652static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len, 641static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
653 u32 __user *optval, int __user *optlen) 642 u32 __user *optval, int __user *optlen)
654{ 643{
655 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 644 const struct ccid3_hc_tx_sock *hctx;
656 const void *val; 645 const void *val;
657 646
658 /* Listen socks doesn't have a private CCID block */ 647 /* Listen socks doesn't have a private CCID block */
659 if (sk->sk_state == DCCP_LISTEN) 648 if (sk->sk_state == DCCP_LISTEN)
660 return -EINVAL; 649 return -EINVAL;
661 650
651 hctx = ccid3_hc_tx_sk(sk);
662 switch (optname) { 652 switch (optname) {
663 case DCCP_SOCKOPT_CCID_TX_INFO: 653 case DCCP_SOCKOPT_CCID_TX_INFO:
664 if (len < sizeof(hctx->ccid3hctx_tfrc)) 654 if (len < sizeof(hctx->ccid3hctx_tfrc))
@@ -772,14 +762,13 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
772 762
773static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) 763static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
774{ 764{
775 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 765 const struct ccid3_hc_rx_sock *hcrx;
776 __be32 x_recv, pinv; 766 __be32 x_recv, pinv;
777 767
778 BUG_ON(hcrx == NULL);
779
780 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) 768 if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
781 return 0; 769 return 0;
782 770
771 hcrx = ccid3_hc_rx_sk(sk);
783 DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_ccval_last_counter; 772 DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_ccval_last_counter;
784 773
785 if (dccp_packet_without_ack(skb)) 774 if (dccp_packet_without_ack(skb))
@@ -870,8 +859,6 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
870 int loss, payload_size; 859 int loss, payload_size;
871 ktime_t now; 860 ktime_t now;
872 861
873 BUG_ON(hcrx == NULL);
874
875 opt_recv = &dccp_sk(sk)->dccps_options_received; 862 opt_recv = &dccp_sk(sk)->dccps_options_received;
876 863
877 switch (DCCP_SKB_CB(skb)->dccpd_type) { 864 switch (DCCP_SKB_CB(skb)->dccpd_type) {
@@ -985,8 +972,6 @@ static void ccid3_hc_rx_exit(struct sock *sk)
985{ 972{
986 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 973 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
987 974
988 BUG_ON(hcrx == NULL);
989
990 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); 975 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
991 976
992 /* Empty packet history */ 977 /* Empty packet history */
@@ -998,14 +983,13 @@ static void ccid3_hc_rx_exit(struct sock *sk)
998 983
999static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) 984static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1000{ 985{
1001 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 986 const struct ccid3_hc_rx_sock *hcrx;
1002 987
1003 /* Listen socks doesn't have a private CCID block */ 988 /* Listen socks doesn't have a private CCID block */
1004 if (sk->sk_state == DCCP_LISTEN) 989 if (sk->sk_state == DCCP_LISTEN)
1005 return; 990 return;
1006 991
1007 BUG_ON(hcrx == NULL); 992 hcrx = ccid3_hc_rx_sk(sk);
1008
1009 info->tcpi_ca_state = hcrx->ccid3hcrx_state; 993 info->tcpi_ca_state = hcrx->ccid3hcrx_state;
1010 info->tcpi_options |= TCPI_OPT_TIMESTAMPS; 994 info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1011 info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; 995 info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt;
@@ -1014,13 +998,14 @@ static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1014static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len, 998static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,
1015 u32 __user *optval, int __user *optlen) 999 u32 __user *optval, int __user *optlen)
1016{ 1000{
1017 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 1001 const struct ccid3_hc_rx_sock *hcrx;
1018 const void *val; 1002 const void *val;
1019 1003
1020 /* Listen socks doesn't have a private CCID block */ 1004 /* Listen socks doesn't have a private CCID block */
1021 if (sk->sk_state == DCCP_LISTEN) 1005 if (sk->sk_state == DCCP_LISTEN)
1022 return -EINVAL; 1006 return -EINVAL;
1023 1007
1008 hcrx = ccid3_hc_rx_sk(sk);
1024 switch (optname) { 1009 switch (optname) {
1025 case DCCP_SOCKOPT_CCID_RX_INFO: 1010 case DCCP_SOCKOPT_CCID_RX_INFO:
1026 if (len < sizeof(hcrx->ccid3hcrx_tfrc)) 1011 if (len < sizeof(hcrx->ccid3hcrx_tfrc))
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index 7cbf2b1329d9..ae99ec430371 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -117,6 +117,15 @@ struct ccid3_hc_tx_sock {
117 struct ccid3_options_received ccid3hctx_options_received; 117 struct ccid3_options_received ccid3hctx_options_received;
118}; 118};
119 119
120static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
121{
122 struct ccid3_hc_tx_sock *hctx = ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
123#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
124 BUG_ON(hctx == NULL);
125#endif
126 return hctx;
127}
128
120/* TFRC receiver states */ 129/* TFRC receiver states */
121enum ccid3_hc_rx_states { 130enum ccid3_hc_rx_states {
122 TFRC_RSTATE_NO_DATA = 1, 131 TFRC_RSTATE_NO_DATA = 1,
@@ -161,14 +170,13 @@ struct ccid3_hc_rx_sock {
161 u32 ccid3hcrx_elapsed_time; 170 u32 ccid3hcrx_elapsed_time;
162}; 171};
163 172
164static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
165{
166 return ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
167}
168
169static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk) 173static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
170{ 174{
171 return ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid); 175 struct ccid3_hc_rx_sock *hcrx = ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid);
176#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
177 BUG_ON(hcrx == NULL);
178#endif
179 return hcrx;
172} 180}
173 181
174#endif /* _DCCP_CCID3_H_ */ 182#endif /* _DCCP_CCID3_H_ */