Added initialization of struct usbcan_message flags when receiving and transmitting...
authorJiri Vanek <vanekjir@fel.cvut.cz>
Wed, 25 Jan 2012 18:42:30 +0000 (19:42 +0100)
committerJiri Vanek <vanekjir@fel.cvut.cz>
Wed, 25 Jan 2012 18:42:30 +0000 (19:42 +0100)
lincan/include/usbcan.h
lincan/src/usbcan.c

index 35136da..5370cea 100644 (file)
@@ -133,13 +133,9 @@ struct usbcan_message {
        volatile long   flags;
 };
 
-#define USBCAN_MESSAGE_FREE                            (1)
-#define USBCAN_MESSAGE_URB_PENDING                     (2)
-#define USBCAN_MESSAGE_TERMINATE                       (3)
-#define USBCAN_MESSAGE_ERROR                           (4)
-#define USBCAN_MESSAGE_DATA_OK                         (5)
-#define USBCAN_MESSAGE_TYPE_RX                         (6)
-#define USBCAN_MESSAGE_TYPE_TX                         (7)
+#define USBCAN_MESSAGE_TERMINATE                       (1)
+#define USBCAN_MESSAGE_ERROR                           (2)
+#define USBCAN_MESSAGE_DATA_OK                         (3)
 
 /* Structure to hold all of our device specific stuff */
 struct usbcan_usb {
index f76d5c6..70e0a84 100644 (file)
@@ -751,7 +751,6 @@ void usbcan_kthread_read_handler(struct usbcan_usb *dev, struct usbcan_message *
        canque_filter_msg2edges(obj->qends, &obj->rx_msg);
 
 skip_msg:
-       set_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
        DEBUGMSG("Renewing RX urb\n");
 
        usbcan_usb_message_move_list(dev, m, &dev->rx_pend_list);
@@ -801,7 +800,6 @@ void usbcan_kthread_write_handler(struct usbcan_usb *dev, struct usbcan_message
 
 skip_msg:
        set_bit(USBCAN_FREE_TX_URB,&dev->flags);
-       set_bit(USBCAN_MESSAGE_FREE,&m->flags);
 
        set_bit(USBCAN_TX_PENDING,&dev->flags);
 
@@ -837,7 +835,6 @@ void usbcan_kthread_write_request_handler(struct usbcan_usb *dev, struct msgobj_
 
                can_msgobj_set_fl(obj,TX_PENDING);
                clear_bit(USBCAN_FREE_TX_URB,&dev->flags);
-               clear_bit(USBCAN_MESSAGE_FREE,&m->flags);
 
                *(u8 *)(m->msg)=0;
                len = m->slot->msg.length;
@@ -854,16 +851,13 @@ void usbcan_kthread_write_request_handler(struct usbcan_usb *dev, struct msgobj_
                        *ptr=0;
                }
 
-               set_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
 
                usbcan_usb_message_move_list(dev, m, &dev->tx_pend_list);
 
                retval = usb_submit_urb (m->u, GFP_KERNEL);
                if (retval){
                        CANMSG("%d. URB error %d\n",i,retval);
-                       clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                        set_bit(USBCAN_FREE_TX_URB,&dev->flags);
-                       set_bit(USBCAN_MESSAGE_FREE,&m->flags);
                        obj->ret = -1;
                        canque_notify_inends(m->qedge, CANQUEUE_NOTIFY_ERRTX_SEND);
                        canque_free_outslot(obj->qends, m->qedge, m->slot);
@@ -1073,7 +1067,6 @@ static void usbcan_tx_callback(struct urb *urb)
                set_bit(USBCAN_MESSAGE_DATA_OK,&m->flags);
                DEBUGMSG("%s > TX flag set\n", __FUNCTION__);
                set_bit(USBCAN_DATA_TX,&m->dev->flags);
-               clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                usbcan_usb_message_move_list(m->dev, m, &m->dev->tx_ready_list);
                if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags))
                        wake_up_process(m->dev->comthread);
@@ -1087,7 +1080,6 @@ static void usbcan_tx_callback(struct urb *urb)
                CANMSG("%s > Urb shutting down with status: %d\n", __FUNCTION__, urb->status);
 //             set_bit(USBCAN_TERMINATE,&m->dev->flags);
                set_bit(USBCAN_MESSAGE_TERMINATE,&m->flags);
-               clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                return;
        default:
                //CANMSG("%s > Nonzero status received: %d\n", __FUNCTION__, urb->status);
@@ -1099,7 +1091,6 @@ static void usbcan_tx_callback(struct urb *urb)
        if (retval<0){
                CANMSG("%s > Retrying urb failed with result %d\n", __FUNCTION__, retval);
                set_bit(USBCAN_ERROR,&m->dev->flags);
-               clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                usbcan_usb_message_move_list(m->dev, m, &m->dev->tx_ready_list);
                if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags))
                        wake_up_process(m->dev->comthread);
@@ -1111,7 +1102,7 @@ static void usbcan_rx_callback(struct urb *urb)
        struct usbcan_message *m = urb->context;
        int retval;
 
-       if (!test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags))
+       if (!test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags))    
                return;
        if (test_bit(USBCAN_MESSAGE_TERMINATE,&m->flags))
                return;
@@ -1124,7 +1115,6 @@ static void usbcan_rx_callback(struct urb *urb)
                set_bit(USBCAN_MESSAGE_DATA_OK,&m->flags);
                DEBUGMSG("%s > RX flag set\n", __FUNCTION__);
                set_bit(USBCAN_DATA_RX,&m->dev->flags);
-               clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                usbcan_usb_message_move_list(m->dev, m, &m->dev->rx_ready_list);
                if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags))
                        wake_up_process(m->dev->comthread);
@@ -1138,7 +1128,6 @@ static void usbcan_rx_callback(struct urb *urb)
                CANMSG("%s > Urb shutting down with status: %d\n", __FUNCTION__, urb->status);
 //             set_bit(USBCAN_TERMINATE,&m->dev->flags);
                set_bit(USBCAN_MESSAGE_TERMINATE,&m->flags);
-               clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                return;
        default:
                //CANMSG("%s > Nonzero status received: %d\n", __FUNCTION__, urb->status);
@@ -1150,7 +1139,6 @@ static void usbcan_rx_callback(struct urb *urb)
        if (retval<0){
                CANMSG("%s > Retrying urb failed with result %d\n", __FUNCTION__, retval);
                set_bit(USBCAN_ERROR,&m->dev->flags);
-               clear_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                usbcan_usb_message_move_list(m->dev, m, &m->dev->rx_ready_list);
                if (test_bit(USBCAN_THREAD_RUNNING,&m->dev->flags))
                        wake_up_process(m->dev->comthread);
@@ -1234,7 +1222,7 @@ int usbcan_kthread(void *data)
                        CANMSG("Error allocating %d. usb receive urb\n",i);
                        goto error;
                }
-               m = kmalloc(sizeof(struct usbcan_message), GFP_KERNEL);
+               m = kzalloc(sizeof(struct usbcan_message), GFP_KERNEL);
                if(!m) {
                        usb_free_urb(u);
                        CANMSG("Error allocating %d. receive usbcan_message\n",i);
@@ -1246,7 +1234,7 @@ int usbcan_kthread(void *data)
                usb_fill_bulk_urb(u, dev->udev,
                        usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
                        m->msg, USBCAN_TRANSFER_SIZE, usbcan_rx_callback, m);
-               set_bit(USBCAN_MESSAGE_TYPE_RX, &m->flags);
+
                list_add_tail(&m->list_node, &dev->rx_ready_list);
        }
 
@@ -1258,7 +1246,7 @@ int usbcan_kthread(void *data)
                        CANMSG("Error allocating %d. usb transmit urb\n",i);
                        goto error;
                }
-               m = kmalloc(sizeof(struct usbcan_message), GFP_KERNEL);
+               m = kzalloc(sizeof(struct usbcan_message), GFP_KERNEL);
                if(!m) {
                        usb_free_urb(u);
                        CANMSG("Error allocating %d. transmit usbcan_message\n",i);
@@ -1271,8 +1259,6 @@ int usbcan_kthread(void *data)
                        usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
                        m->msg, USBCAN_TRANSFER_SIZE, usbcan_tx_callback, m);
 
-               set_bit(USBCAN_MESSAGE_FREE,&m->flags);
-               set_bit(USBCAN_MESSAGE_TYPE_TX,&m->flags);
                list_add_tail(&m->list_node, &dev->tx_idle_list);
 
        }
@@ -1283,7 +1269,6 @@ int usbcan_kthread(void *data)
        for (i=0;i<USBCAN_TOT_RX_URBS;i++){
                struct usbcan_message *m;
                m = list_first_entry(&dev->rx_ready_list, typeof(*m), list_node);
-               set_bit(USBCAN_MESSAGE_URB_PENDING,&m->flags);
                usbcan_usb_message_move_list(dev, m, &dev->rx_pend_list);
 
                retval=usb_submit_urb(m->u, GFP_KERNEL);