Ignore:
Timestamp:
2011-11-07T10:54:01Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f750345
Parents:
4578a6e
Message:

usbhid, mouse: Even better error handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r4578a6e r0f12c17  
    296296        return true;
    297297}
    298 
    299 /*----------------------------------------------------------------------------*/
    300 
     298/*----------------------------------------------------------------------------*/
     299#define FUN_UNBIND_DESTROY(fun) \
     300if (fun) { \
     301        if (ddf_fun_unbind((fun)) == EOK) { \
     302                (fun)->driver_data = NULL; \
     303                ddf_fun_destroy((fun)); \
     304        } else { \
     305                usb_log_error("Could not unbind function `%s', it " \
     306                    "will not be destroyed.\n", (fun)->name); \
     307        } \
     308} else (void)0
     309/*----------------------------------------------------------------------------*/
    301310static int usb_mouse_create_function(usb_hid_dev_t *hid_dev, usb_mouse_t *mouse)
    302311{
     
    306315        /* Create the exposed function. */
    307316        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
    308         ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 
     317        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    309318            HID_MOUSE_FUN_NAME);
    310319        if (fun == NULL) {
    311                 usb_log_error("Could not create DDF function node.\n");
     320                usb_log_error("Could not create DDF function node `%s'.\n",
     321                    HID_MOUSE_FUN_NAME);
    312322                return ENOMEM;
    313323        }
     
    318328        int rc = ddf_fun_bind(fun);
    319329        if (rc != EOK) {
    320                 usb_log_error("Could not bind DDF function: %s.\n",
    321                     str_error(rc));
     330                usb_log_error("Could not bind DDF function `%s': %s.\n",
     331                    fun->name, str_error(rc));
    322332                fun->driver_data = NULL;
    323333                ddf_fun_destroy(fun);
     
    325335        }
    326336
    327         usb_log_debug("Adding DDF function to category %s...\n",
    328             HID_MOUSE_CATEGORY);
     337        usb_log_debug("Adding DDF function `%s' to category %s...\n",
     338            fun->name, HID_MOUSE_CATEGORY);
    329339        rc = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
    330340        if (rc != EOK) {
     
    332342                    "Could not add DDF function to category %s: %s.\n",
    333343                    HID_MOUSE_CATEGORY, str_error(rc));
    334                 ddf_fun_unbind(fun);
    335                 fun->driver_data = NULL;
    336                 ddf_fun_destroy(fun);
     344                FUN_UNBIND_DESTROY(fun);
    337345                return rc;
    338346        }
     
    347355            HID_MOUSE_WHEEL_FUN_NAME);
    348356        if (fun == NULL) {
    349                 usb_log_error("Could not create DDF function node.\n");
    350                 ddf_fun_unbind(mouse->mouse_fun);
    351                 mouse->mouse_fun->driver_data = NULL;
    352                 ddf_fun_destroy(mouse->mouse_fun);
     357                usb_log_error("Could not create DDF function node `%s'.\n",
     358                    HID_MOUSE_WHEEL_FUN_NAME);
     359                FUN_UNBIND_DESTROY(mouse->mouse_fun);
    353360                mouse->mouse_fun = NULL;
    354361                return ENOMEM;
     
    364371        rc = ddf_fun_bind(fun);
    365372        if (rc != EOK) {
    366                 usb_log_error("Could not bind DDF function: %s.\n",
    367                     str_error(rc));
    368                 ddf_fun_unbind(mouse->mouse_fun);
    369                 mouse->mouse_fun->driver_data = NULL;
    370                 ddf_fun_destroy(mouse->mouse_fun);
     373                usb_log_error("Could not bind DDF function `%s': %s.\n",
     374                    fun->name, str_error(rc));
     375                FUN_UNBIND_DESTROY(mouse->mouse_fun);
    371376                mouse->mouse_fun = NULL;
     377
    372378                fun->driver_data = NULL;
    373379                ddf_fun_destroy(fun);
     
    382388                    "Could not add DDF function to category %s: %s.\n",
    383389                    HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    384                 ddf_fun_unbind(mouse->mouse_fun);
    385                 mouse->mouse_fun->driver_data = NULL;
    386                 ddf_fun_destroy(mouse->mouse_fun);
     390
     391                FUN_UNBIND_DESTROY(mouse->mouse_fun);
    387392                mouse->mouse_fun = NULL;
    388                 ddf_fun_unbind(fun);
    389                 fun->driver_data = NULL;
    390                 ddf_fun_destroy(fun);
     393                FUN_UNBIND_DESTROY(fun);
    391394                return rc;
    392395        }
     
    437440        return highest_button;
    438441}
    439 
    440 /*----------------------------------------------------------------------------*/
    441 
     442/*----------------------------------------------------------------------------*/
    442443int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    443444{
     
    492493        return EOK;
    493494}
    494 
    495 /*----------------------------------------------------------------------------*/
    496 
     495/*----------------------------------------------------------------------------*/
    497496bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    498497{
     
    507506        return usb_mouse_process_report(hid_dev, mouse_dev);
    508507}
    509 
    510 /*----------------------------------------------------------------------------*/
    511 
     508/*----------------------------------------------------------------------------*/
    512509void usb_mouse_deinit(usb_hid_dev_t *hid_dev, void *data)
    513510{
     
    532529        }
    533530
    534         /* We might be called before being completely initialized */
    535         if (mouse_dev->mouse_fun) {
    536                 const int ret = ddf_fun_unbind(mouse_dev->mouse_fun);
    537                 if (ret != EOK) {
    538                         usb_log_error("Failed to unbind mouse function.\n");
    539                 } else {
    540                         /* driver_data(mouse_dev) will be freed explicitly */
    541                         mouse_dev->mouse_fun->driver_data = NULL;
    542                         ddf_fun_destroy(mouse_dev->mouse_fun);
    543                 }
    544         }
    545 
    546         /* We might be called before being completely initialized */
    547         if (mouse_dev->mouse_fun) {
    548                 const int ret = ddf_fun_unbind(mouse_dev->wheel_fun);
    549                 if (ret != EOK) {
    550                         usb_log_error("Failed to unbind wheel function.\n");
    551                 } else {
    552                         /* driver_data(mouse_dev) will be freed explicitly */
    553                         mouse_dev->wheel_fun->driver_data = NULL;
    554                         ddf_fun_destroy(mouse_dev->wheel_fun);
    555                 }
    556         }
     531        FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
     532        FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);
     533
    557534        free(mouse_dev->buttons);
    558535        free(mouse_dev);
    559536}
    560 
    561 /*----------------------------------------------------------------------------*/
    562 
     537/*----------------------------------------------------------------------------*/
    563538int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev)
    564539{
Note: See TracChangeset for help on using the changeset viewer.