@@ -131,17 +131,6 @@ static inline void low_nmcpy(unsigned char *dst, char *src)
131131 memcpy (& dst [8 ], src , 8 );
132132}
133133
134- static void iucv_skb_queue_purge (struct sk_buff_head * list )
135- {
136- struct sk_buff * skb ;
137-
138- while ((skb = skb_dequeue (list )) != NULL ) {
139- if (skb -> dev )
140- dev_put (skb -> dev );
141- kfree_skb (skb );
142- }
143- }
144-
145134static int afiucv_pm_prepare (struct device * dev )
146135{
147136#ifdef CONFIG_PM_DEBUG
@@ -176,7 +165,7 @@ static int afiucv_pm_freeze(struct device *dev)
176165 read_lock (& iucv_sk_list .lock );
177166 sk_for_each (sk , node , & iucv_sk_list .head ) {
178167 iucv = iucv_sk (sk );
179- iucv_skb_queue_purge (& iucv -> send_skb_q );
168+ skb_queue_purge (& iucv -> send_skb_q );
180169 skb_queue_purge (& iucv -> backlog_skb_q );
181170 switch (sk -> sk_state ) {
182171 case IUCV_DISCONN :
@@ -337,7 +326,6 @@ static void iucv_sock_wake_msglim(struct sock *sk)
337326static int afiucv_hs_send (struct iucv_message * imsg , struct sock * sock ,
338327 struct sk_buff * skb , u8 flags )
339328{
340- struct net * net = sock_net (sock );
341329 struct iucv_sock * iucv = iucv_sk (sock );
342330 struct af_iucv_trans_hdr * phs_hdr ;
343331 struct sk_buff * nskb ;
@@ -374,10 +362,10 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
374362 if (imsg )
375363 memcpy (& phs_hdr -> iucv_hdr , imsg , sizeof (struct iucv_message ));
376364
377- skb -> dev = dev_get_by_index ( net , sock -> sk_bound_dev_if ) ;
365+ skb -> dev = iucv -> hs_dev ;
378366 if (!skb -> dev )
379367 return - ENODEV ;
380- if (!(skb -> dev -> flags & IFF_UP ))
368+ if (!(skb -> dev -> flags & IFF_UP ) || ! netif_carrier_ok ( skb -> dev ) )
381369 return - ENETDOWN ;
382370 if (skb -> len > skb -> dev -> mtu ) {
383371 if (sock -> sk_type == SOCK_SEQPACKET )
@@ -392,15 +380,14 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
392380 return - ENOMEM ;
393381 skb_queue_tail (& iucv -> send_skb_q , nskb );
394382 err = dev_queue_xmit (skb );
395- if (err ) {
383+ if (net_xmit_eval ( err ) ) {
396384 skb_unlink (nskb , & iucv -> send_skb_q );
397- dev_put (nskb -> dev );
398385 kfree_skb (nskb );
399386 } else {
400387 atomic_sub (confirm_recv , & iucv -> msg_recv );
401388 WARN_ON (atomic_read (& iucv -> msg_recv ) < 0 );
402389 }
403- return err ;
390+ return net_xmit_eval ( err ) ;
404391}
405392
406393static struct sock * __iucv_get_sock_by_name (char * nm )
@@ -471,7 +458,8 @@ static void iucv_sock_close(struct sock *sk)
471458{
472459 struct iucv_sock * iucv = iucv_sk (sk );
473460 unsigned long timeo ;
474- int err , blen ;
461+ int err = 0 ;
462+ int blen ;
475463 struct sk_buff * skb ;
476464
477465 lock_sock (sk );
@@ -498,7 +486,7 @@ static void iucv_sock_close(struct sock *sk)
498486 sk -> sk_state = IUCV_CLOSING ;
499487 sk -> sk_state_change (sk );
500488
501- if (!skb_queue_empty (& iucv -> send_skb_q )) {
489+ if (!err && ! skb_queue_empty (& iucv -> send_skb_q )) {
502490 if (sock_flag (sk , SOCK_LINGER ) && sk -> sk_lingertime )
503491 timeo = sk -> sk_lingertime ;
504492 else
@@ -515,13 +503,19 @@ static void iucv_sock_close(struct sock *sk)
515503 sk -> sk_err = ECONNRESET ;
516504 sk -> sk_state_change (sk );
517505
518- iucv_skb_queue_purge (& iucv -> send_skb_q );
506+ skb_queue_purge (& iucv -> send_skb_q );
519507 skb_queue_purge (& iucv -> backlog_skb_q );
520508
521509 default : /* fall through */
522510 iucv_sever_path (sk , 1 );
523511 }
524512
513+ if (iucv -> hs_dev ) {
514+ dev_put (iucv -> hs_dev );
515+ iucv -> hs_dev = NULL ;
516+ sk -> sk_bound_dev_if = 0 ;
517+ }
518+
525519 /* mark socket for deletion by iucv_sock_kill() */
526520 sock_set_flag (sk , SOCK_ZAPPED );
527521
@@ -713,7 +707,6 @@ static int iucv_sock_bind(struct socket *sock, struct sockaddr *addr,
713707 goto done_unlock ;
714708
715709 /* Bind the socket */
716-
717710 if (pr_iucv )
718711 if (!memcmp (sa -> siucv_user_id , iucv_userid , 8 ))
719712 goto vm_bind ; /* VM IUCV transport */
@@ -727,6 +720,8 @@ static int iucv_sock_bind(struct socket *sock, struct sockaddr *addr,
727720 memcpy (iucv -> src_name , sa -> siucv_name , 8 );
728721 memcpy (iucv -> src_user_id , sa -> siucv_user_id , 8 );
729722 sk -> sk_bound_dev_if = dev -> ifindex ;
723+ iucv -> hs_dev = dev ;
724+ dev_hold (dev );
730725 sk -> sk_state = IUCV_BOUND ;
731726 iucv -> transport = AF_IUCV_TRANS_HIPER ;
732727 if (!iucv -> msglimit )
@@ -1128,8 +1123,10 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
11281123 noblock , & err );
11291124 else
11301125 skb = sock_alloc_send_skb (sk , len , noblock , & err );
1131- if (!skb )
1126+ if (!skb ) {
1127+ err = - ENOMEM ;
11321128 goto out ;
1129+ }
11331130 if (iucv -> transport == AF_IUCV_TRANS_HIPER )
11341131 skb_reserve (skb , sizeof (struct af_iucv_trans_hdr ) + ETH_HLEN );
11351132 if (memcpy_fromiovec (skb_put (skb , len ), msg -> msg_iov , len )) {
@@ -1152,6 +1149,7 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
11521149 /* increment and save iucv message tag for msg_completion cbk */
11531150 txmsg .tag = iucv -> send_tag ++ ;
11541151 memcpy (CB_TAG (skb ), & txmsg .tag , CB_TAG_LEN );
1152+
11551153 if (iucv -> transport == AF_IUCV_TRANS_HIPER ) {
11561154 atomic_inc (& iucv -> msg_sent );
11571155 err = afiucv_hs_send (& txmsg , sk , skb , 0 );
@@ -1206,8 +1204,6 @@ static int iucv_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
12061204 return len ;
12071205
12081206fail :
1209- if (skb -> dev )
1210- dev_put (skb -> dev );
12111207 kfree_skb (skb );
12121208out :
12131209 release_sock (sk );
@@ -1400,7 +1396,14 @@ static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
14001396 }
14011397
14021398 kfree_skb (skb );
1403- atomic_inc (& iucv -> msg_recv );
1399+ if (iucv -> transport == AF_IUCV_TRANS_HIPER ) {
1400+ atomic_inc (& iucv -> msg_recv );
1401+ if (atomic_read (& iucv -> msg_recv ) > iucv -> msglimit ) {
1402+ WARN_ON (1 );
1403+ iucv_sock_close (sk );
1404+ return - EFAULT ;
1405+ }
1406+ }
14041407
14051408 /* Queue backlog skbs */
14061409 spin_lock_bh (& iucv -> message_q .lock );
@@ -1957,6 +1960,8 @@ static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
19571960 memcpy (niucv -> src_name , iucv -> src_name , 8 );
19581961 memcpy (niucv -> src_user_id , iucv -> src_user_id , 8 );
19591962 nsk -> sk_bound_dev_if = sk -> sk_bound_dev_if ;
1963+ niucv -> hs_dev = iucv -> hs_dev ;
1964+ dev_hold (niucv -> hs_dev );
19601965 afiucv_swap_src_dest (skb );
19611966 trans_hdr -> flags = AF_IUCV_FLAG_SYN | AF_IUCV_FLAG_ACK ;
19621967 trans_hdr -> window = niucv -> msglimit ;
@@ -2025,12 +2030,15 @@ static int afiucv_hs_callback_fin(struct sock *sk, struct sk_buff *skb)
20252030 struct iucv_sock * iucv = iucv_sk (sk );
20262031
20272032 /* other end of connection closed */
2028- if (iucv ) {
2029- bh_lock_sock (sk );
2033+ if (!iucv )
2034+ goto out ;
2035+ bh_lock_sock (sk );
2036+ if (sk -> sk_state == IUCV_CONNECTED ) {
20302037 sk -> sk_state = IUCV_DISCONN ;
20312038 sk -> sk_state_change (sk );
2032- bh_unlock_sock (sk );
20332039 }
2040+ bh_unlock_sock (sk );
2041+ out :
20342042 kfree_skb (skb );
20352043 return NET_RX_SUCCESS ;
20362044}
@@ -2175,11 +2183,11 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
21752183 break ;
21762184 case (AF_IUCV_FLAG_WIN ):
21772185 err = afiucv_hs_callback_win (sk , skb );
2178- if (skb -> len > sizeof (struct af_iucv_trans_hdr ))
2179- err = afiucv_hs_callback_rx ( sk , skb );
2180- else
2181- kfree ( skb );
2182- break ;
2186+ if (skb -> len == sizeof (struct af_iucv_trans_hdr )) {
2187+ kfree_skb ( skb );
2188+ break ;
2189+ }
2190+ /* fall through */
21832191 case 0 :
21842192 /* plain data frame */
21852193 memcpy (CB_TRGCLS (skb ), & trans_hdr -> iucv_hdr .class ,
@@ -2205,65 +2213,64 @@ static void afiucv_hs_callback_txnotify(struct sk_buff *skb,
22052213 struct iucv_sock * iucv = NULL ;
22062214 struct sk_buff_head * list ;
22072215 struct sk_buff * list_skb ;
2208- struct sk_buff * this = NULL ;
2216+ struct sk_buff * nskb ;
22092217 unsigned long flags ;
22102218 struct hlist_node * node ;
22112219
2212- read_lock (& iucv_sk_list .lock );
2220+ read_lock_irqsave (& iucv_sk_list .lock , flags );
22132221 sk_for_each (sk , node , & iucv_sk_list .head )
22142222 if (sk == isk ) {
22152223 iucv = iucv_sk (sk );
22162224 break ;
22172225 }
2218- read_unlock (& iucv_sk_list .lock );
2226+ read_unlock_irqrestore (& iucv_sk_list .lock , flags );
22192227
2220- if (!iucv )
2228+ if (!iucv || sock_flag ( sk , SOCK_ZAPPED ) )
22212229 return ;
22222230
2223- bh_lock_sock (sk );
22242231 list = & iucv -> send_skb_q ;
2225- list_skb = list -> next ;
2232+ spin_lock_irqsave ( & list -> lock , flags ) ;
22262233 if (skb_queue_empty (list ))
22272234 goto out_unlock ;
2228-
2229- spin_lock_irqsave ( & list -> lock , flags ) ;
2235+ list_skb = list -> next ;
2236+ nskb = list_skb -> next ;
22302237 while (list_skb != (struct sk_buff * )list ) {
22312238 if (skb_shinfo (list_skb ) == skb_shinfo (skb )) {
2232- this = list_skb ;
22332239 switch (n ) {
22342240 case TX_NOTIFY_OK :
2235- __skb_unlink (this , list );
2241+ __skb_unlink (list_skb , list );
2242+ kfree_skb (list_skb );
22362243 iucv_sock_wake_msglim (sk );
2237- dev_put (this -> dev );
2238- kfree_skb (this );
22392244 break ;
22402245 case TX_NOTIFY_PENDING :
22412246 atomic_inc (& iucv -> pendings );
22422247 break ;
22432248 case TX_NOTIFY_DELAYED_OK :
2244- __skb_unlink (this , list );
2249+ __skb_unlink (list_skb , list );
22452250 atomic_dec (& iucv -> pendings );
22462251 if (atomic_read (& iucv -> pendings ) <= 0 )
22472252 iucv_sock_wake_msglim (sk );
2248- dev_put (this -> dev );
2249- kfree_skb (this );
2253+ kfree_skb (list_skb );
22502254 break ;
22512255 case TX_NOTIFY_UNREACHABLE :
22522256 case TX_NOTIFY_DELAYED_UNREACHABLE :
22532257 case TX_NOTIFY_TPQFULL : /* not yet used */
22542258 case TX_NOTIFY_GENERALERROR :
22552259 case TX_NOTIFY_DELAYED_GENERALERROR :
2256- __skb_unlink (this , list );
2257- dev_put (this -> dev );
2258- kfree_skb (this );
2259- sk -> sk_state = IUCV_DISCONN ;
2260- sk -> sk_state_change (sk );
2260+ __skb_unlink (list_skb , list );
2261+ kfree_skb (list_skb );
2262+ if (sk -> sk_state == IUCV_CONNECTED ) {
2263+ sk -> sk_state = IUCV_DISCONN ;
2264+ sk -> sk_state_change (sk );
2265+ }
22612266 break ;
22622267 }
22632268 break ;
22642269 }
2265- list_skb = list_skb -> next ;
2270+ list_skb = nskb ;
2271+ nskb = nskb -> next ;
22662272 }
2273+ out_unlock :
22672274 spin_unlock_irqrestore (& list -> lock , flags );
22682275
22692276 if (sk -> sk_state == IUCV_CLOSING ) {
@@ -2273,8 +2280,6 @@ static void afiucv_hs_callback_txnotify(struct sk_buff *skb,
22732280 }
22742281 }
22752282
2276- out_unlock :
2277- bh_unlock_sock (sk );
22782283}
22792284static const struct proto_ops iucv_sock_ops = {
22802285 .family = PF_IUCV ,
0 commit comments