Changeset 1c6c4092 in mainline for uspace/drv/usbhid/kbddev.c


Ignore:
Timestamp:
2011-03-01T16:39:31Z (15 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/fix-logger-deadlock, topic/msim-upgrade, topic/simplify-dev-export
Children:
0f31e2b, 494eaf7
Parents:
27270db
Message:

Properly destroying HID and KBD device structures.

+ Do not send LOCK keys to console.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/kbddev.c

    r27270db r1c6c4092  
    4141#include <io/keycode.h>
    4242#include <ipc/kbd.h>
     43#include <async.h>
    4344
    4445#include <usb/usb.h>
     
    253254        usb_log_debug2("\n\nmods after: 0x%x\n", kbd_dev->mods);
    254255        usb_log_debug2("\nLock keys after: 0x%x\n\n", kbd_dev->lock_keys);
     256       
     257        if (key = KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) {
     258                // do not send anything to the console, this is our business
     259                return;
     260        }
    255261       
    256262        if (type == KEY_PRESS && (kbd_dev->mods & KM_LCTRL) && key == KC_F1) {
     
    453459/*----------------------------------------------------------------------------*/
    454460
    455 static usbhid_kbd_t *usbhid_kbd_new()
     461static usbhid_kbd_t *usbhid_kbd_new(void)
    456462{
    457463        usbhid_kbd_t *kbd_dev =
     
    475481       
    476482        return kbd_dev;
     483}
     484
     485/*----------------------------------------------------------------------------*/
     486
     487static void usbhid_kbd_free(usbhid_kbd_t **kbd_dev)
     488{
     489        if (kbd_dev == NULL || *kbd_dev == NULL) {
     490                return;
     491        }
     492       
     493        // hangup phone to the console
     494        async_hangup((*kbd_dev)->console_phone);
     495       
     496        if ((*kbd_dev)->hid_dev != NULL) {
     497                usbhid_dev_free(&(*kbd_dev)->hid_dev);
     498                assert((*kbd_dev)->hid_dev == NULL);
     499        }
     500       
     501        free(*kbd_dev);
     502        *kbd_dev = NULL;
    477503}
    478504
     
    623649
    624650        usbhid_kbd_poll(kbd_dev);
     651       
     652        // at the end, properly destroy the KBD structure
     653        usbhid_kbd_free(&kbd_dev);
     654        assert(kbd_dev == NULL);
    625655
    626656        return EOK;
     
    645675         * Initialize device (get and process descriptors, get address, etc.)
    646676         */
    647         usb_log_info("Initializing USB HID/KBD device...\n");
     677        usb_log_info("Initializing USB/HID KBD device...\n");
    648678       
    649679        usbhid_kbd_t *kbd_dev = usbhid_kbd_new();
    650680        if (kbd_dev == NULL) {
    651                 usb_log_error("Error while creating USB HID/KBD device "
     681                usb_log_error("Error while creating USB/HID KBD device "
    652682                    "structure.\n");
    653683                ddf_fun_destroy(kbd_fun);
     
    658688       
    659689        if (rc != EOK) {
    660                 usb_log_error("Failed to initialize USB HID/KBD device.\n");
     690                usb_log_error("Failed to initialize USB/HID KBD device.\n");
    661691                ddf_fun_destroy(kbd_fun);
     692                usbhid_kbd_free(&kbd_dev);
    662693                return rc;
    663694        }       
    664695       
    665         usb_log_info("USB/KBD device structure initialized.\n");
     696        usb_log_info("USB/HID KBD device structure initialized.\n");
    666697       
    667698        /*
     
    675706        if (rc != EOK) {
    676707                usb_log_error("Could not bind DDF function.\n");
     708                // TODO: Can / should I destroy the DDF function?
     709                ddf_fun_destroy(kbd_fun);
     710                usbhid_kbd_free(&kbd_dev);
    677711                return rc;
    678712        }
     
    682716                usb_log_error("Could not add DDF function to class 'keyboard'"
    683717                    "\n");
     718                // TODO: Can / should I destroy the DDF function?
     719                ddf_fun_destroy(kbd_fun);
     720                usbhid_kbd_free(&kbd_dev);
    684721                return rc;
    685722        }
     
    690727        fid_t fid = fibril_create(usbhid_kbd_fibril, kbd_dev);
    691728        if (fid == 0) {
    692                 usb_log_error("Failed to start fibril for HID device\n");
     729                usb_log_error("Failed to start fibril for KBD device\n");
    693730                return ENOMEM;
    694731        }
Note: See TracChangeset for help on using the changeset viewer.