Changes in uspace/lib/usbdev/src/devdrv.c [882580a:0c0f823b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/devdrv.c
r882580a r0c0f823b 46 46 47 47 static driver_ops_t generic_driver_ops = { 48 . add_device= generic_device_add,48 .dev_add = 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 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 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); 94 88 return count; 95 89 } … … 104 98 usb_device_t *dev, int alternate_setting) 105 99 { 100 assert(dev); 101 106 102 if (endpoints == NULL) { 107 103 dev->pipes = NULL; … … 300 296 301 297 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; 302 309 } 303 310 … … 319 326 * (not NULL terminated). 320 327 * @param[out] pipes_count_ptr Where to store number of pipes 321 * (set to if you wish to ignore the count).328 * (set to NULL if you wish to ignore the count). 322 329 * @return Error code. 323 330 */ … … 340 347 const size_t pipe_count = count_other_pipes(endpoints); 341 348 if (pipe_count == 0) { 342 *pipes_count_ptr = pipe_count; 349 if (pipes_count_ptr) 350 *pipes_count_ptr = pipe_count; 343 351 *pipes_ptr = NULL; 344 352 return EOK; … … 346 354 347 355 usb_endpoint_mapping_t *pipes 348 = malloc(sizeof(usb_endpoint_mapping_t) * pipe_count);356 = calloc(pipe_count, sizeof(usb_endpoint_mapping_t)); 349 357 if (pipes == NULL) { 350 358 return ENOMEM; 351 359 } 352 360 353 /* Initialize to NULL to allow smooth rollback. */354 for (i = 0; i < pipe_count; i++) {355 pipes[i].pipe = NULL;356 }357 358 361 /* Now allocate and fully initialize. */ 359 362 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 }365 363 pipes[i].description = endpoints[i]; 366 364 pipes[i].interface_no = interface_no; … … 389 387 for (i = 0; i < pipe_count; i++) { 390 388 if (pipes[i].present) { 391 rc = usb_pipe_register( pipes[i].pipe,389 rc = usb_pipe_register(&pipes[i].pipe, 392 390 pipes[i].descriptor->poll_interval, &hc_conn); 393 391 if (rc != EOK) { … … 398 396 399 397 if (usb_hc_connection_close(&hc_conn) != EOK) 400 usb_log_warning(" usb_device_create_pipes(): "401 "Failed to close connection.\n");398 usb_log_warning("%s: Failed to close connection.\n", 399 __FUNCTION__); 402 400 403 401 *pipes_ptr = pipes; … … 417 415 for (i = 0; i < pipe_count; i++) { 418 416 if (pipes[i].present) { 419 usb_pipe_unregister( pipes[i].pipe, &hc_conn);417 usb_pipe_unregister(&pipes[i].pipe, &hc_conn); 420 418 } 421 419 } … … 431 429 */ 432 430 rollback_free_only: 433 for (i = 0; i < pipe_count; i++) {434 if (pipes[i].pipe != NULL) {435 free(pipes[i].pipe);436 }437 }438 431 free(pipes); 439 432 … … 477 470 i, pipes[i].present ? "" : "not "); 478 471 if (pipes[i].present) 479 usb_pipe_unregister(pipes[i].pipe, &hc_conn); 480 free(pipes[i].pipe); 472 usb_pipe_unregister(&pipes[i].pipe, &hc_conn); 481 473 } 482 474 … … 489 481 return EOK; 490 482 } 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 * @return497 */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 519 483 520 484 /** Initialize new instance of USB device. … … 533 497 assert(ddf_dev != NULL); 534 498 499 *errstr_ptr = NULL; 500 535 501 usb_dev->ddf_dev = ddf_dev; 536 502 usb_dev->driver_data = NULL; 537 503 usb_dev->descriptors.configuration = NULL; 538 usb_dev->alternate_interfaces = NULL;539 504 usb_dev->pipes_count = 0; 540 505 usb_dev->pipes = NULL; 541 506 542 507 /* Initialize backing wire and control pipe. */ 543 int rc = init_wire_and_ctrl_pipe(usb_dev, errstr_ptr); 544 if (rc != EOK) { 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"; 545 521 return rc; 546 522 } … … 553 529 &usb_dev->descriptors); 554 530 if (rc != EOK) { 555 /* Nothing allocated, nothing to free. */556 531 *errstr_ptr = "descriptor retrieval"; 557 532 return rc; 558 533 } 559 534 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); 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); 567 547 if (rc != EOK) { 568 548 /* Full configuration descriptor is allocated. */ 569 free(usb_dev->descriptors.configuration);549 usb_device_release_descriptors(&usb_dev->descriptors); 570 550 /* Alternate interfaces may be allocated */ 571 usb_alternate_interfaces_de stroy(usb_dev->alternate_interfaces);551 usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces); 572 552 *errstr_ptr = "pipes initialization"; 573 553 return rc; 574 554 } 575 576 *errstr_ptr = NULL;577 555 578 556 return EOK; … … 591 569 destroy_current_pipes(dev); 592 570 593 usb_alternate_interfaces_de stroy(dev->alternate_interfaces);594 free(dev->descriptors.configuration);571 usb_alternate_interfaces_deinit(&dev->alternate_interfaces); 572 usb_device_release_descriptors(&dev->descriptors); 595 573 free(dev->driver_data); 596 574 }
Note:
See TracChangeset
for help on using the changeset viewer.