Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 44d8853 in mainline


Ignore:
Timestamp:
2011-01-28T23:51:36Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial
Children:
4046c1ea, c8ca07e
Parents:
e68de30
Message:

Fixed: Do not crash on zero buffers

Location:
uspace/drv/uhci
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/callback.c

    re68de30 r44d8853  
    99        assert(instance);
    1010        assert(func_in == NULL || func_out == NULL);
    11         instance->new_buffer = malloc32(size);
    12         if (!instance->new_buffer) {
    13                 uhci_print_error("Failed to allocate device acessible buffer.\n");
    14                 return ENOMEM;
     11        if (size > 0) {
     12                instance->new_buffer = malloc32(size);
     13                if (!instance->new_buffer) {
     14                        uhci_print_error("Failed to allocate device acessible buffer.\n");
     15                        return ENOMEM;
     16                }
     17                if (func_out)
     18                        memcpy(instance->new_buffer, buffer, size);
     19        } else {
     20                instance->new_buffer = NULL;
    1521        }
    1622
    17         if (func_out)
    18                 memcpy(instance->new_buffer, buffer, size);
    1923
    2024        instance->callback_out = func_out;
  • uspace/drv/uhci/uhci.c

    re68de30 r44d8853  
    175175        assert(instance);
    176176
     177        uhci_print_verbose("Appending a new transfer to queue.\n");
    177178        ret = transfer_list_append(&instance->transfers[transfer_type], td);
    178179        CHECK_RET_TRANS_FREE_JOB_TD("Failed to append transfer descriptor.\n");
     
    226227                uint16_t reg;
    227228                reg = pio_read_16(&instance->registers->usbcmd);
    228                 uhci_print_verbose("Command register: %X\n", reg);
     229                uhci_print_info("Command register: %X\n", reg);
    229230                reg = pio_read_16(&instance->registers->usbsts);
    230                 uhci_print_verbose("Status register: %X\n", reg);
     231                uhci_print_info("Status register: %X\n", reg);
    231232/*
    232233                uintptr_t frame_list = pio_read_32(&instance->registers->flbaseadd);
  • uspace/drv/uhci/uhci_struct/transfer_descriptor.c

    re68de30 r44d8853  
    2727        uhci_print_verbose("Creating device field: %x.\n", instance->device);
    2828
    29         instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
     29        if (size) {
     30                instance->buffer_ptr = (uintptr_t)addr_to_phys(buffer);
    3031
    31         uhci_print_verbose("Creating buffer field: %p(%p).\n",
    32           buffer, instance->buffer_ptr);
     32                uhci_print_verbose("Creating buffer field: %p(%p).\n",
     33                        buffer, instance->buffer_ptr);
    3334
    34         char * buff = buffer;
     35                if (size >= 8) {
     36                        char * buff = buffer;
    3537
    36         uhci_print_verbose("Buffer dump(8B): %x %x %x %x %x %x %x %x.\n",
    37           buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6], buff[7]);
     38                        uhci_print_verbose("Buffer dump(8B): %x %x %x %x %x %x %x %x.\n",
     39                                buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6], buff[7]);
     40                }
     41        } else {
     42                instance->buffer_ptr = 0;
     43        }
    3844
    3945        instance->next_va = NULL;
    4046        instance->callback = NULL;
     47        uhci_print_info("Created a new TD.\n");
    4148}
    4249
     
    7481        callback_run(instance->callback,
    7582                convert_outcome(instance->status),
    76                 instance->status >> TD_STATUS_ACTLEN_POS & TD_STATUS_ACTLEN_MASK
     83                ((instance->status >> TD_STATUS_ACTLEN_POS) + 1) & TD_STATUS_ACTLEN_MASK
    7784        );
    7885}
Note: See TracChangeset for help on using the changeset viewer.