master/module.c
changeset 127 e67c80a76de4
parent 111 9963537ec776
child 151 1961b674466c
equal deleted inserted replaced
126:bbc963b9fead 127:e67c80a76de4
    73 
    73 
    74     EC_INFO("Master driver, %s\n", COMPILE_INFO);
    74     EC_INFO("Master driver, %s\n", COMPILE_INFO);
    75 
    75 
    76     if (ec_master_count < 1) {
    76     if (ec_master_count < 1) {
    77         EC_ERR("Error - Invalid ec_master_count: %i\n", ec_master_count);
    77         EC_ERR("Error - Invalid ec_master_count: %i\n", ec_master_count);
    78         return -1;
    78         goto out_return;
    79     }
    79     }
    80 
    80 
    81     EC_INFO("Initializing %i EtherCAT master(s)...\n", ec_master_count);
    81     EC_INFO("Initializing %i EtherCAT master(s)...\n", ec_master_count);
    82 
    82 
    83     if ((ec_masters = (ec_master_t *) kmalloc(sizeof(ec_master_t)
    83     if (!(ec_masters = (ec_master_t *)
    84                                               * ec_master_count,
    84           kmalloc(sizeof(ec_master_t) * ec_master_count, GFP_KERNEL))) {
    85                                               GFP_KERNEL)) == NULL) {
       
    86         EC_ERR("Could not allocate memory for EtherCAT master(s)!\n");
    85         EC_ERR("Could not allocate memory for EtherCAT master(s)!\n");
    87         return -1;
    86         goto out_return;
    88     }
    87     }
    89 
    88 
    90     if ((ec_masters_reserved =
    89     if (!(ec_masters_reserved =
    91          (unsigned int *) kmalloc(sizeof(int) * ec_master_count,
    90           (unsigned int *) kmalloc(sizeof(int) * ec_master_count,
    92                                   GFP_KERNEL)) == NULL) {
    91                                    GFP_KERNEL))) {
    93         EC_ERR("Could not allocate memory for reservation flags!\n");
    92         EC_ERR("Could not allocate memory for reservation flags!\n");
    94         kfree(ec_masters);
    93         goto out_free_masters;
    95         return -1;
       
    96     }
    94     }
    97 
    95 
    98     for (i = 0; i < ec_master_count; i++) {
    96     for (i = 0; i < ec_master_count; i++) {
    99         ec_master_init(ec_masters + i);
    97         ec_master_init(ec_masters + i);
   100         ec_masters_reserved[i] = 0;
    98         ec_masters_reserved[i] = 0;
   101     }
    99     }
   102 
   100 
   103     EC_INFO("Master driver initialized.\n");
   101     EC_INFO("Master driver initialized.\n");
   104 
       
   105     return 0;
   102     return 0;
       
   103 
       
   104  out_free_masters:
       
   105     kfree(ec_masters);
       
   106  out_return:
       
   107     return -1;
   106 }
   108 }
   107 
   109 
   108 /*****************************************************************************/
   110 /*****************************************************************************/
   109 
   111 
   110 /**
   112 /**
   117 {
   119 {
   118     unsigned int i;
   120     unsigned int i;
   119 
   121 
   120     EC_INFO("Cleaning up master driver...\n");
   122     EC_INFO("Cleaning up master driver...\n");
   121 
   123 
   122     if (ec_masters) {
   124     for (i = 0; i < ec_master_count; i++) {
   123         for (i = 0; i < ec_master_count; i++) {
   125         if (ec_masters_reserved[i])
   124             if (ec_masters_reserved[i]) {
   126             EC_WARN("Master %i is still in use!\n", i);
   125                 EC_WARN("Master %i is still in use!\n", i);
   127         ec_master_clear(&ec_masters[i]);
   126             }
   128     }
   127             ec_master_clear(&ec_masters[i]);
   129 
   128         }
   130     kfree(ec_masters);
   129         kfree(ec_masters);
   131     kfree(ec_masters_reserved);
   130     }
       
   131 
   132 
   132     EC_INFO("Master driver cleaned up.\n");
   133     EC_INFO("Master driver cleaned up.\n");
   133 }
   134 }
   134 
   135 
   135 /******************************************************************************
   136 /******************************************************************************
   172     if (master->device) {
   173     if (master->device) {
   173         EC_ERR("Master %i already has a device!\n", master_index);
   174         EC_ERR("Master %i already has a device!\n", master_index);
   174         return NULL;
   175         return NULL;
   175     }
   176     }
   176 
   177 
   177     if (!(master->device = (ec_device_t *) kmalloc(sizeof(ec_device_t),
   178     if (!(master->device = (ec_device_t *)
   178                                                    GFP_KERNEL))) {
   179           kmalloc(sizeof(ec_device_t), GFP_KERNEL))) {
   179         EC_ERR("Failed allocating device!\n");
   180         EC_ERR("Failed allocating device!\n");
   180         return NULL;
   181         return NULL;
   181     }
   182     }
   182 
   183 
   183     if (ec_device_init(master->device, master, net_dev, isr, module))
   184     if (ec_device_init(master->device, master, net_dev, isr, module)) {
   184         return NULL;
   185         kfree(master->device);
       
   186         master->device = NULL;
       
   187         return NULL;
       
   188     }
   185 
   189 
   186     return master->device;
   190     return master->device;
   187 }
   191 }
   188 
   192 
   189 /*****************************************************************************/
   193 /*****************************************************************************/