master/pdo.c
changeset 814 a51f857b1b2d
parent 799 068a58b96965
child 826 70aeae0de217
equal deleted inserted replaced
813:bfc3f1ab52de 814:a51f857b1b2d
    46 
    46 
    47 void ec_pdo_clear_entries(ec_pdo_t *);
    47 void ec_pdo_clear_entries(ec_pdo_t *);
    48 
    48 
    49 /*****************************************************************************/
    49 /*****************************************************************************/
    50 
    50 
    51 /** PDO constructor.
    51 /** Pdo constructor.
    52  */
    52  */
    53 void ec_pdo_init(
    53 void ec_pdo_init(
    54         ec_pdo_t *pdo /**< EtherCAT PDO */
    54         ec_pdo_t *pdo /**< EtherCAT Pdo */
    55         )
    55         )
    56 {
    56 {
    57     pdo->sync_index = -1; // not assigned 
    57     pdo->sync_index = -1; // not assigned 
    58     pdo->name = NULL;
    58     pdo->name = NULL;
    59     INIT_LIST_HEAD(&pdo->entries);
    59     INIT_LIST_HEAD(&pdo->entries);
    85     return -1;
    85     return -1;
    86 }
    86 }
    87 
    87 
    88 /*****************************************************************************/
    88 /*****************************************************************************/
    89 
    89 
    90 /** PDO destructor.
    90 /** Pdo destructor.
    91  */
    91  */
    92 void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT PDO */)
    92 void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT Pdo */)
    93 {
    93 {
    94     if (pdo->name)
    94     if (pdo->name)
    95         kfree(pdo->name);
    95         kfree(pdo->name);
    96 
    96 
    97     ec_pdo_clear_entries(pdo);
    97     ec_pdo_clear_entries(pdo);
    99 
    99 
   100 /*****************************************************************************/
   100 /*****************************************************************************/
   101 
   101 
   102 /** Clear Pdo entry list.
   102 /** Clear Pdo entry list.
   103  */
   103  */
   104 void ec_pdo_clear_entries(ec_pdo_t *pdo /**< EtherCAT PDO */)
   104 void ec_pdo_clear_entries(ec_pdo_t *pdo /**< EtherCAT Pdo */)
   105 {
   105 {
   106     ec_pdo_entry_t *entry, *next;
   106     ec_pdo_entry_t *entry, *next;
   107 
   107 
   108     // free all PDO entries
   108     // free all Pdo entries
   109     list_for_each_entry_safe(entry, next, &pdo->entries, list) {
   109     list_for_each_entry_safe(entry, next, &pdo->entries, list) {
   110         list_del(&entry->list);
   110         list_del(&entry->list);
   111         ec_pdo_entry_clear(entry);
   111         ec_pdo_entry_clear(entry);
   112         kfree(entry);
   112         kfree(entry);
   113     }
   113     }
   127     if (pdo->name)
   127     if (pdo->name)
   128         kfree(pdo->name);
   128         kfree(pdo->name);
   129 
   129 
   130     if (name && (len = strlen(name))) {
   130     if (name && (len = strlen(name))) {
   131         if (!(pdo->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
   131         if (!(pdo->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
   132             EC_ERR("Failed to allocate PDO name.\n");
   132             EC_ERR("Failed to allocate Pdo name.\n");
   133             return -1;
   133             return -1;
   134         }
   134         }
   135         memcpy(pdo->name, name, len + 1);
   135         memcpy(pdo->name, name, len + 1);
   136     } else {
   136     } else {
   137         pdo->name = NULL;
   137         pdo->name = NULL;
   151     ec_pdo_clear_entries(pdo);
   151     ec_pdo_clear_entries(pdo);
   152 
   152 
   153     list_for_each_entry(other_entry, &other->entries, list) {
   153     list_for_each_entry(other_entry, &other->entries, list) {
   154         if (!(entry = (ec_pdo_entry_t *)
   154         if (!(entry = (ec_pdo_entry_t *)
   155                     kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
   155                     kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
   156             EC_ERR("Failed to allocate memory for PDO entry copy.\n");
   156             EC_ERR("Failed to allocate memory for Pdo entry copy.\n");
   157             return -1;
   157             return -1;
   158         }
   158         }
   159 
   159 
   160         if (ec_pdo_entry_init_copy(entry, other_entry)) {
   160         if (ec_pdo_entry_init_copy(entry, other_entry)) {
   161             kfree(entry);
   161             kfree(entry);
   259     if (entry->name)
   259     if (entry->name)
   260         kfree(entry->name);
   260         kfree(entry->name);
   261 
   261 
   262     if (name && (len = strlen(name))) {
   262     if (name && (len = strlen(name))) {
   263         if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
   263         if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
   264             EC_ERR("Failed to allocate PDO entry name.\n");
   264             EC_ERR("Failed to allocate Pdo entry name.\n");
   265             return -1;
   265             return -1;
   266         }
   266         }
   267         memcpy(entry->name, name, len + 1);
   267         memcpy(entry->name, name, len + 1);
   268     } else {
   268     } else {
   269         entry->name = NULL;
   269         entry->name = NULL;