Changeset b4b534ac in mainline for uspace/drv/bus/usb/usbmid/usbmid.c
- Timestamp:
- 2016-07-22T08:24:47Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f76d2c2
- Parents:
- 5b18137 (diff), 8351f9a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbmid/usbmid.c
r5b18137 rb4b534ac 39 39 #include <stdlib.h> 40 40 #include <usb_iface.h> 41 #include <usb/ddfiface.h>42 41 #include <usb/dev/pipes.h> 43 42 #include <usb/classes/classes.h> … … 45 44 #include "usbmid.h" 46 45 47 /** Callback for DDF USB interface. */ 48 static int usb_iface_get_interface_impl(ddf_fun_t *fun, int *iface_no) 46 /** Get USB device handle by calling the parent usb_device_t. 47 * 48 * @param[in] fun Device function the operation is running on. 49 * @param[out] handle Device handle. 50 * @return Error code. 51 */ 52 static int usb_iface_device_handle(ddf_fun_t *fun, devman_handle_t *handle) 53 { 54 assert(fun); 55 assert(handle); 56 usb_device_t *usb_dev = usb_device_get(ddf_fun_get_dev(fun)); 57 *handle = usb_device_get_devman_handle(usb_dev); 58 return EOK; 59 } 60 61 /** Callback for DDF USB get interface. */ 62 static int usb_iface_iface_no(ddf_fun_t *fun, int *iface_no) 49 63 { 50 64 usbmid_interface_t *iface = ddf_fun_data_get(fun); 51 65 assert(iface); 52 66 53 if (iface_no != NULL) {67 if (iface_no) 54 68 *iface_no = iface->interface_no; 55 }56 69 57 70 return EOK; 58 71 } 59 72 60 /** DDF interface of the child - interface function. */73 /** DDF interface of the child - USB functions. */ 61 74 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, 75 .get_my_device_handle = usb_iface_device_handle, 76 .get_my_interface = usb_iface_iface_no, 65 77 }; 66 78 … … 78 90 return ret; 79 91 } 80 /* NOTE: usbmid->interface points somewhere, but we did not81 * allocate that space, so don't touch */82 92 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 93 return EOK; 86 94 } … … 95 103 */ 96 104 int usbmid_spawn_interface_child(usb_device_t *parent, 97 usbmid_interface_t * iface,105 usbmid_interface_t **iface_ret, 98 106 const usb_standard_device_descriptor_t *device_descriptor, 99 107 const usb_standard_interface_descriptor_t *interface_descriptor) 100 108 { 109 ddf_fun_t *child = NULL; 101 110 char *child_name = NULL; 102 111 int rc; … … 110 119 usb_str_class(interface_descriptor->interface_class), 111 120 interface_descriptor->interface_number); 112 if (rc < 0) 121 if (rc < 0) { 113 122 return ENOMEM; 123 } 114 124 115 rc = ddf_fun_set_name(iface->fun, child_name); 125 /* Create the device. */ 126 child = usb_device_ddf_fun_create(parent, fun_inner, child_name); 116 127 free(child_name); 117 if ( rc != EOK)128 if (child == NULL) { 118 129 return ENOMEM; 130 } 119 131 120 132 match_id_list_t match_ids; … … 123 135 rc = usb_device_create_match_ids_from_interface(device_descriptor, 124 136 interface_descriptor, &match_ids); 125 if (rc != EOK) 137 if (rc != EOK) { 138 ddf_fun_destroy(child); 126 139 return rc; 140 } 127 141 128 142 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);143 rc = ddf_fun_add_match_id(child, match_id->id, match_id->score); 130 144 if (rc != EOK) { 131 145 clean_match_ids(&match_ids); 146 ddf_fun_destroy(child); 132 147 return rc; 133 148 } 134 149 } 135 150 clean_match_ids(&match_ids); 151 ddf_fun_set_ops(child, &child_device_ops); 136 152 137 ddf_fun_set_ops(iface->fun, &child_device_ops);153 usbmid_interface_t *iface = ddf_fun_data_alloc(child, sizeof(*iface)); 138 154 139 rc = ddf_fun_bind(iface->fun); 140 if (rc != EOK) 155 iface->fun = child; 156 iface->interface_no = interface_descriptor->interface_number; 157 link_initialize(&iface->link); 158 159 rc = ddf_fun_bind(child); 160 if (rc != EOK) { 161 /* This takes care of match_id deallocation as well. */ 162 ddf_fun_destroy(child); 141 163 return rc; 164 } 165 *iface_ret = iface; 142 166 143 167 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.