Changes in uspace/drv/bus/usb/usbmid/usbmid.c [87a3df7f:58563585] in mainline
- File:
-
- 1 edited
-
uspace/drv/bus/usb/usbmid/usbmid.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/usbmid.c
r87a3df7f r58563585 35 35 * Helper functions. 36 36 */ 37 37 38 #include <errno.h> 38 39 #include <str_error.h> 39 40 #include <stdlib.h> 40 41 #include <usb_iface.h> 41 #include <usb/ddfiface.h>42 42 #include <usb/dev/pipes.h> 43 43 #include <usb/classes/classes.h> … … 45 45 #include "usbmid.h" 46 46 47 /** Callback for DDF USB interface. */ 48 static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no) 47 /** Get USB device handle by calling the parent usb_device_t. 48 * 49 * @param[in] fun Device function the operation is running on. 50 * @param[out] handle Device handle. 51 * @return Error code. 52 */ 53 static int usb_iface_device_handle(ddf_fun_t *fun, devman_handle_t *handle) 54 { 55 assert(fun); 56 assert(handle); 57 usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun)); 58 *handle = usb_device_get_devman_handle(usb_dev); 59 return EOK; 60 } 61 62 /** Callback for DDF USB get interface. */ 63 static int usb_iface_iface_no(ddf_fun_t *fun, int *iface_no) 49 64 { 50 65 usbmid_interface_t *iface = ddf_fun_data_get(fun); 51 66 assert(iface); 52 67 53 if (iface_no != NULL) {68 if (iface_no) 54 69 *iface_no = iface->interface_no; 55 }56 70 57 71 return EOK; 58 72 } 59 73 60 /** DDF interface of the child - interface function. */74 /** DDF interface of the child - USB functions. */ 61 75 static usb_iface_t child_usb_iface = { 62 .get_hc_handle = usb_iface_get_hc_handle_device_impl, 63 .get_my_address = usb_iface_get_my_address_forward_impl, 64 .get_my_interface = usb_iface_get_interface_impl, 76 .get_my_device_handle = usb_iface_device_handle, 77 .get_my_interface = usb_iface_iface_no, 65 78 }; 66 79 … … 78 91 return ret; 79 92 } 80 /* NOTE: usbmid->interface points somewhere, but we did not81 * allocate that space, so don't touch */82 93 ddf_fun_destroy(mid_iface->fun); 83 /* NOTE: mid_iface is invalid at this point, it was assigned to84 * mid_iface->fun->driver_data and freed in ddf_fun_destroy */85 94 return EOK; 86 95 } … … 95 104 */ 96 105 int usbmid_spawn_interface_child(usb_device_t *parent, 97 usbmid_interface_t * iface,106 usbmid_interface_t **iface_ret, 98 107 const usb_standard_device_descriptor_t *device_descriptor, 99 108 const usb_standard_interface_descriptor_t *interface_descriptor) 100 109 { 110 ddf_fun_t *child = NULL; 101 111 char *child_name = NULL; 102 112 int rc; … … 110 120 usb_str_class(interface_descriptor->interface_class), 111 121 interface_descriptor->interface_number); 112 if (rc < 0) 122 if (rc < 0) { 113 123 return ENOMEM; 124 } 114 125 115 rc = ddf_fun_set_name(iface->fun, child_name); 126 /* Create the device. */ 127 child = usb_device_ddf_fun_create(parent, fun_inner, child_name); 116 128 free(child_name); 117 if ( rc != EOK)129 if (child == NULL) { 118 130 return ENOMEM; 131 } 119 132 120 133 match_id_list_t match_ids; … … 123 136 rc = usb_device_create_match_ids_from_interface(device_descriptor, 124 137 interface_descriptor, &match_ids); 125 if (rc != EOK) 138 if (rc != EOK) { 139 ddf_fun_destroy(child); 126 140 return rc; 141 } 127 142 128 143 list_foreach(match_ids.ids, link, match_id_t, match_id) { 129 rc = ddf_fun_add_match_id( iface->fun, match_id->id, match_id->score);144 rc = ddf_fun_add_match_id(child, match_id->id, match_id->score); 130 145 if (rc != EOK) { 131 146 clean_match_ids(&match_ids); 147 ddf_fun_destroy(child); 132 148 return rc; 133 149 } 134 150 } 135 151 clean_match_ids(&match_ids); 152 ddf_fun_set_ops(child, &child_device_ops); 136 153 137 ddf_fun_set_ops(iface->fun, &child_device_ops);154 usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface)); 138 155 139 rc = ddf_fun_bind(iface->fun); 140 if (rc != EOK) 156 iface->fun = child; 157 iface->interface_no = interface_descriptor->interface_number; 158 link_initialize(&iface->link); 159 160 rc = ddf_fun_bind(child); 161 if (rc != EOK) { 162 /* This takes care of match_id deallocation as well. */ 163 ddf_fun_destroy(child); 141 164 return rc; 165 } 166 *iface_ret = iface; 142 167 143 168 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.
