Changeset 065064e6 in mainline for uspace/drv/bus/usb/usbhid/usbhid.c


Ignore:
Timestamp:
2011-10-15T12:49:18Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3f7418
Parents:
7c95d6f5
Message:

usb: Add and use usb_device_data_alloc.

Inspired by ddf_dev_data_alloc and ddf_fun_data_alloc.
Fix possible double free (hid dev and hid fun shared driver_data).

File:
1 edited

Legend:

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

    r7c95d6f5 r065064e6  
    412412/*----------------------------------------------------------------------------*/
    413413
    414 usb_hid_dev_t *usb_hid_new(void)
    415 {
    416         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)calloc(1,
    417             sizeof(usb_hid_dev_t));
     414int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
     415{
     416        int rc, i;
     417
     418        usb_log_debug("Initializing HID structure...\n");
    418419
    419420        if (hid_dev == NULL) {
    420                 usb_log_error("No memory!\n");
    421                 return NULL;
     421                usb_log_error("Failed to init HID structure: no structure given"
     422                    ".\n");
     423                return EINVAL;
     424        }
     425
     426        if (dev == NULL) {
     427                usb_log_error("Failed to init HID structure: no USB device"
     428                    " given.\n");
     429                return EINVAL;
    422430        }
    423431
     
    426434        if (hid_dev->report == NULL) {
    427435                usb_log_error("No memory!\n");
    428                 free(hid_dev);
    429                 return NULL;
    430         }
    431 
    432         hid_dev->poll_pipe_index = -1;
    433 
    434         return hid_dev;
    435 }
    436 
    437 /*----------------------------------------------------------------------------*/
    438 
    439 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    440 {
    441         int rc, i;
    442 
    443         usb_log_debug("Initializing HID structure...\n");
    444 
    445         if (hid_dev == NULL) {
    446                 usb_log_error("Failed to init HID structure: no structure given"
    447                     ".\n");
    448                 return EINVAL;
    449         }
    450 
    451         if (dev == NULL) {
    452                 usb_log_error("Failed to init HID structure: no USB device"
    453                     " given.\n");
    454                 return EINVAL;
    455         }
    456 
     436                return ENOMEM;
     437        }
    457438        usb_hid_report_init(hid_dev->report);
    458439
    459440        /* The USB device should already be initialized, save it in structure */
    460441        hid_dev->usb_dev = dev;
     442        hid_dev->poll_pipe_index = -1;
    461443
    462444        rc = usb_hid_check_pipes(hid_dev, dev);
Note: See TracChangeset for help on using the changeset viewer.