Correction of spinlock acquire order.
[lincan.git] / lincan / src / can_queue.c
index dfdafbb..a75bb46 100644 (file)
@@ -97,6 +97,11 @@ int canque_fifo_init_slots(struct canque_fifo_t *fifo)
  list_entry(ptr, type, member)
 */
 
+void __canque_edge_decref(struct canque_edge_t *edge)
+{
+       __canque_edge_decref_body(edge);
+}
+
 /**
  * canque_get_inslot - finds one outgoing edge and allocates slot from it
  * @qends: ends structure belonging to calling communication object
@@ -519,8 +524,7 @@ int canqueue_connect_edge(struct canque_edge_t *qedge, struct canque_ends_t *ine
        if(qedge == NULL) return -1;
        DEBUGQUE("canqueue_connect_edge %d\n",qedge->edge_num);
        canque_edge_incref(qedge);
-       can_spin_lock_irqsave(&inends->ends_lock, flags);
-       can_spin_lock(&outends->ends_lock);
+       flags=canque_edge_lock_both_ends(qedge);
        can_spin_lock(&qedge->fifo.fifo_lock);
        qedge->inends=inends;
        list_add(&qedge->inpeers,&inends->inlist);
@@ -528,8 +532,7 @@ int canqueue_connect_edge(struct canque_edge_t *qedge, struct canque_ends_t *ine
        list_add(&qedge->outpeers,&outends->outlist);
        list_add(&qedge->activepeers,&outends->idle);
        can_spin_unlock(&qedge->fifo.fifo_lock);
-       can_spin_unlock(&outends->ends_lock);
-       can_spin_unlock_irqrestore(&inends->ends_lock, flags);
+       canque_edge_unlock_both_ends(qedge, flags);
        canque_notify_bothends(qedge, CANQUEUE_NOTIFY_ATTACH);
 
        if(canque_fifo_test_and_set_fl(&qedge->fifo, READY))
@@ -551,9 +554,17 @@ int canqueue_disconnect_edge(struct canque_edge_t *qedge)
        struct canque_ends_t *inends, *outends;
 
        inends=qedge->inends;
-       if(inends) can_spin_lock_irqsave(&inends->ends_lock,flags);
        outends=qedge->outends;
-       if(outends) can_spin_lock(&outends->ends_lock);
+
+       if(inends && outends) {
+               flags=canque_edge_lock_both_ends(qedge);
+       } else {
+               DEBUGQUE("canqueue_disconnect_edge called with not fully connected edge");
+               if(inends) can_spin_lock_irqsave(&inends->ends_lock,flags);
+               if(outends) can_spin_lock(&outends->ends_lock);
+               flags=0;
+       }
+       
        can_spin_lock(&qedge->fifo.fifo_lock);
        if(atomic_read(&qedge->edge_used)==0) {
                if(qedge->outends){
@@ -569,8 +580,14 @@ int canqueue_disconnect_edge(struct canque_edge_t *qedge)
                ret=1;
        } else ret=-1;
        can_spin_unlock(&qedge->fifo.fifo_lock);
-       if(outends) can_spin_unlock(&outends->ends_lock);
-       if(inends) can_spin_unlock_irqrestore(&inends->ends_lock,flags);
+
+       if(inends && outends) {
+               canque_edge_unlock_both_ends(qedge, flags);
+       } else {
+               if(outends) can_spin_unlock(&outends->ends_lock);
+               if(inends) can_spin_unlock_irqrestore(&inends->ends_lock,flags);
+       }
+
        DEBUGQUE("canqueue_disconnect_edge %d returned %d\n",qedge->edge_num,ret);
        return ret;
 }