248 struct module *module /**< pointer to the module */ |
248 struct module *module /**< pointer to the module */ |
249 ) |
249 ) |
250 { |
250 { |
251 ec_master_t *master; |
251 ec_master_t *master; |
252 |
252 |
253 if (!net_dev) { |
|
254 EC_WARN("Device is NULL!\n"); |
|
255 goto out_return; |
|
256 } |
|
257 |
|
258 if (!(master = ec_find_master(master_index))) return NULL; |
253 if (!(master = ec_find_master(master_index))) return NULL; |
259 |
254 |
260 // critical section start |
|
261 if (master->device) { |
255 if (master->device) { |
262 EC_ERR("Master %i already has a device!\n", master_index); |
256 EC_ERR("Master %i already has a device!\n", master_index); |
263 // critical section leave |
|
264 goto out_return; |
257 goto out_return; |
265 } |
258 } |
266 |
259 |
267 if (!(master->device = |
260 if (!(master->device = |
268 (ec_device_t *) kmalloc(sizeof(ec_device_t), GFP_KERNEL))) { |
261 (ec_device_t *) kmalloc(sizeof(ec_device_t), GFP_KERNEL))) { |
269 EC_ERR("Failed to allocate device!\n"); |
262 EC_ERR("Failed to allocate device!\n"); |
270 // critical section leave |
|
271 goto out_return; |
263 goto out_return; |
272 } |
264 } |
273 // critical section end |
|
274 |
265 |
275 if (ec_device_init(master->device, master, net_dev, isr, module)) { |
266 if (ec_device_init(master->device, master, net_dev, isr, module)) { |
276 EC_ERR("Failed to init device!\n"); |
267 EC_ERR("Failed to init device!\n"); |
277 goto out_free; |
268 goto out_free; |
278 } |
269 } |
377 |
368 |
378 EC_INFO("Requesting master %i...\n", master_index); |
369 EC_INFO("Requesting master %i...\n", master_index); |
379 |
370 |
380 if (!(master = ec_find_master(master_index))) goto out_return; |
371 if (!(master = ec_find_master(master_index))) goto out_return; |
381 |
372 |
382 // begin critical section |
|
383 if (master->reserved) { |
373 if (master->reserved) { |
384 EC_ERR("Master %i is already in use!\n", master_index); |
374 EC_ERR("Master %i is already in use!\n", master_index); |
385 goto out_return; |
375 goto out_return; |
386 } |
376 } |
387 master->reserved = 1; |
377 master->reserved = 1; |
388 // end critical section |
|
389 |
378 |
390 if (!master->device) { |
379 if (!master->device) { |
391 EC_ERR("Master %i has no assigned device!\n", master_index); |
380 EC_ERR("Master %i has no assigned device!\n", master_index); |
392 goto out_release; |
381 goto out_release; |
393 } |
382 } |