Changes in uspace/lib/usbdev/src/devdrv.c [0c0f823b:882580a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devdrv.c
r0c0f823b r882580a 46 46 47 47 static driver_ops_t generic_driver_ops = { 48 . dev_add= generic_device_add,48 .add_device = generic_device_add, 49 49 .dev_remove = generic_device_remove, 50 50 .dev_gone = generic_device_gone, … … 81 81 * @return Number of pipes (excluding default control pipe). 82 82 */ 83 static inline size_t count_other_pipes( 84 const usb_endpoint_description_t **endpoints) 85 { 86 size_t count; 87 for (count = 0; endpoints && endpoints[count] != NULL; ++count); 83 static size_t count_other_pipes(const usb_endpoint_description_t **endpoints) 84 { 85 size_t count = 0; 86 if (endpoints == NULL) { 87 return 0; 88 } 89 90 while (endpoints[count] != NULL) { 91 count++; 92 } 93 88 94 return count; 89 95 } … … 98 104 usb_device_t *dev, int alternate_setting) 99 105 { 100 assert(dev);101 102 106 if (endpoints == NULL) { 103 107 dev->pipes = NULL; … … 296 300 297 301 return rc; 298 }299 300 /** Cleanup structure initialized via usb_device_retrieve_descriptors.301 *302 * @param[in] descriptors Where to store the descriptors.303 */304 void usb_device_release_descriptors(usb_device_descriptors_t *descriptors)305 {306 assert(descriptors);307 free(descriptors->configuration);308 descriptors->configuration = NULL;309 302 } 310 303 … … 326 319 * (not NULL terminated). 327 320 * @param[out] pipes_count_ptr Where to store number of pipes 328 * (set to NULLif you wish to ignore the count).321 * (set to if you wish to ignore the count). 329 322 * @return Error code. 330 323 */ … … 347 340 const size_t pipe_count = count_other_pipes(endpoints); 348 341 if (pipe_count == 0) { 349 if (pipes_count_ptr) 350 *pipes_count_ptr = pipe_count; 342 *pipes_count_ptr = pipe_count; 351 343 *pipes_ptr = NULL; 352 344 return EOK; … … 354 346 355 347 usb_endpoint_mapping_t *pipes 356 = calloc(pipe_count, sizeof(usb_endpoint_mapping_t));348 = malloc(sizeof(usb_endpoint_mapping_t) * pipe_count); 357 349 if (pipes == NULL) { 358 350 return ENOMEM; 359 351 } 360 352 353 /* Initialize to NULL to allow smooth rollback. */ 354 for (i = 0; i < pipe_count; i++) { 355 pipes[i].pipe = NULL; 356 } 357 361 358 /* Now allocate and fully initialize. */ 362 359 for (i = 0; i < pipe_count; i++) { 360 pipes[i].pipe = malloc(sizeof(usb_pipe_t)); 361 if (pipes[i].pipe == NULL) { 362 rc = ENOMEM; 363 goto rollback_free_only; 364 } 363 365 pipes[i].description = endpoints[i]; 364 366 pipes[i].interface_no = interface_no; … … 387 389 for (i = 0; i < pipe_count; i++) { 388 390 if (pipes[i].present) { 389 rc = usb_pipe_register( &pipes[i].pipe,391 rc = usb_pipe_register(pipes[i].pipe, 390 392 pipes[i].descriptor->poll_interval, &hc_conn); 391 393 if (rc != EOK) { … … 396 398 397 399 if (usb_hc_connection_close(&hc_conn) != EOK) 398 usb_log_warning(" %s: Failed to close connection.\n",399 __FUNCTION__);400 usb_log_warning("usb_device_create_pipes(): " 401 "Failed to close connection.\n"); 400 402 401 403 *pipes_ptr = pipes; … … 415 417 for (i = 0; i < pipe_count; i++) { 416 418 if (pipes[i].present) { 417 usb_pipe_unregister( &pipes[i].pipe, &hc_conn);419 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 418 420 } 419 421 } … … 429 431 */ 430 432 rollback_free_only: 433 for (i = 0; i < pipe_count; i++) { 434 if (pipes[i].pipe != NULL) { 435 free(pipes[i].pipe); 436 } 437 } 431 438 free(pipes); 432 439 … … 470 477 i, pipes[i].present ? "" : "not "); 471 478 if (pipes[i].present) 472 usb_pipe_unregister(&pipes[i].pipe, &hc_conn); 479 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 480 free(pipes[i].pipe); 473 481 } 474 482 … … 481 489 return EOK; 482 490 } 491 492 /** Initialize control pipe in a device. 493 * 494 * @param dev USB device in question. 495 * @param errmsg Where to store error context. 496 * @return 497 */ 498 static int init_wire_and_ctrl_pipe(usb_device_t *dev, const char **errmsg) 499 { 500 int rc; 501 502 rc = usb_device_connection_initialize_from_device(&dev->wire, 503 dev->ddf_dev); 504 if (rc != EOK) { 505 *errmsg = "device connection initialization"; 506 return rc; 507 } 508 509 rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe, 510 &dev->wire); 511 if (rc != EOK) { 512 *errmsg = "default control pipe initialization"; 513 return rc; 514 } 515 516 return EOK; 517 } 518 483 519 484 520 /** Initialize new instance of USB device. … … 497 533 assert(ddf_dev != NULL); 498 534 499 *errstr_ptr = NULL;500 501 535 usb_dev->ddf_dev = ddf_dev; 502 536 usb_dev->driver_data = NULL; 503 537 usb_dev->descriptors.configuration = NULL; 538 usb_dev->alternate_interfaces = NULL; 504 539 usb_dev->pipes_count = 0; 505 540 usb_dev->pipes = NULL; 506 541 507 542 /* Initialize backing wire and control pipe. */ 508 int rc = usb_device_connection_initialize_from_device( 509 &usb_dev->wire, ddf_dev); 510 if (rc != EOK) { 511 *errstr_ptr = "device connection initialization"; 512 return rc; 513 } 514 515 /* This pipe was registered by the hub driver, 516 * during device initialization. */ 517 rc = usb_pipe_initialize_default_control(&usb_dev->ctrl_pipe, 518 &usb_dev->wire); 519 if (rc != EOK) { 520 *errstr_ptr = "default control pipe initialization"; 543 int rc = init_wire_and_ctrl_pipe(usb_dev, errstr_ptr); 544 if (rc != EOK) { 521 545 return rc; 522 546 } … … 529 553 &usb_dev->descriptors); 530 554 if (rc != EOK) { 555 /* Nothing allocated, nothing to free. */ 531 556 *errstr_ptr = "descriptor retrieval"; 532 557 return rc; 533 558 } 534 559 535 /* Create alternate interfaces. We will silently ignore failure. 536 * We might either control one interface or an entire device, 537 * it makes no sense to speak about alternate interfaces when 538 * controlling a device. */ 539 rc = usb_alternate_interfaces_init(&usb_dev->alternate_interfaces, 540 usb_dev->descriptors.configuration, 541 usb_dev->descriptors.configuration_size, usb_dev->interface_no); 542 const int alternate_iface = 543 (rc == EOK) ? usb_dev->alternate_interfaces.current : 0; 544 545 /* TODO Add comment here. */ 546 rc = initialize_other_pipes(endpoints, usb_dev, alternate_iface); 560 /* Create alternate interfaces. We will silently ignore failure. */ 561 //TODO Why ignore? 562 usb_alternate_interfaces_create(usb_dev->descriptors.configuration, 563 usb_dev->descriptors.configuration_size, usb_dev->interface_no, 564 &usb_dev->alternate_interfaces); 565 566 rc = initialize_other_pipes(endpoints, usb_dev, 0); 547 567 if (rc != EOK) { 548 568 /* Full configuration descriptor is allocated. */ 549 usb_device_release_descriptors(&usb_dev->descriptors);569 free(usb_dev->descriptors.configuration); 550 570 /* Alternate interfaces may be allocated */ 551 usb_alternate_interfaces_de init(&usb_dev->alternate_interfaces);571 usb_alternate_interfaces_destroy(usb_dev->alternate_interfaces); 552 572 *errstr_ptr = "pipes initialization"; 553 573 return rc; 554 574 } 575 576 *errstr_ptr = NULL; 555 577 556 578 return EOK; … … 569 591 destroy_current_pipes(dev); 570 592 571 usb_alternate_interfaces_de init(&dev->alternate_interfaces);572 usb_device_release_descriptors(&dev->descriptors);593 usb_alternate_interfaces_destroy(dev->alternate_interfaces); 594 free(dev->descriptors.configuration); 573 595 free(dev->driver_data); 574 596 }
Note:
See TracChangeset
for help on using the changeset viewer.