kobject_add() in constructors.
authorFlorian Pose <fp@igh-essen.com>
Mon, 06 Nov 2006 14:22:35 +0000
changeset 484 9fde4a17b820
parent 483 1a507e9ab735
child 485 8354ddf38481
kobject_add() in constructors.
TODO
master/canopen.c
master/domain.c
master/fsm.c
master/fsm_coe.c
master/master.c
master/module.c
master/slave.c
--- a/TODO	Mon Nov 06 14:21:35 2006 +0000
+++ b/TODO	Mon Nov 06 14:22:35 2006 +0000
@@ -8,33 +8,19 @@
 
 Important things to do:
 
-* Add Kobjects in constructors.
-
 * Read AL Status Code with AL Control Response (if possible?)
-
 * Coupling of EoE handlers before configuring slaves.
   (avoiding duplicate configuration)
-
-* SysFS interface
-  - Add secondary slave address
-  - Add SDO dictionary
-
 * Implement all EtherCAT commands
-
 * Determine number of frames the NIC can handle
-
-* Implement eepro100 driver
-
-* Progress bar in ecrt.
+* Implement e100 driver
 
 -------------------------------------------------------------------------------
 
 Not-so-important things to do:
 
 * Calculate bus topology
-
 * File access over EtherCAT (FoE)
-
 * Allow VLAN tagging
 
 -------------------------------------------------------------------------------
--- a/master/canopen.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/canopen.c	Mon Nov 06 14:22:35 2006 +0000
@@ -122,6 +122,12 @@
     sdo->kobj.parent = &slave->sdo_kobj;
     if (kobject_set_name(&sdo->kobj, "%4X", sdo->index)) {
         EC_ERR("Failed to set kobj name.\n");
+        kobject_put(&sdo->kobj);
+        return -1;
+    }
+    if (kobject_add(&sdo->kobj)) {
+        EC_ERR("Failed to add SDO kobject.\n");
+        kobject_put(&sdo->kobj);
         return -1;
     }
 
@@ -222,6 +228,12 @@
     entry->kobj.parent = &sdo->kobj;
     if (kobject_set_name(&entry->kobj, "%i", entry->subindex)) {
         EC_ERR("Failed to set kobj name.\n");
+        kobject_put(&entry->kobj);
+        return -1;
+    }
+    if (kobject_add(&entry->kobj)) {
+        EC_ERR("Failed to add entry kobject.\n");
+        kobject_put(&entry->kobj);
         return -1;
     }
 
--- a/master/domain.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/domain.c	Mon Nov 06 14:22:35 2006 +0000
@@ -120,6 +120,12 @@
     domain->kobj.parent = &master->kobj;
     if (kobject_set_name(&domain->kobj, "domain%i", index)) {
         EC_ERR("Failed to set kobj name.\n");
+        kobject_put(&domain->kobj);
+        return -1;
+    }
+    if (kobject_add(&domain->kobj)) {
+        EC_ERR("Failed to add domain kobject.\n");
+        kobject_put(&domain->kobj);
         return -1;
     }
 
--- a/master/fsm.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/fsm.c	Mon Nov 06 14:22:35 2006 +0000
@@ -275,14 +275,6 @@
                 return;
             }
 
-            if (kobject_add(&slave->kobj)) {
-                EC_ERR("Failed to add kobject.\n");
-                kobject_put(&slave->kobj); // free
-                ec_master_destroy_slaves(master);
-                fsm->master_state = ec_fsm_master_error;
-                return;
-            }
-
             list_add_tail(&slave->list, &master->slaves);
         }
 
@@ -388,14 +380,6 @@
                        slave->ring_position);
             }
 
-            if (kobject_add(&slave->sdo_kobj)) {
-                EC_ERR("Failed to add SDO kobj of slave %i.\n",
-                       slave->ring_position);
-                slave->error_flag = 1;
-                fsm->master_state = ec_fsm_master_error;
-                return;
-            }
-
             slave->sdo_dictionary_fetched = 1;
 
             // start fetching SDO dictionary
--- a/master/fsm_coe.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/fsm_coe.c	Mon Nov 06 14:22:35 2006 +0000
@@ -413,13 +413,6 @@
             return;
         }
 
-        if (kobject_add(&sdo->kobj)) {
-            EC_ERR("Failed to add kobject.\n");
-            kobject_put(&sdo->kobj); // free
-            fsm->state = ec_fsm_coe_error;
-            return;
-        }
-
         list_add_tail(&sdo->list, &slave->sdo_dictionary);
     }
 
@@ -776,20 +769,15 @@
     entry->bit_length = EC_READ_U16(data + 12);
 
     if (data_size) {
-        if (!(entry->description = kmalloc(data_size + 1, GFP_ATOMIC))) {
+        uint8_t *desc;
+        if (!(desc = kmalloc(data_size + 1, GFP_ATOMIC))) {
             EC_ERR("Failed to allocate SDO entry name!\n");
             fsm->state = ec_fsm_coe_error;
             return;
         }
-        memcpy(entry->description, data + 16, data_size);
-        entry->description[data_size] = 0;
-    }
-
-    if (kobject_add(&entry->kobj)) {
-        EC_ERR("Failed to add kobject.\n");
-        kobject_put(&entry->kobj); // free
-        fsm->state = ec_fsm_coe_error;
-        return;
+        memcpy(desc, data + 16, data_size);
+        desc[data_size] = 0;
+        entry->description = desc;
     }
 
     list_add_tail(&entry->list, &sdo->entries);
--- a/master/master.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/master.c	Mon Nov 06 14:22:35 2006 +0000
@@ -203,6 +203,11 @@
         kobject_put(&master->kobj);
         return -1;
     }
+    if (kobject_add(&master->kobj)) {
+        EC_ERR("Failed to add master kobj.\n");
+        kobject_put(&master->kobj);
+        return -1;
+    }
 
     return 0;
 
@@ -1271,7 +1276,7 @@
 
     if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
         EC_ERR("Error allocating domain memory!\n");
-        goto out_return;
+        return NULL;
     }
 
     if (list_empty(&master->domains)) index = 0;
@@ -1282,21 +1287,12 @@
 
     if (ec_domain_init(domain, master, index)) {
         EC_ERR("Failed to init domain.\n");
-        goto out_return;
-    }
-
-    if (kobject_add(&domain->kobj)) {
-        EC_ERR("Failed to add domain kobject.\n");
-        goto out_put;
+        return NULL;
     }
 
     list_add_tail(&domain->list, &master->domains);
+
     return domain;
-
- out_put:
-    kobject_put(&domain->kobj);
- out_return:
-    return NULL;
 }
 
 /*****************************************************************************/
--- a/master/module.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/module.c	Mon Nov 06 14:22:35 2006 +0000
@@ -115,12 +115,6 @@
         if (ec_master_init(master, i, ec_eoeif_count, device_number))
             goto out_free;
 
-        if (kobject_add(&master->kobj)) {
-            EC_ERR("Failed to add kobj.\n");
-            kobject_put(&master->kobj); // free master
-            goto out_free;
-        }
-
         list_add_tail(&master->list, &ec_masters);
     }
 
--- a/master/slave.c	Mon Nov 06 14:21:35 2006 +0000
+++ b/master/slave.c	Mon Nov 06 14:22:35 2006 +0000
@@ -108,29 +108,6 @@
     slave->ring_position = ring_position;
     slave->station_address = station_address;
 
-    // init kobject and add it to the hierarchy
-    memset(&slave->kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&slave->kobj);
-    slave->kobj.ktype = &ktype_ec_slave;
-    slave->kobj.parent = &master->kobj;
-    if (kobject_set_name(&slave->kobj, "slave%03i", slave->ring_position)) {
-        EC_ERR("Failed to set kobject name.\n");
-        kobject_put(&slave->kobj);
-        return -1;
-    }
-
-    // init SDO kobject and add it to the hierarchy
-    memset(&slave->sdo_kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&slave->sdo_kobj);
-    slave->sdo_kobj.ktype = &ktype_ec_slave_sdos;
-    slave->sdo_kobj.parent = &slave->kobj;
-    if (kobject_set_name(&slave->sdo_kobj, "sdos")) {
-        EC_ERR("Failed to set kobject name.\n");
-        kobject_put(&slave->sdo_kobj);
-        kobject_put(&slave->kobj);
-        return -1;
-    }
-
     slave->master = master;
 
     slave->requested_state = EC_SLAVE_STATE_UNKNOWN;
@@ -185,7 +162,42 @@
         slave->sii_physical_layer[i] = 0xFF;
     }
 
+    // init kobject and add it to the hierarchy
+    memset(&slave->kobj, 0x00, sizeof(struct kobject));
+    kobject_init(&slave->kobj);
+    slave->kobj.ktype = &ktype_ec_slave;
+    slave->kobj.parent = &master->kobj;
+    if (kobject_set_name(&slave->kobj, "slave%03i", slave->ring_position)) {
+        EC_ERR("Failed to set kobject name.\n");
+        goto out_slave_put;
+    }
+    if (kobject_add(&slave->kobj)) {
+        EC_ERR("Failed to add slave's kobject.\n");
+        goto out_slave_put;
+    }
+
+    // init SDO kobject and add it to the hierarchy
+    memset(&slave->sdo_kobj, 0x00, sizeof(struct kobject));
+    kobject_init(&slave->sdo_kobj);
+    slave->sdo_kobj.ktype = &ktype_ec_slave_sdos;
+    slave->sdo_kobj.parent = &slave->kobj;
+    if (kobject_set_name(&slave->sdo_kobj, "sdos")) {
+        EC_ERR("Failed to set kobject name.\n");
+        goto out_sdo_put;
+    }
+    if (kobject_add(&slave->sdo_kobj)) {
+        EC_ERR("Failed to add SDOs kobject.\n");
+        goto out_sdo_put;
+    }
+
     return 0;
+
+ out_sdo_put:
+    kobject_put(&slave->sdo_kobj);
+    kobject_del(&slave->kobj);
+ out_slave_put:
+    kobject_put(&slave->kobj);
+    return -1;
 }
 
 /*****************************************************************************/
@@ -206,7 +218,7 @@
     }
 
     // free SDO kobject
-    if (slave->sdo_dictionary_fetched) kobject_del(&slave->sdo_kobj);
+    kobject_del(&slave->sdo_kobj);
     kobject_put(&slave->sdo_kobj);
 
     // destroy self