Code aufgeräumt und kleines Speicherleck entdeckt.
This commit is contained in:
parent
2c69194a1a
commit
bc02897af2
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue