master/slave.c
changeset 296 967aaacf9b20
parent 293 14aeb79aa992
child 298 d491d1f84ebc
child 1715 e675450f2174
equal deleted inserted replaced
295:934ec4051dd4 296:967aaacf9b20
   537     uint8_t *cat_data;
   537     uint8_t *cat_data;
   538     unsigned int i;
   538     unsigned int i;
   539 
   539 
   540     word_offset = 0x0040;
   540     word_offset = 0x0040;
   541 
   541 
   542     if (!(cat_data = (uint8_t *) kmalloc(0x10000, GFP_KERNEL))) {
   542     if (!(cat_data = (uint8_t *) kmalloc(0x10000, GFP_ATOMIC))) {
   543         EC_ERR("Failed to allocate 64k bytes for category data.\n");
   543         EC_ERR("Failed to allocate 64k bytes for category data.\n");
   544         return -1;
   544         return -1;
   545     }
   545     }
   546 
   546 
   547     while (1) {
   547     while (1) {
   635     offset = 1;
   635     offset = 1;
   636     for (i = 0; i < string_count; i++) {
   636     for (i = 0; i < string_count; i++) {
   637         size = data[offset];
   637         size = data[offset];
   638         // allocate memory for string structure and data at a single blow
   638         // allocate memory for string structure and data at a single blow
   639         if (!(string = (ec_eeprom_string_t *)
   639         if (!(string = (ec_eeprom_string_t *)
   640               kmalloc(sizeof(ec_eeprom_string_t) + size + 1, GFP_KERNEL))) {
   640               kmalloc(sizeof(ec_eeprom_string_t) + size + 1, GFP_ATOMIC))) {
   641             EC_ERR("Failed to allocate string memory.\n");
   641             EC_ERR("Failed to allocate string memory.\n");
   642             return -1;
   642             return -1;
   643         }
   643         }
   644         string->size = size;
   644         string->size = size;
   645         // string memory appended to string structure
   645         // string memory appended to string structure
   699 
   699 
   700     sync_count = word_count / 4; // sync manager struct is 4 words long
   700     sync_count = word_count / 4; // sync manager struct is 4 words long
   701 
   701 
   702     for (i = 0; i < sync_count; i++, data += 8) {
   702     for (i = 0; i < sync_count; i++, data += 8) {
   703         if (!(sync = (ec_eeprom_sync_t *)
   703         if (!(sync = (ec_eeprom_sync_t *)
   704               kmalloc(sizeof(ec_eeprom_sync_t), GFP_KERNEL))) {
   704               kmalloc(sizeof(ec_eeprom_sync_t), GFP_ATOMIC))) {
   705             EC_ERR("Failed to allocate Sync-Manager memory.\n");
   705             EC_ERR("Failed to allocate Sync-Manager memory.\n");
   706             return -1;
   706             return -1;
   707         }
   707         }
   708 
   708 
   709         sync->index = i;
   709         sync->index = i;
   735     ec_eeprom_pdo_entry_t *entry;
   735     ec_eeprom_pdo_entry_t *entry;
   736     unsigned int entry_count, i;
   736     unsigned int entry_count, i;
   737 
   737 
   738     while (word_count >= 4) {
   738     while (word_count >= 4) {
   739         if (!(pdo = (ec_eeprom_pdo_t *)
   739         if (!(pdo = (ec_eeprom_pdo_t *)
   740               kmalloc(sizeof(ec_eeprom_pdo_t), GFP_KERNEL))) {
   740               kmalloc(sizeof(ec_eeprom_pdo_t), GFP_ATOMIC))) {
   741             EC_ERR("Failed to allocate PDO memory.\n");
   741             EC_ERR("Failed to allocate PDO memory.\n");
   742             return -1;
   742             return -1;
   743         }
   743         }
   744 
   744 
   745         INIT_LIST_HEAD(&pdo->entries);
   745         INIT_LIST_HEAD(&pdo->entries);
   756         word_count -= 4;
   756         word_count -= 4;
   757         data += 8;
   757         data += 8;
   758 
   758 
   759         for (i = 0; i < entry_count; i++) {
   759         for (i = 0; i < entry_count; i++) {
   760             if (!(entry = (ec_eeprom_pdo_entry_t *)
   760             if (!(entry = (ec_eeprom_pdo_entry_t *)
   761                   kmalloc(sizeof(ec_eeprom_pdo_entry_t), GFP_KERNEL))) {
   761                   kmalloc(sizeof(ec_eeprom_pdo_entry_t), GFP_ATOMIC))) {
   762                 EC_ERR("Failed to allocate PDO entry memory.\n");
   762                 EC_ERR("Failed to allocate PDO entry memory.\n");
   763                 return -1;
   763                 return -1;
   764             }
   764             }
   765 
   765 
   766             entry->index = *((uint16_t *) data);
   766             entry->index = *((uint16_t *) data);
   806 
   806 
   807     // EEPROM-String mit Index finden und kopieren
   807     // EEPROM-String mit Index finden und kopieren
   808     list_for_each_entry(string, &slave->eeprom_strings, list) {
   808     list_for_each_entry(string, &slave->eeprom_strings, list) {
   809         if (--index) continue;
   809         if (--index) continue;
   810 
   810 
   811         if (!(*ptr = (char *) kmalloc(string->size + 1, GFP_KERNEL))) {
   811         if (!(*ptr = (char *) kmalloc(string->size + 1, GFP_ATOMIC))) {
   812             EC_ERR("Unable to allocate string memory.\n");
   812             EC_ERR("Unable to allocate string memory.\n");
   813             return -1;
   813             return -1;
   814         }
   814         }
   815         memcpy(*ptr, string->data, string->size + 1);
   815         memcpy(*ptr, string->data, string->size + 1);
   816         return 0;
   816         return 0;
   818 
   818 
   819     EC_WARN("String %i not found in slave %i.\n", index, slave->ring_position);
   819     EC_WARN("String %i not found in slave %i.\n", index, slave->ring_position);
   820 
   820 
   821     err_string = "(string not found)";
   821     err_string = "(string not found)";
   822 
   822 
   823     if (!(*ptr = (char *) kmalloc(strlen(err_string) + 1, GFP_KERNEL))) {
   823     if (!(*ptr = (char *) kmalloc(strlen(err_string) + 1, GFP_ATOMIC))) {
   824         EC_ERR("Unable to allocate string memory.\n");
   824         EC_ERR("Unable to allocate string memory.\n");
   825         return -1;
   825         return -1;
   826     }
   826     }
   827 
   827 
   828     memcpy(*ptr, err_string, strlen(err_string) + 1);
   828     memcpy(*ptr, err_string, strlen(err_string) + 1);