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