Changes in uspace/drv/bus/usb/usbhid/mouse/mousedev.c [378bf85:350274a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r378bf85 r350274a 34 34 * USB Mouse driver API. 35 35 */ 36 37 /* XXX Fix this */38 #define _DDF_DATA_IMPLANT39 36 40 37 #include <usb/debug.h> … … 249 246 } 250 247 251 #define FUN_UNBIND_DESTROY(fun) \252 if (fun) { \253 if (ddf_fun_unbind((fun)) == EOK) { \254 ddf_fun_destroy((fun)); \255 } else { \256 usb_log_error("Could not unbind function `%s', it " \257 "will not be destroyed.\n", ddf_fun_get_name(fun)); \258 } \259 } else (void)0260 261 static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)262 {263 assert(hid_dev != NULL);264 assert(mouse != NULL);265 266 /* Create the exposed function. */267 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);268 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,269 HID_MOUSE_FUN_NAME);270 if (fun == NULL) {271 usb_log_error("Could not create DDF function node `%s'.\n",272 HID_MOUSE_FUN_NAME);273 return ENOMEM;274 }275 276 ddf_fun_set_ops(fun, &ops);277 ddf_fun_data_implant(fun, mouse);278 279 int rc = ddf_fun_bind(fun);280 if (rc != EOK) {281 usb_log_error("Could not bind DDF function `%s': %s.\n",282 ddf_fun_get_name(fun), str_error(rc));283 ddf_fun_destroy(fun);284 return rc;285 }286 287 usb_log_debug("Adding DDF function `%s' to category %s...\n",288 ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);289 rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);290 if (rc != EOK) {291 usb_log_error(292 "Could not add DDF function to category %s: %s.\n",293 HID_MOUSE_CATEGORY, str_error(rc));294 FUN_UNBIND_DESTROY(fun);295 return rc;296 }297 mouse->mouse_fun = fun;298 return EOK;299 }300 301 248 /** Get highest index of a button mentioned in given report. 302 249 * … … 341 288 int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data) 342 289 { 290 ddf_fun_t *fun = NULL; 291 usb_mouse_t *mouse_dev = NULL; 292 bool bound = false; 293 int rc; 294 343 295 usb_log_debug("Initializing HID/Mouse structure...\n"); 344 296 … … 346 298 usb_log_error("Failed to init mouse structure: no structure" 347 299 " given.\n"); 348 return EINVAL; 349 } 350 351 usb_mouse_t *mouse_dev = calloc(1, sizeof(usb_mouse_t)); 300 rc = EINVAL; 301 goto error; 302 } 303 304 /* Create the exposed function. */ 305 usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME); 306 fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 307 HID_MOUSE_FUN_NAME); 308 if (fun == NULL) { 309 usb_log_error("Could not create DDF function node `%s'.\n", 310 HID_MOUSE_FUN_NAME); 311 rc = ENOMEM; 312 goto error; 313 } 314 315 ddf_fun_set_ops(fun, &ops); 316 317 mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t)); 352 318 if (mouse_dev == NULL) { 353 319 usb_log_error("Error while creating USB/HID Mouse device " 354 320 "structure.\n"); 355 return ENOMEM; 321 rc = ENOMEM; 322 goto error; 356 323 } 357 324 … … 368 335 if (mouse_dev->buttons == NULL) { 369 336 usb_log_error(NAME ": out of memory, giving up on device!\n"); 370 free(mouse_dev);371 return ENOMEM;337 rc = ENOMEM; 338 goto error; 372 339 } 373 340 … … 376 343 hid_dev->usb_dev->interface_no, IDLE_RATE); 377 344 378 int rc = usb_mouse_create_function(hid_dev, mouse_dev);345 rc = ddf_fun_bind(fun); 379 346 if (rc != EOK) { 380 free(mouse_dev->buttons); 381 free(mouse_dev); 382 return rc; 383 } 347 usb_log_error("Could not bind DDF function `%s': %s.\n", 348 ddf_fun_get_name(fun), str_error(rc)); 349 goto error; 350 } 351 352 bound = true; 353 354 usb_log_debug("Adding DDF function `%s' to category %s...\n", 355 ddf_fun_get_name(fun), HID_MOUSE_CATEGORY); 356 rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY); 357 if (rc != EOK) { 358 usb_log_error("Could not add DDF function to category %s: " 359 "%s.\n", HID_MOUSE_CATEGORY, str_error(rc)); 360 goto error; 361 } 362 363 mouse_dev->mouse_fun = fun; 384 364 385 365 /* Save the Mouse device structure into the HID device structure. */ 386 366 *data = mouse_dev; 387 388 367 return EOK; 368 error: 369 if (bound) 370 ddf_fun_unbind(fun); 371 if (mouse_dev != NULL) 372 free(mouse_dev->buttons); 373 if (fun != NULL) 374 ddf_fun_destroy(fun); 375 return rc; 389 376 } 390 377 … … 417 404 } 418 405 419 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 420 406 ddf_fun_unbind(mouse_dev->mouse_fun); 421 407 free(mouse_dev->buttons); 408 ddf_fun_destroy(mouse_dev->mouse_fun); 422 409 } 423 410
Note:
See TracChangeset
for help on using the changeset viewer.