Changeset a8c4e871 in mainline


Ignore:
Timestamp:
2011-10-15T14:09:14Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce2a1c2
Parents:
a044f71
Message:

usb: use _deinit suffix for functions that do not destroy/free their argument

usbhid: don't use heap allocated report praser
random whitespace fixes

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkbd/main.c

    ra044f71 ra8c4e871  
    6969        int rc = usb_hid_report_init(*report);
    7070        if (rc != EOK) {
    71                 usb_hid_free_report(*report);
     71                usb_hid_report_deinit(*report);
    7272                *report = NULL;
    7373                return rc;
     
    7979            &report_desc_size);
    8080        if (rc != EOK) {
    81                 usb_hid_free_report(*report);
     81                usb_hid_report_deinit(*report);
    8282                *report = NULL;
    8383                return rc;
     
    8585       
    8686        if (report_desc_size == 0) {
    87                 usb_hid_free_report(*report);
     87                usb_hid_report_deinit(*report);
    8888                *report = NULL;
    8989                // TODO: other error code?
     
    9393        uint8_t *desc = (uint8_t *) malloc(report_desc_size);
    9494        if (desc == NULL) {
    95                 usb_hid_free_report(*report);
     95                usb_hid_report_deinit(*report);
    9696                *report = NULL;
    9797                return ENOMEM;
     
    103103            &actual_size);
    104104        if (rc != EOK) {
    105                 usb_hid_free_report(*report);
     105                usb_hid_report_deinit(*report);
    106106                *report = NULL;
    107107                free(desc);
     
    110110       
    111111        if (actual_size != report_desc_size) {
    112                 usb_hid_free_report(*report);
     112                usb_hid_report_deinit(*report);
    113113                *report = NULL;
    114114                free(desc);
  • uspace/app/usbinfo/hid.c

    ra044f71 ra8c4e871  
    167167
    168168        free(raw_report);
    169         usb_hid_free_report(&report);
     169        usb_hid_report_deinit(&report);
    170170}
    171171
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.c

    ra044f71 ra8c4e871  
    237237
    238238        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    239             hid_dev->report, NULL, kbd_dev->led_path,
     239            &hid_dev->report, NULL, kbd_dev->led_path,
    240240            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    241241            USB_HID_REPORT_TYPE_OUTPUT);
    242242
    243243        while (field != NULL) {
    244                
    245                 if ((field->usage == USB_HID_LED_NUM_LOCK) 
     244
     245                if ((field->usage == USB_HID_LED_NUM_LOCK)
    246246                    && (kbd_dev->mods & KM_NUM_LOCK)){
    247247                        field->value = 1;
    248248                }
    249249
    250                 if ((field->usage == USB_HID_LED_CAPS_LOCK) 
     250                if ((field->usage == USB_HID_LED_CAPS_LOCK)
    251251                    && (kbd_dev->mods & KM_CAPS_LOCK)){
    252252                        field->value = 1;
    253253                }
    254254
    255                 if ((field->usage == USB_HID_LED_SCROLL_LOCK) 
     255                if ((field->usage == USB_HID_LED_SCROLL_LOCK)
    256256                    && (kbd_dev->mods & KM_SCROLL_LOCK)){
    257257                        field->value = 1;
    258258                }
    259                
    260                 field = usb_hid_report_get_sibling(hid_dev->report, field,
    261                     kbd_dev->led_path, 
    262                 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    263                         USB_HID_REPORT_TYPE_OUTPUT);
     259
     260                field = usb_hid_report_get_sibling(
     261                    &hid_dev->report, field, kbd_dev->led_path,
     262                USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     263                    USB_HID_REPORT_TYPE_OUTPUT);
    264264        }
    265265
    266266        // TODO: what about the Report ID?
    267         int rc = usb_hid_report_output_translate(hid_dev->report, 0,
     267        int rc = usb_hid_report_output_translate(&hid_dev->report, 0,
    268268            kbd_dev->output_buffer, kbd_dev->output_size);
    269269
     
    432432static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev)
    433433{
    434         assert(hid_dev->report != NULL);
    435434        assert(hid_dev != NULL);
    436435        assert(kbd_dev != NULL);
     
    444443
    445444        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    446             hid_dev->report, NULL, path,
    447             USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
     445            &hid_dev->report, NULL, path,
     446            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    448447            USB_HID_REPORT_TYPE_INPUT);
    449448        unsigned i = 0;
     
    454453               
    455454                assert(i < kbd_dev->key_count);
    456                
     455
    457456                // save the key usage
    458457                if (field->value != 0) {
     
    463462                }
    464463                usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]);
    465                
     464
    466465                ++i;
    467                 field = usb_hid_report_get_sibling(hid_dev->report, field, path,
    468                     USB_HID_PATH_COMPARE_END
    469                     | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     466                field = usb_hid_report_get_sibling(
     467                    &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     468                        | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    470469                    USB_HID_REPORT_TYPE_INPUT);
    471470        }
     
    616615
    617616        kbd_dev->key_count = usb_hid_report_size(
    618             hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
     617            &hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
    619618        usb_hid_report_path_free(path);
    620619
    621620        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    622621
    623         kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
     622        kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));
    624623
    625624        if (kbd_dev->keys == NULL) {
     
    643642         */
    644643        kbd_dev->output_size = 0;
    645         kbd_dev->output_buffer = usb_hid_report_output(hid_dev->report,
     644        kbd_dev->output_buffer = usb_hid_report_output(&hid_dev->report,
    646645            &kbd_dev->output_size, 0);
    647646        if (kbd_dev->output_buffer == NULL) {
     
    657656            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    658657
    659         kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report,
    660             0, USB_HID_REPORT_TYPE_OUTPUT);
     658        kbd_dev->led_output_size = usb_hid_report_size(
     659            &hid_dev->report, 0, USB_HID_REPORT_TYPE_OUTPUT);
    661660
    662661        usb_log_debug("Output report size (in items): %zu\n",
     
    826825int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev)
    827826{
    828         int rc = usb_hid_parse_report_descriptor(hid_dev->report,
    829             USB_KBD_BOOT_REPORT_DESCRIPTOR,
     827        int rc = usb_hid_parse_report_descriptor(
     828            &hid_dev->report, USB_KBD_BOOT_REPORT_DESCRIPTOR,
    830829            USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE);
    831830
     
    836835        }
    837836
    838         rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 
     837        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
    839838            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    840839
  • uspace/drv/bus/usb/usbhid/main.c

    ra044f71 ra8c4e871  
    9292        if (rc != EOK) {
    9393                usb_log_error("Failed to initialize USB/HID device.\n");
    94                 usb_hid_destroy(hid_dev);
     94                usb_hid_deinit(hid_dev);
    9595                return rc;
    9696        }
     
    128128                usb_log_error("Failed to start polling fibril for `%s'.\n",
    129129                    dev->ddf_dev->name);
    130                 usb_hid_destroy(hid_dev);
     130                usb_hid_deinit(hid_dev);
    131131                return rc;
    132132        }
    133133        hid_dev->running = true;
    134         dev->driver_data = hid_dev;
    135134
    136135        /*
     
    204203
    205204        assert(!hid_dev->running);
    206         usb_hid_destroy(hid_dev);
     205        usb_hid_deinit(hid_dev);
    207206        usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name);
    208207        return EOK;
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    ra044f71 ra8c4e871  
    268268
    269269        int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
    270             hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     270            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    271271        int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
    272             hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     272            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    273273        int wheel = get_mouse_axis_move_value(hid_dev->report_id,
    274             hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     274            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    275275
    276276        if ((shift_x != 0) || (shift_y != 0)) {
    277                 async_exch_t *exch = async_exchange_begin(mouse_dev->mouse_sess);
     277                async_exch_t *exch =
     278                    async_exchange_begin(mouse_dev->mouse_sess);
    278279                async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
    279280                async_exchange_end(exch);
     
    291292
    292293        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    293             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    294             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    295             USB_HID_REPORT_TYPE_INPUT);
     294            &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     295            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, USB_HID_REPORT_TYPE_INPUT);
    296296
    297297        while (field != NULL) {
     
    314314                        async_req_2_0(exch, MOUSEEV_BUTTON_EVENT, field->usage, 0);
    315315                        async_exchange_end(exch);
    316                        
     316
    317317                        mouse_dev->buttons[field->usage - field->usage_minimum] =
    318318                           field->value;
    319319                }
    320                
     320
    321321                field = usb_hid_report_get_sibling(
    322                     hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    323                     | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
     322                    &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     323                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    324324                    USB_HID_REPORT_TYPE_INPUT);
    325325        }
     
    474474        // that the current solution is good enough.
    475475        /* Adding 1 because we will be accessing buttons[highest]. */
    476         mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report,
    477             hid_dev->report_id) + 1;
     476        mouse_dev->buttons_count = 1 + usb_mouse_get_highest_button(
     477            &hid_dev->report, hid_dev->report_id);
    478478        mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    479479
     
    532532int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev)
    533533{
    534         int rc = usb_hid_parse_report_descriptor(hid_dev->report,
    535             USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
     534        int rc = usb_hid_parse_report_descriptor(
     535            &hid_dev->report, USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
    536536            USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
    537537
     
    542542        }
    543543
    544         rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 
     544        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
    545545            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    546546
  • uspace/drv/bus/usb/usbhid/multimedia/multimedia.c

    ra044f71 ra8c4e871  
    272272
    273273        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    274             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    275             | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
     274            &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     275            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    276276            USB_HID_REPORT_TYPE_INPUT);
    277277
     
    293293
    294294                field = usb_hid_report_get_sibling(
    295                     hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
     295                    &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    296296                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    297297                    USB_HID_REPORT_TYPE_INPUT);
  • uspace/drv/bus/usb/usbhid/usbhid.c

    ra044f71 ra8c4e871  
    204204        }
    205205
    206         assert(hid_dev->report != NULL);
    207 
    208206        usb_log_debug("Compare flags: %d\n", mapping->compare);
    209207
     
    213211        do {
    214212                usb_log_debug("Trying report id %u\n", report_id);
    215                
     213
    216214                if (report_id != 0) {
    217215                        usb_hid_report_path_set_report_id(usage_path,
     
    220218
    221219                usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    222                     hid_dev->report,
    223                     NULL, usage_path, mapping->compare,
     220                    &hid_dev->report, NULL, usage_path, mapping->compare,
    224221                    USB_HID_REPORT_TYPE_INPUT);
    225                
     222
    226223                usb_log_debug("Field: %p\n", field);
    227224
     
    230227                        break;
    231228                }
    232                
     229
    233230                report_id = usb_hid_get_next_report_id(
    234                     hid_dev->report, report_id,
    235                     USB_HID_REPORT_TYPE_INPUT);
     231                    &hid_dev->report, report_id, USB_HID_REPORT_TYPE_INPUT);
    236232        } while (!matches && report_id != 0);
    237233
     
    378374static int usb_hid_init_report(usb_hid_dev_t *hid_dev)
    379375{
    380         assert(hid_dev != NULL && hid_dev->report != NULL);
     376        assert(hid_dev != NULL);
    381377
    382378        uint8_t report_id = 0;
    383         size_t size;
    384 
    385379        size_t max_size = 0;
    386380
    387381        do {
    388382                usb_log_debug("Getting size of the report.\n");
    389                 size = usb_hid_report_byte_size(hid_dev->report, report_id,
    390                     USB_HID_REPORT_TYPE_INPUT);
     383                const size_t size =
     384                    usb_hid_report_byte_size(&hid_dev->report, report_id,
     385                        USB_HID_REPORT_TYPE_INPUT);
    391386                usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);
    392387                max_size = (size > max_size) ? size : max_size;
    393388                usb_log_debug("Getting next report ID\n");
    394                 report_id = usb_hid_get_next_report_id(hid_dev->report,
     389                report_id = usb_hid_get_next_report_id(&hid_dev->report,
    395390                    report_id, USB_HID_REPORT_TYPE_INPUT);
    396391        } while (report_id != 0);
     
    430425        }
    431426
    432         hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
    433             usb_hid_report_t)));
    434         if (hid_dev->report == NULL) {
    435                 usb_log_error("No memory!\n");
    436                 return ENOMEM;
    437         }
    438         usb_hid_report_init(hid_dev->report);
     427        usb_hid_report_init(&hid_dev->report);
    439428
    440429        /* The USB device should already be initialized, save it in structure */
     
    446435                return rc;
    447436        }
    448                
     437
    449438        /* Get the report descriptor and parse it. */
    450         rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 
    451             hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
     439        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
     440            &hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
    452441
    453442        bool fallback = false;
     
    524513                        }
    525514                }
    526                
     515
    527516                rc = (ok) ? EOK : -1;   // what error to report
    528517        }
     
    570559        // parse the input report
    571560
    572         int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
     561        int rc = usb_hid_parse_report(&hid_dev->report, buffer, buffer_size,
    573562            &hid_dev->report_id);
    574563
     
    576565                usb_log_warning("Error in usb_hid_parse_report():"
    577566                    "%s\n", str_error(rc));
    578         }       
     567        }
    579568
    580569        bool cont = false;
     
    631620/*----------------------------------------------------------------------------*/
    632621
    633 void usb_hid_destroy(usb_hid_dev_t *hid_dev)
     622void usb_hid_deinit(usb_hid_dev_t *hid_dev)
    634623{
    635624        int i;
     
    657646
    658647        /* Destroy the parser */
    659         if (hid_dev->report != NULL) {
    660                 usb_hid_free_report(hid_dev->report);
    661         }
     648        usb_hid_report_deinit(&hid_dev->report);
    662649
    663650}
  • uspace/drv/bus/usb/usbhid/usbhid.h

    ra044f71 ra8c4e871  
    119119
    120120        /** HID Report parser. */
    121         usb_hid_report_t *report;
     121        usb_hid_report_t report;
    122122
    123123        uint8_t report_id;
     
    146146
    147147int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
     148void usb_hid_deinit(usb_hid_dev_t *hid_dev);
    148149
    149 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
    150     size_t buffer_size, void *arg);
     150bool usb_hid_polling_callback(usb_device_t *dev,
     151    uint8_t *buffer, size_t buffer_size, void *arg);
    151152
    152 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
    153      void *arg);
     153void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg);
    154154
    155155void usb_hid_new_report(usb_hid_dev_t *hid_dev);
    156156
    157157int usb_hid_report_number(usb_hid_dev_t *hid_dev);
    158 
    159 void usb_hid_destroy(usb_hid_dev_t *hid_dev);
    160158
    161159#endif /* USB_HID_USBHID_H_ */
  • uspace/lib/usbhid/include/usb/hid/hiddescriptor.h

    ra044f71 ra8c4e871  
    4242#include <usb/hid/hidtypes.h>
    4343
    44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 
     44int usb_hid_parse_report_descriptor(usb_hid_report_t *report,
    4545                const uint8_t *data, size_t size);
    46 
    47 void usb_hid_free_report(usb_hid_report_t *report);
    4846
    4947void usb_hid_descriptor_print(usb_hid_report_t *report);
    5048
    5149int usb_hid_report_init(usb_hid_report_t *report);
     50
     51void usb_hid_report_deinit(usb_hid_report_t *report);
    5252
    5353int usb_hid_report_append_fields(usb_hid_report_t *report,
  • uspace/lib/usbhid/src/hiddescriptor.c

    ra044f71 ra8c4e871  
    10161016 * @return void
    10171017 */
    1018 void usb_hid_free_report(usb_hid_report_t *report)
     1018void usb_hid_report_deinit(usb_hid_report_t *report)
    10191019{
    10201020        if(report == NULL){
Note: See TracChangeset for help on using the changeset viewer.