@@ -656,7 +656,6 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
656656/* Insert endpoint into the hash table. */
657657static void __sctp_hash_endpoint (struct sctp_endpoint * ep )
658658{
659- struct sctp_ep_common * * epp ;
660659 struct sctp_ep_common * epb ;
661660 struct sctp_hashbucket * head ;
662661
@@ -666,12 +665,7 @@ static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
666665 head = & sctp_ep_hashtable [epb -> hashent ];
667666
668667 sctp_write_lock (& head -> lock );
669- epp = & head -> chain ;
670- epb -> next = * epp ;
671- if (epb -> next )
672- (* epp )-> pprev = & epb -> next ;
673- * epp = epb ;
674- epb -> pprev = epp ;
668+ hlist_add_head (& epb -> node , & head -> chain );
675669 sctp_write_unlock (& head -> lock );
676670}
677671
@@ -691,19 +685,15 @@ static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
691685
692686 epb = & ep -> base ;
693687
688+ if (hlist_unhashed (& epb -> node ))
689+ return ;
690+
694691 epb -> hashent = sctp_ep_hashfn (epb -> bind_addr .port );
695692
696693 head = & sctp_ep_hashtable [epb -> hashent ];
697694
698695 sctp_write_lock (& head -> lock );
699-
700- if (epb -> pprev ) {
701- if (epb -> next )
702- epb -> next -> pprev = epb -> pprev ;
703- * epb -> pprev = epb -> next ;
704- epb -> pprev = NULL ;
705- }
706-
696+ __hlist_del (& epb -> node );
707697 sctp_write_unlock (& head -> lock );
708698}
709699
@@ -721,12 +711,13 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *l
721711 struct sctp_hashbucket * head ;
722712 struct sctp_ep_common * epb ;
723713 struct sctp_endpoint * ep ;
714+ struct hlist_node * node ;
724715 int hash ;
725716
726717 hash = sctp_ep_hashfn (ntohs (laddr -> v4 .sin_port ));
727718 head = & sctp_ep_hashtable [hash ];
728719 read_lock (& head -> lock );
729- for (epb = head -> chain ; epb ; epb = epb -> next ) {
720+ sctp_for_each_hentry (epb , node , & head -> chain ) {
730721 ep = sctp_ep (epb );
731722 if (sctp_endpoint_is_match (ep , laddr ))
732723 goto hit ;
@@ -744,7 +735,6 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *l
744735/* Insert association into the hash table. */
745736static void __sctp_hash_established (struct sctp_association * asoc )
746737{
747- struct sctp_ep_common * * epp ;
748738 struct sctp_ep_common * epb ;
749739 struct sctp_hashbucket * head ;
750740
@@ -756,12 +746,7 @@ static void __sctp_hash_established(struct sctp_association *asoc)
756746 head = & sctp_assoc_hashtable [epb -> hashent ];
757747
758748 sctp_write_lock (& head -> lock );
759- epp = & head -> chain ;
760- epb -> next = * epp ;
761- if (epb -> next )
762- (* epp )-> pprev = & epb -> next ;
763- * epp = epb ;
764- epb -> pprev = epp ;
749+ hlist_add_head (& epb -> node , & head -> chain );
765750 sctp_write_unlock (& head -> lock );
766751}
767752
@@ -790,14 +775,7 @@ static void __sctp_unhash_established(struct sctp_association *asoc)
790775 head = & sctp_assoc_hashtable [epb -> hashent ];
791776
792777 sctp_write_lock (& head -> lock );
793-
794- if (epb -> pprev ) {
795- if (epb -> next )
796- epb -> next -> pprev = epb -> pprev ;
797- * epb -> pprev = epb -> next ;
798- epb -> pprev = NULL ;
799- }
800-
778+ __hlist_del (& epb -> node );
801779 sctp_write_unlock (& head -> lock );
802780}
803781
@@ -822,6 +800,7 @@ static struct sctp_association *__sctp_lookup_association(
822800 struct sctp_ep_common * epb ;
823801 struct sctp_association * asoc ;
824802 struct sctp_transport * transport ;
803+ struct hlist_node * node ;
825804 int hash ;
826805
827806 /* Optimize here for direct hit, only listening connections can
@@ -830,7 +809,7 @@ static struct sctp_association *__sctp_lookup_association(
830809 hash = sctp_assoc_hashfn (ntohs (local -> v4 .sin_port ), ntohs (peer -> v4 .sin_port ));
831810 head = & sctp_assoc_hashtable [hash ];
832811 read_lock (& head -> lock );
833- for (epb = head -> chain ; epb ; epb = epb -> next ) {
812+ sctp_for_each_hentry (epb , node , & head -> chain ) {
834813 asoc = sctp_assoc (epb );
835814 transport = sctp_assoc_is_match (asoc , local , peer );
836815 if (transport )
0 commit comments