Changeset 05920d23 in mainline


Ignore:
Timestamp:
2011-11-07T08:56:22Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f047d0
Parents:
07498c1
Message:

usbhid, multimedia: Fix error paths.

Store DDF function instead of soft-state in *data pointer.

File:
1 edited

Legend:

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

    r07498c1 r05920d23  
    6767        /** IPC session to the console device (for sending key events). */
    6868        async_sess_t *console_sess;
    69         /** DDF function */
    70         ddf_fun_t *fun;
    7169} usb_multimedia_t;
    7270
    7371
    7472/*----------------------------------------------------------------------------*/
    75 /** 
     73/**
    7674 * Default handler for IPC methods not handled by DDF.
    7775 *
     
    8886{
    8987        usb_log_debug(NAME " default_connection_handler()\n");
    90 
    91         usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data;
    92 
    93         if (multim_dev == NULL) {
     88        if (fun == NULL || fun->driver_data == NULL) {
    9489                async_answer_0(icallid, EINVAL);
    9590                return;
    9691        }
     92
     93        usb_multimedia_t *multim_dev = fun->driver_data;
    9794
    9895        async_sess_t *sess =
     
    109106                async_answer_0(icallid, EINVAL);
    110107}
    111 
    112 /*----------------------------------------------------------------------------*/
    113 
     108/*----------------------------------------------------------------------------*/
    114109static ddf_dev_ops_t multimedia_ops = {
    115110        .default_handler = default_connection_handler
    116111};
    117 
    118112/*----------------------------------------------------------------------------*/
    119113/**
     
    134128 * @param key Key code of the key according to HID Usage Tables.
    135129 */
    136 static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev,
     130static void usb_multimedia_push_ev(
    137131    usb_multimedia_t *multim_dev, int type, unsigned int key)
    138132{
     
    154148
    155149        async_exch_t *exch = async_exchange_begin(multim_dev->console_sess);
    156         async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c);
    157         async_exchange_end(exch);
    158 }
    159 
    160 /*----------------------------------------------------------------------------*/
    161 
     150        if (exch != NULL) {
     151                async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c);
     152                async_exchange_end(exch);
     153        } else {
     154                usb_log_warning("Failed to send multimedia key.\n");
     155        }
     156}
     157/*----------------------------------------------------------------------------*/
    162158int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data)
    163159{
     
    186182
    187183        multim_dev->console_sess = NULL;
    188         multim_dev->fun = fun;
    189184
    190185        //todo Autorepeat?
     
    211206
    212207        /* Save the KBD device structure into the HID device structure. */
    213         *data = multim_dev;
     208        *data = fun;
    214209
    215210        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
    216211        return EOK;
    217212}
    218 
    219 /*----------------------------------------------------------------------------*/
    220 
     213/*----------------------------------------------------------------------------*/
    221214void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data)
    222215{
    223         if (data != NULL) {
    224                 usb_multimedia_t *multim_dev = data;
     216        ddf_fun_t *fun = data;
     217        if (fun != NULL && fun->driver_data != NULL) {
     218                usb_multimedia_t *multim_dev = fun->driver_data;
    225219                /* Hangup session to the console */
    226220                if (multim_dev->console_sess)
    227221                        async_hangup(multim_dev->console_sess);
    228                 const int ret = ddf_fun_unbind(multim_dev->fun);
     222                const int ret = ddf_fun_unbind(fun);
    229223                if (ret != EOK) {
    230224                        usb_log_error("Failed to unbind %s function.\n",
    231                             multim_dev->fun->name);
     225                            fun->name);
    232226                } else {
    233                         usb_log_debug2("%s unbound.\n", multim_dev->fun->name);
     227                        usb_log_debug2("%s unbound.\n", fun->name);
    234228                        /* This frees multim_dev too as it was stored in
    235229                         * fun->data */
    236                         ddf_fun_destroy(multim_dev->fun);
     230                        ddf_fun_destroy(fun);
    237231                }
    238         }
    239 }
    240 
    241 /*----------------------------------------------------------------------------*/
    242 
     232        } else {
     233                usb_log_error(
     234                    "Failed to deinit multimedia subdriver, data missing.\n");
     235        }
     236}
     237/*----------------------------------------------------------------------------*/
    243238bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev, void *data)
    244239{
    245240        // TODO: checks
    246         if (hid_dev == NULL || data == NULL) {
     241        ddf_fun_t *fun = data;
     242        if (hid_dev == NULL || fun == NULL || fun->driver_data == NULL) {
    247243                return false;
    248244        }
    249245
    250         usb_multimedia_t *multim_dev = data;
     246        usb_multimedia_t *multim_dev = fun->driver_data;
    251247
    252248        usb_hid_report_path_t *path = usb_hid_report_path();
     249        if (path == NULL)
     250                return true; /* This might be a temporary failure. */
     251
    253252        int ret =
    254253            usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
    255         if (ret != EOK)
     254        if (ret != EOK) {
     255                usb_hid_report_path_free(path);
    256256                return true; /* This might be a temporary failure. */
     257        }
    257258
    258259        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     
    263264            USB_HID_REPORT_TYPE_INPUT);
    264265
    265         /*! @todo Is this iterating OK if done multiple times?
    266          *  @todo The parsing is not OK
    267          */
     266        //FIXME Is this iterating OK if done multiple times?
     267        //FIXME The parsing is not OK. (what's wrong?)
    268268        while (field != NULL) {
    269                 if(field->value != 0) {
    270                         usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n", 
     269                if (field->value != 0) {
     270                        usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n",
    271271                            field->value, field->usage);
    272272                        const unsigned key =
     
    275275                            usbhid_multimedia_usage_to_str(field->usage);
    276276                        usb_log_info("Pressed key: %s\n", key_str);
    277                         usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS,
    278                                                key);
     277                        usb_multimedia_push_ev(multim_dev, KEY_PRESS, key);
    279278                }
    280279
     
    289288        return true;
    290289}
    291 
    292290/**
    293291 * @}
Note: See TracChangeset for help on using the changeset viewer.