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

Changeset 3dc3f99 in mainline


Ignore:
Timestamp:
2018-01-07T01:59:06Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
Children:
ecbad17
Parents:
5e2b1ae6
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-07 01:57:29)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-07 01:59:06)
Message:

usbhost: inline get_free_address

As it's now used only once, it is not necessary to split this much.

Also, removed some afterchecks. There's no reason to assert results of
simple code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/usb2_bus.c

    r5e2b1ae6 r3dc3f99  
    5757}
    5858
    59 /** Get a free USB address
    60  *
    61  * @param[in] bus Device manager structure to use.
    62  * @return Free address, or error code.
    63  */
    64 static int get_free_address(usb2_bus_t *bus, usb_address_t *addr)
    65 {
     59/** Unregister and destroy all endpoints using given address.
     60 * @param bus usb_bus structure, non-null.
     61 * @param address USB address.
     62 * @param endpoint USB endpoint number.
     63 * @param direction Communication direction.
     64 * @return Error code.
     65 */
     66static int release_address(usb2_bus_t *bus, usb_address_t address)
     67{
     68        if (!usb_address_is_valid(address))
     69                return EINVAL;
     70
     71        const int ret = bus->address_occupied[address] ? EOK : ENOENT;
     72        bus->address_occupied[address] = false;
     73        return ret;
     74}
     75
     76/** Request USB address.
     77 * @param bus usb_device_manager
     78 * @param addr Pointer to requested address value, place to store new address
     79 * @return Error code.
     80 * @note Default address is only available in strict mode.
     81 */
     82static int request_address(usb2_bus_t *bus, usb_address_t *addr)
     83{
     84        // Find a free address
    6685        usb_address_t new_address = bus->last_address;
    6786        do {
     
    7291                        return ENOSPC;
    7392        } while (bus->address_occupied[new_address]);
    74 
    75         assert(new_address != USB_ADDRESS_DEFAULT);
    7693        bus->last_address = new_address;
    7794
    7895        *addr = new_address;
    79         return EOK;
    80 }
    81 
    82 /** Unregister and destroy all endpoints using given address.
    83  * @param bus usb_bus structure, non-null.
    84  * @param address USB address.
    85  * @param endpoint USB endpoint number.
    86  * @param direction Communication direction.
    87  * @return Error code.
    88  */
    89 static int release_address(usb2_bus_t *bus, usb_address_t address)
    90 {
    91         if (!usb_address_is_valid(address))
    92                 return EINVAL;
    93 
    94         const int ret = bus->address_occupied[address] ? EOK : ENOENT;
    95         bus->address_occupied[address] = false;
    96         return ret;
    97 }
    98 
    99 /** Request USB address.
    100  * @param bus usb_device_manager
    101  * @param addr Pointer to requested address value, place to store new address
    102  * @return Error code.
    103  * @note Default address is only available in strict mode.
    104  */
    105 static int request_address(usb2_bus_t *bus, usb_address_t *addr)
    106 {
    107         int err;
    108 
    109         assert(bus);
    110         assert(addr);
    111 
    112         if (!usb_address_is_valid(*addr))
    113                 return EINVAL;
    114 
    115         if ((err = get_free_address(bus, addr)))
    116                 return err;
    117 
    118         assert(usb_address_is_valid(*addr));
    119         assert(bus->address_occupied[*addr] == false);
    120         assert(*addr != USB_ADDRESS_DEFAULT);
    121 
    12296        bus->address_occupied[*addr] = true;
    12397
Note: See TracChangeset for help on using the changeset viewer.