Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmid/usbmid.c

    r317a463 r5203e256  
    4545
    4646/** Callback for DDF USB interface. */
    47 static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no)
     47static int usb_iface_get_address_impl(ddf_fun_t *fun, devman_handle_t handle,
     48    usb_address_t *address)
     49{
     50        return usb_iface_get_address_hub_impl(fun, handle, address);
     51}
     52
     53/** Callback for DDF USB interface. */
     54static int usb_iface_get_interface_impl(ddf_fun_t *fun, devman_handle_t handle,
     55    int *iface_no)
    4856{
    4957        assert(fun);
     
    6169/** DDF interface of the child - interface function. */
    6270static usb_iface_t child_usb_iface = {
    63         .get_hc_handle = usb_iface_get_hc_handle_device_impl,
    64         .get_my_address = usb_iface_get_my_address_forward_impl,
    65         .get_my_interface = usb_iface_get_interface_impl,
     71        .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
     72        .get_address = usb_iface_get_address_impl,
     73        .get_interface = usb_iface_get_interface_impl
    6674};
    6775
     
    7179};
    7280
    73 int usbmid_interface_destroy(usbmid_interface_t *mid_iface)
    74 {
    75         assert(mid_iface);
    76         assert_link_not_used(&mid_iface->link);
    77         const int ret = ddf_fun_unbind(mid_iface->fun);
    78         if (ret != EOK) {
    79                 return ret;
    80         }
    81         /* NOTE: usbmid->interface points somewhere, but we did not
    82          * allocate that space, so don't touch */
    83         ddf_fun_destroy(mid_iface->fun);
    84         /* NOTE: mid_iface is invalid at this point, it was assigned to
    85          * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
    86         return EOK;
    87 }
    8881
    8982/** Spawn new child device from one interface.
     
    109102         * class name something humanly understandable.
    110103         */
    111         rc = asprintf(&child_name, "%s%hhu",
     104        rc = asprintf(&child_name, "%s%d",
    112105            usb_str_class(interface_descriptor->interface_class),
    113             interface_descriptor->interface_number);
     106            (int) interface_descriptor->interface_number);
    114107        if (rc < 0) {
    115                 return ENOMEM;
     108                goto error_leave;
    116109        }
    117110
    118111        /* Create the device. */
    119112        child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
    120         free(child_name);
    121113        if (child == NULL) {
    122                 return ENOMEM;
     114                rc = ENOMEM;
     115                goto error_leave;
    123116        }
    124117
     118        iface->fun = child;
     119
     120        child->driver_data = iface;
     121        child->ops = &child_device_ops;
     122
    125123        rc = usb_device_create_match_ids_from_interface(device_descriptor,
    126             interface_descriptor, &child->match_ids);
     124            interface_descriptor,
     125            &child->match_ids);
    127126        if (rc != EOK) {
    128                 ddf_fun_destroy(child);
    129                 return rc;
     127                goto error_leave;
    130128        }
    131129
    132130        rc = ddf_fun_bind(child);
    133131        if (rc != EOK) {
     132                goto error_leave;
     133        }
     134
     135        return EOK;
     136
     137error_leave:
     138        if (child != NULL) {
     139                child->name = NULL;
    134140                /* This takes care of match_id deallocation as well. */
    135141                ddf_fun_destroy(child);
    136                 return rc;
     142        }
     143        if (child_name != NULL) {
     144                free(child_name);
    137145        }
    138146
    139         iface->fun = child;
    140         child->driver_data = iface;
    141         child->ops = &child_device_ops;
    142 
    143         return EOK;
     147        return rc;
    144148}
    145149
Note: See TracChangeset for help on using the changeset viewer.