Ignore:
File:
1 edited

Legend:

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

    recb107b rfcafa04  
    7979};
    8080
     81/** Create new interface for USB MID device.
     82 *
     83 * @param fun Backing generic DDF device function (representing interface).
     84 * @param iface_no Interface number.
     85 * @return New interface.
     86 * @retval NULL Error occured.
     87 */
     88usbmid_interface_t *usbmid_interface_create(ddf_fun_t *fun, int iface_no)
     89{
     90        usbmid_interface_t *iface = malloc(sizeof(usbmid_interface_t));
     91        if (iface == NULL) {
     92                usb_log_error("Out of memory (wanted %zuB).\n",
     93                    sizeof(usbmid_interface_t));
     94                return NULL;
     95        }
     96
     97        iface->fun = fun;
     98        iface->interface_no = iface_no;
     99
     100        return iface;
     101}
     102
    81103
    82104/** Spawn new child device from one interface.
    83105 *
    84106 * @param parent Parent MID device.
    85  * @param iface Interface information.
    86107 * @param device_descriptor Device descriptor.
    87108 * @param interface_descriptor Interface descriptor.
     
    89110 */
    90111int usbmid_spawn_interface_child(usb_device_t *parent,
    91     usbmid_interface_t *iface,
    92112    const usb_standard_device_descriptor_t *device_descriptor,
    93113    const usb_standard_interface_descriptor_t *interface_descriptor)
     
    95115        ddf_fun_t *child = NULL;
    96116        char *child_name = NULL;
     117        usbmid_interface_t *child_as_interface = NULL;
    97118        int rc;
    98119
     
    116137        }
    117138
    118         iface->fun = child;
    119139
    120         child->driver_data = iface;
     140
     141        child_as_interface = usbmid_interface_create(child,
     142            (int) interface_descriptor->interface_number);
     143        if (child_as_interface == NULL) {
     144                rc = ENOMEM;
     145                goto error_leave;
     146        }
     147
     148        child->driver_data = child_as_interface;
    121149        child->ops = &child_device_ops;
    122150
     
    144172                free(child_name);
    145173        }
     174        if (child_as_interface != NULL) {
     175                free(child_as_interface);
     176        }
    146177
    147178        return rc;
Note: See TracChangeset for help on using the changeset viewer.