[IrDA]: Fix Rx/Tx path race.
authorG. Liakhovetski <gl@dsa-ac.de>
Sat, 9 Jun 2007 02:15:17 +0000 (19:15 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 9 Jun 2007 02:15:17 +0000 (19:15 -0700)
From: G. Liakhovetski <gl@dsa-ac.de>

We need to switch to NRM _before_ sending the final packet otherwise
we might hit a race condition where we get the first packet from the
peer while we're still in LAP_XMIT_P.

Signed-off-by: Samuel Ortiz <samuel@sortiz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/irda/irlap.h
net/irda/irlap_event.c
net/irda/irlap_frame.c

index f0248fb8e196f0c5b4cd669cefe34f536d374bf9..a3d370efb9034b55ea7b31bd5772928a06411151 100644 (file)
@@ -289,4 +289,21 @@ static inline void irlap_clear_disconnect(struct irlap_cb *self)
        self->disconnect_pending = FALSE;
 }
 
+/*
+ * Function irlap_next_state (self, state)
+ *
+ *    Switches state and provides debug information
+ *
+ */
+static inline void irlap_next_state(struct irlap_cb *self, IRLAP_STATE state)
+{
+       /*
+       if (!self || self->magic != LAP_MAGIC)
+               return;
+
+       IRDA_DEBUG(4, "next LAP state = %s\n", irlap_state[state]);
+       */
+       self->state = state;
+}
+
 #endif
index 0b02073ffdf306b6895ce36513db54dbf439cb9d..71c805506933cbf200ac8c1a5a7bbbd5af4c46c6 100644 (file)
@@ -316,23 +316,6 @@ void irlap_do_event(struct irlap_cb *self, IRLAP_EVENT event,
        }
 }
 
-/*
- * Function irlap_next_state (self, state)
- *
- *    Switches state and provides debug information
- *
- */
-static inline void irlap_next_state(struct irlap_cb *self, IRLAP_STATE state)
-{
-       /*
-       if (!self || self->magic != LAP_MAGIC)
-               return;
-
-       IRDA_DEBUG(4, "next LAP state = %s\n", irlap_state[state]);
-       */
-       self->state = state;
-}
-
 /*
  * Function irlap_state_ndm (event, skb, frame)
  *
@@ -1086,7 +1069,6 @@ static int irlap_state_xmit_p(struct irlap_cb *self, IRLAP_EVENT event,
                        } else {
                                /* Final packet of window */
                                irlap_send_data_primary_poll(self, skb);
-                               irlap_next_state(self, LAP_NRM_P);
 
                                /*
                                 * Make sure state machine does not try to send
index 3c5a68e36414f98a2cc9aad8340f250022e827fe..3013c49ab975e865b593746911f0d88f2921c8b0 100644 (file)
@@ -798,16 +798,19 @@ void irlap_send_data_primary_poll(struct irlap_cb *self, struct sk_buff *skb)
                self->vs = (self->vs + 1) % 8;
                self->ack_required = FALSE;
 
+               irlap_next_state(self, LAP_NRM_P);
                irlap_send_i_frame(self, tx_skb, CMD_FRAME);
        } else {
                IRDA_DEBUG(4, "%s(), sending unreliable frame\n", __FUNCTION__);
 
                if (self->ack_required) {
                        irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
+                       irlap_next_state(self, LAP_NRM_P);
                        irlap_send_rr_frame(self, CMD_FRAME);
                        self->ack_required = FALSE;
                } else {
                        skb->data[1] |= PF_BIT;
+                       irlap_next_state(self, LAP_NRM_P);
                        irlap_send_ui_frame(self, skb_get(skb), self->caddr, CMD_FRAME);
                }
        }