Improved device member initialisation. stable-1.5
authorFlorian Pose <fp@igh-essen.com>
Fri, 30 Nov 2012 12:11:28 +0100
branchstable-1.5
changeset 2451 cc852c40e299
parent 2450 c0cf0e6cff43
child 2454 5cf6bb14a579
Improved device member initialisation.
master/device.c
--- a/master/device.c	Fri Nov 30 12:09:12 2012 +0100
+++ b/master/device.c	Fri Nov 30 12:11:28 2012 +0100
@@ -72,19 +72,50 @@
     char ifname[10];
     char mb = 'x';
 #endif
+
+    device->master = master;
+    device->dev = NULL;
+    device->poll = NULL;
+    device->module = NULL;
+    device->open = 0;
+    device->link_state = 0;
+    for (i = 0; i < EC_TX_RING_SIZE; i++) {
+        device->tx_skb[i] = NULL;
+    }
+    device->tx_ring_index = 0;
+#ifdef EC_HAVE_CYCLES
+    device->cycles_poll = 0;
+#endif
+#ifdef EC_DEBUG_RING
+    device->timeval_poll.tv_sec = 0;
+    device->timeval_poll.tv_usec = 0;
+#endif
+    device->jiffies_poll = 0;
+
+    ec_device_clear_stats(device);
+
+#ifdef EC_DEBUG_RING
+    for (i = 0; i < EC_DEBUG_RING_SIZE; i++) {
+        ec_debug_frame_t *df = &device->debug_frames[i];
+        df->dir = TX;
+        df->t.tv_sec = 0;
+        df->t.tv_usec = 0;
+        memset(df->data, 0, EC_MAX_DATA_SIZE);
+        df->data_size = 0;
+    }
+#endif
 #ifdef EC_DEBUG_RING
     device->debug_frame_index = 0;
     device->debug_frame_count = 0;
 #endif
 
-    device->master = master;
-    device->tx_ring_index = 0;
-
 #ifdef EC_DEBUG_IF
-    if (device == &master->main_device)
+    if (device == &master->devices[EC_DEVICE_MAIN]) {
         mb = 'm';
-    else if (device == &master->backup_device)
+    }
+    else if (device == &master->devices[EC_DEVICE_BACKUP]) {
         mb = 'b';
+    }
 
     sprintf(ifname, "ecdbg%c%u", mb, master->index);
 
@@ -95,9 +126,6 @@
     }
 #endif
 
-    for (i = 0; i < EC_TX_RING_SIZE; i++)
-        device->tx_skb[i] = NULL;
-
     for (i = 0; i < EC_TX_RING_SIZE; i++) {
         if (!(device->tx_skb[i] = dev_alloc_skb(ETH_FRAME_LEN))) {
             EC_MASTER_ERR(master, "Error allocating device socket buffer!\n");
@@ -112,13 +140,14 @@
         memset(eth->h_dest, 0xFF, ETH_ALEN);
     }
 
-    ec_device_detach(device); // resets remaining fields
     return 0;
 
 out_tx_ring:
-    for (i = 0; i < EC_TX_RING_SIZE; i++)
-        if (device->tx_skb[i])
+    for (i = 0; i < EC_TX_RING_SIZE; i++) {
+        if (device->tx_skb[i]) {
             dev_kfree_skb(device->tx_skb[i]);
+        }
+    }
 #ifdef EC_DEBUG_IF
     ec_debug_clear(&device->dbg);
 out_return:
@@ -197,8 +226,9 @@
 
     ec_device_clear_stats(device);
 
-    for (i = 0; i < EC_TX_RING_SIZE; i++)
+    for (i = 0; i < EC_TX_RING_SIZE; i++) {
         device->tx_skb[i]->dev = NULL;
+    }
 }
 
 /*****************************************************************************/
@@ -379,10 +409,12 @@
     ec_debug_frame_t *df = &device->debug_frames[device->debug_frame_index];
 
     df->dir = dir;
-    if (dir == TX)
+    if (dir == TX) {
         do_gettimeofday(&df->t);
-    else
+    }
+    else {
         df->t = device->timeval_poll;
+    }
     memcpy(df->data, data, size);
     df->data_size = size;