Changes in uspace/lib/usbdev/src/recognise.c [56fd7cf:6e3c005] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/recognise.c
r56fd7cf r6e3c005 33 33 * Functions for recognition of attached devices. 34 34 */ 35 36 /** XXX Fix this */37 #define _DDF_DATA_IMPLANT38 39 35 #include <sys/types.h> 40 36 #include <fibril_synch.h> … … 315 311 * will be written. 316 312 * @return Error code. 317 *318 313 */ 319 314 int usb_device_register_child_in_devman(usb_pipe_t *ctrl_pipe, … … 323 318 if (child_fun == NULL || ctrl_pipe == NULL) 324 319 return EINVAL; 325 320 326 321 if (!dev_ops && dev_data) { 327 322 usb_log_warning("Using standard fun ops with arbitrary " 328 323 "driver data. This does not have to work.\n"); 329 324 } 330 325 331 326 /** Index to append after device name for uniqueness. */ 332 327 static atomic_t device_name_index = {0}; 333 328 const size_t this_device_name_index = 334 329 (size_t) atomic_preinc(&device_name_index); 335 330 336 331 ddf_fun_t *child = NULL; 337 332 int rc; 338 333 339 334 /* 340 335 * TODO: Once the device driver framework support persistent 341 336 * naming etc., something more descriptive could be created. 342 337 */ 343 char child_name[12]; 338 char child_name[12]; /* The format is: "usbAB_aXYZ", length 11 */ 344 339 rc = snprintf(child_name, sizeof(child_name), 345 340 "usb%02zu_a%d", this_device_name_index, ctrl_pipe->wire->address); … … 347 342 goto failure; 348 343 } 349 344 350 345 child = ddf_fun_create(parent, fun_inner, child_name); 351 346 if (child == NULL) { … … 353 348 goto failure; 354 349 } 355 356 if (dev_ops != NULL) 357 ddf_fun_set_ops(child, dev_ops); 358 else 359 ddf_fun_set_ops(child, &child_ops); 360 361 ddf_fun_data_implant(child, dev_data); 362 363 /* 364 * Store the attached device in fun 365 * driver data if there is no other data 366 */ 350 351 if (dev_ops != NULL) { 352 child->ops = dev_ops; 353 } else { 354 child->ops = &child_ops; 355 } 356 357 child->driver_data = dev_data; 358 /* Store the attached device in fun driver data if there is no 359 * other data */ 367 360 if (!dev_data) { 368 361 usb_hub_attached_device_t *new_device = ddf_fun_data_alloc( … … 372 365 goto failure; 373 366 } 374 375 367 new_device->address = ctrl_pipe->wire->address; 376 368 new_device->fun = child; 377 369 } 378 379 match_id_list_t match_ids; 380 init_match_ids(&match_ids); 381 rc = usb_device_create_match_ids(ctrl_pipe, &match_ids); 382 if (rc != EOK) 370 371 372 rc = usb_device_create_match_ids(ctrl_pipe, &child->match_ids); 373 if (rc != EOK) { 383 374 goto failure; 384 385 list_foreach(match_ids.ids, id_link) { 386 match_id_t *match_id = list_get_instance(id_link, match_id_t, link); 387 rc = ddf_fun_add_match_id(child, match_id->id, match_id->score); 388 if (rc != EOK) { 389 clean_match_ids(&match_ids); 390 goto failure; 391 } 392 } 393 394 clean_match_ids(&match_ids); 395 375 } 376 396 377 rc = ddf_fun_bind(child); 397 if (rc != EOK) 378 if (rc != EOK) { 398 379 goto failure; 399 380 } 381 400 382 *child_fun = child; 401 383 return EOK; 402 384 403 385 failure: 404 386 if (child != NULL) { 387 /* We know nothing about the data if it came from outside. */ 388 if (dev_data) { 389 child->driver_data = NULL; 390 } 405 391 /* This takes care of match_id deallocation as well. */ 406 392 ddf_fun_destroy(child); 407 393 } 408 394 409 395 return rc; 410 396 } 411 397 398 412 399 /** 413 400 * @}
Note:
See TracChangeset
for help on using the changeset viewer.