From bc02897af225a6296ab830c57625d9a62d87f07f Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Fri, 24 Mar 2006 08:35:46 +0000 Subject: [PATCH] =?UTF-8?q?Code=20aufger=C3=A4umt=20und=20kleines=20Speich?= =?UTF-8?q?erleck=20entdeckt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- master/module.c | 48 ++++++++++++++++++++++++++---------------------- master/slave.c | 10 ++++------ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/master/module.c b/master/module.c index 0a26ef29..834df70b 100644 --- a/master/module.c +++ b/master/module.c @@ -75,24 +75,22 @@ int __init ec_init_module(void) 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; + goto out_return; } - if ((ec_masters_reserved = - (unsigned int *) kmalloc(sizeof(int) * ec_master_count, - GFP_KERNEL)) == NULL) { + 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 @@ int __init ec_init_module(void) } EC_INFO("Master driver initialized.\n"); - return 0; + + out_free_masters: + kfree(ec_masters); + out_return: + return -1; } /*****************************************************************************/ @@ -119,16 +121,15 @@ void __exit ec_cleanup_module(void) 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 @@ ec_device_t *ecdev_register(unsigned int master_index, 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)) + if (ec_device_init(master->device, master, net_dev, isr, module)) { + kfree(master->device); + master->device = NULL; return NULL; + } return master->device; } diff --git a/master/slave.c b/master/slave.c index caf1ccc0..9d1d9d4d 100644 --- a/master/slave.c +++ b/master/slave.c @@ -329,8 +329,6 @@ int ec_slave_fetch_categories(ec_slave_t *slave /**< EtherCAT-Slave */) 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 @@ int ec_slave_fetch_sync(ec_slave_t *slave, /**< EtherCAT-Slave */ 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 @@ int ec_slave_fetch_pdo(ec_slave_t *slave, /**< EtherCAT-Slave */ 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; }