# HG changeset patch # User Florian Pose # Date 1143189346 0 # Node ID e67c80a76de47a9d4cb6f39cfbd77e3d3b4b38e2 # Parent bbc963b9fead44cbc8e5d0a39d6496534d83fb41 Code aufger?umt und kleines Speicherleck entdeckt. diff -r bbc963b9fead -r e67c80a76de4 master/module.c --- a/master/module.c Wed Mar 22 11:42:44 2006 +0000 +++ b/master/module.c Fri Mar 24 08:35:46 2006 +0000 @@ -75,24 +75,22 @@ if (ec_master_count < 1) { EC_ERR("Error - Invalid ec_master_count: %i\n", ec_master_count); - return -1; + goto out_return; } EC_INFO("Initializing %i EtherCAT master(s)...\n", ec_master_count); - if ((ec_masters = (ec_master_t *) kmalloc(sizeof(ec_master_t) - * ec_master_count, - GFP_KERNEL)) == NULL) { + if (!(ec_masters = (ec_master_t *) + kmalloc(sizeof(ec_master_t) * ec_master_count, GFP_KERNEL))) { EC_ERR("Could not allocate memory for EtherCAT master(s)!\n"); - return -1; - } - - if ((ec_masters_reserved = - (unsigned int *) kmalloc(sizeof(int) * ec_master_count, - GFP_KERNEL)) == NULL) { + goto out_return; + } + + if (!(ec_masters_reserved = + (unsigned int *) kmalloc(sizeof(int) * ec_master_count, + GFP_KERNEL))) { EC_ERR("Could not allocate memory for reservation flags!\n"); - kfree(ec_masters); - return -1; + goto out_free_masters; } for (i = 0; i < ec_master_count; i++) { @@ -101,8 +99,12 @@ } EC_INFO("Master driver initialized.\n"); - return 0; + + out_free_masters: + kfree(ec_masters); + out_return: + return -1; } /*****************************************************************************/ @@ -119,15 +121,14 @@ EC_INFO("Cleaning up master driver...\n"); - if (ec_masters) { - for (i = 0; i < ec_master_count; i++) { - if (ec_masters_reserved[i]) { - EC_WARN("Master %i is still in use!\n", i); - } - ec_master_clear(&ec_masters[i]); - } - kfree(ec_masters); - } + for (i = 0; i < ec_master_count; i++) { + if (ec_masters_reserved[i]) + EC_WARN("Master %i is still in use!\n", i); + ec_master_clear(&ec_masters[i]); + } + + kfree(ec_masters); + kfree(ec_masters_reserved); EC_INFO("Master driver cleaned up.\n"); } @@ -174,14 +175,17 @@ return NULL; } - if (!(master->device = (ec_device_t *) kmalloc(sizeof(ec_device_t), - GFP_KERNEL))) { + if (!(master->device = (ec_device_t *) + kmalloc(sizeof(ec_device_t), GFP_KERNEL))) { EC_ERR("Failed allocating device!\n"); return NULL; } - if (ec_device_init(master->device, master, net_dev, isr, module)) - return NULL; + if (ec_device_init(master->device, master, net_dev, isr, module)) { + kfree(master->device); + master->device = NULL; + return NULL; + } return master->device; } diff -r bbc963b9fead -r e67c80a76de4 master/slave.c --- a/master/slave.c Wed Mar 22 11:42:44 2006 +0000 +++ b/master/slave.c Fri Mar 24 08:35:46 2006 +0000 @@ -329,8 +329,6 @@ word_offset = 0x0040; - //EC_DBG("Slave %i...\n", slave->ring_position); - if (!(cat_data = (uint8_t *) kmalloc(0x10000, GFP_KERNEL))) { EC_ERR("Failed to allocate 64k bytes for category data.\n"); return -1; @@ -482,8 +480,8 @@ sync_count = word_count / 4; // Sync-Manager-Strunktur ist 4 Worte lang for (i = 0; i < sync_count; i++, data += 8) { - if (!(sync = (ec_eeprom_sync_t *) kmalloc(sizeof(ec_eeprom_sync_t), - GFP_KERNEL))) { + if (!(sync = (ec_eeprom_sync_t *) + kmalloc(sizeof(ec_eeprom_sync_t), GFP_KERNEL))) { EC_ERR("Failed to allocate Sync-Manager memory.\n"); return -1; } @@ -517,8 +515,8 @@ unsigned int entry_count, i; while (word_count >= 4) { - if (!(pdo = (ec_eeprom_pdo_t *) kmalloc(sizeof(ec_eeprom_pdo_t), - GFP_KERNEL))) { + if (!(pdo = (ec_eeprom_pdo_t *) + kmalloc(sizeof(ec_eeprom_pdo_t), GFP_KERNEL))) { EC_ERR("Failed to allocate PDO memory.\n"); return -1; }