Changes in uspace/drv/bus/usb/usbhid/generic/hiddev.c [065064e6:15f3c3f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r065064e6 r15f3c3f 52 52 .direction = USB_DIRECTION_IN, 53 53 .interface_class = USB_CLASS_HID, 54 .interface_subclass = -1,55 .interface_protocol = -1,56 54 .flags = 0 57 55 }; … … 94 92 usb_log_debug2("Generic HID: Get event length (fun: %p, " 95 93 "fun->driver_data: %p.\n", fun, fun->driver_data); 96 94 97 95 if (fun == NULL || fun->driver_data == NULL) { 98 96 return 0; … … 100 98 101 99 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 102 100 103 101 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", 104 102 hid_dev, hid_dev->max_input_report_size); 105 103 106 104 return hid_dev->max_input_report_size; 107 105 } … … 113 111 { 114 112 usb_log_debug2("Generic HID: Get event.\n"); 115 113 116 114 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 117 115 || act_size == NULL || event_nr == NULL) { … … 121 119 122 120 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 123 121 124 122 if (hid_dev->input_report_size > size) { 125 123 usb_log_debug("input_report_size > size (%zu, %zu)\n", … … 127 125 return EINVAL; // TODO: other error code 128 126 } 129 127 130 128 /*! @todo This should probably be somehow atomic. */ 131 129 memcpy(buffer, hid_dev->input_report, … … 133 131 *act_size = hid_dev->input_report_size; 134 132 *event_nr = usb_hid_report_number(hid_dev); 135 133 136 134 usb_log_debug2("OK\n"); 137 135 138 136 return EOK; 139 137 } … … 144 142 { 145 143 usb_log_debug("Generic HID: Get report descriptor length.\n"); 146 144 147 145 if (fun == NULL || fun->driver_data == NULL) { 148 146 usb_log_debug("No function"); 149 147 return EINVAL; 150 148 } 151 152 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 153 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 151 154 152 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 155 153 hid_dev->report_desc_size); 156 154 157 155 return hid_dev->report_desc_size; 158 156 } … … 164 162 { 165 163 usb_log_debug2("Generic HID: Get report descriptor.\n"); 166 164 167 165 if (fun == NULL || fun->driver_data == NULL) { 168 166 usb_log_debug("No function"); 169 167 return EINVAL; 170 168 } 171 172 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 173 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 171 174 172 if (hid_dev->report_desc_size > size) { 175 173 return EINVAL; 176 174 } 177 175 178 176 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size); 179 177 *actual_size = hid_dev->report_desc_size; 180 178 181 179 return EOK; 182 180 } … … 192 190 /*----------------------------------------------------------------------------*/ 193 191 194 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data) 195 { 196 ddf_fun_t *fun = data; 197 const int ret = ddf_fun_unbind(fun); 198 if (ret != EOK) { 199 usb_log_error("Failed to unbind generic hid fun.\n"); 200 return; 201 } 202 usb_log_debug2("%s unbound.\n", fun->name); 203 /* We did not allocate this, so leave this alone 204 * the device would take care of it */ 205 fun->driver_data = NULL; 206 ddf_fun_destroy(fun); 207 } 208 209 /*----------------------------------------------------------------------------*/ 210 211 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 212 { 213 if (hid_dev == NULL) { 214 return EINVAL; 215 } 216 192 static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev) 193 { 217 194 /* Create the exposed function. */ 218 195 /** @todo Generate numbers for the devices? */ … … 224 201 return ENOMEM; 225 202 } 226 203 227 204 fun->ops = &usb_generic_hid_ops; 205 fun->driver_data = hid_dev; 228 206 229 207 int rc = ddf_fun_bind(fun); … … 234 212 return rc; 235 213 } 236 /* This is nasty both device and this function have the same 237 * driver data, thus destruction would lead to double free */ 238 fun->driver_data = hid_dev; 239 214 240 215 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); 241 *data = fun; 242 243 return EOK; 216 217 return EOK; 218 } 219 220 /*----------------------------------------------------------------------------*/ 221 222 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 223 { 224 if (hid_dev == NULL) { 225 return EINVAL; 226 } 227 228 return usb_generic_hid_create_function(hid_dev); 244 229 } 245 230
Note:
See TracChangeset
for help on using the changeset viewer.