master/master.c
changeset 659 d7c5a958bad0
parent 656 370aa8c2d1b1
child 661 bc1de1362efb
equal deleted inserted replaced
658:898b6f6bfb50 659:d7c5a958bad0
   103         unsigned int index, /**< master index */
   103         unsigned int index, /**< master index */
   104         const uint8_t *main_mac, /**< MAC address of main device */
   104         const uint8_t *main_mac, /**< MAC address of main device */
   105         const uint8_t *backup_mac /**< MAC address of backup device */
   105         const uint8_t *backup_mac /**< MAC address of backup device */
   106         )
   106         )
   107 {
   107 {
   108     ec_eoe_t *eoe, *next_eoe;
       
   109     unsigned int i;
   108     unsigned int i;
   110 
   109 
   111     master->index = index;
   110     master->index = index;
   112     master->reserved = 0;
   111     master->reserved = 0;
   113 
   112 
   180 
   179 
   181     // init state machine datagram
   180     // init state machine datagram
   182     ec_datagram_init(&master->fsm_datagram);
   181     ec_datagram_init(&master->fsm_datagram);
   183     if (ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE)) {
   182     if (ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE)) {
   184         EC_ERR("Failed to allocate FSM datagram.\n");
   183         EC_ERR("Failed to allocate FSM datagram.\n");
   185         goto out_clear_eoe;
   184         goto out_clear_backup;
   186     }
   185     }
   187 
   186 
   188     // create state machine object
   187     // create state machine object
   189     ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram);
   188     ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram);
   190 
   189 
   195     master->kobj.parent = module_kobj;
   194     master->kobj.parent = module_kobj;
   196     
   195     
   197     if (kobject_set_name(&master->kobj, "master%i", index)) {
   196     if (kobject_set_name(&master->kobj, "master%i", index)) {
   198         EC_ERR("Failed to set master kobject name.\n");
   197         EC_ERR("Failed to set master kobject name.\n");
   199         kobject_put(&master->kobj);
   198         kobject_put(&master->kobj);
   200         return -1;
   199         goto out_clear_fsm;
   201     }
   200     }
   202     
   201     
   203     if (kobject_add(&master->kobj)) {
   202     if (kobject_add(&master->kobj)) {
   204         EC_ERR("Failed to add master kobject.\n");
   203         EC_ERR("Failed to add master kobject.\n");
   205         kobject_put(&master->kobj);
   204         kobject_put(&master->kobj);
   206         return -1;
   205         goto out_clear_fsm;
   207     }
   206     }
   208 
   207 
   209     return 0;
   208     return 0;
   210 
   209 
   211 out_clear_eoe:
   210 out_clear_fsm:
   212     list_for_each_entry_safe(eoe, next_eoe, &master->eoe_handlers, list) {
   211     ec_fsm_master_clear(&master->fsm);
   213         list_del(&eoe->list);
   212 out_clear_backup:
   214         ec_eoe_clear(eoe);
       
   215         kfree(eoe);
       
   216     }
       
   217     ec_device_clear(&master->backup_device);
   213     ec_device_clear(&master->backup_device);
   218 out_clear_main:
   214 out_clear_main:
   219     ec_device_clear(&master->main_device);
   215     ec_device_clear(&master->main_device);
   220 out_return:
   216 out_return:
   221     return -1;
   217     return -1;