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

Changeset fc3dfe6d in mainline


Ignore:
Timestamp:
2018-02-11T17:18:17Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial
Children:
d345ce2
Parents:
239eea41
git-author:
Ondřej Hlavatý <aearsis@…> (2018-02-10 22:16:55)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-02-11 17:18:17)
Message:

usb: fix relying on negative errnos

Location:
uspace/lib/usbhost
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/bus.h

    r239eea41 rfc3dfe6d  
    157157    usbhc_iface_transfer_callback_t, void *, const char *);
    158158
    159 ssize_t bus_device_send_batch_sync(device_t *, usb_target_t,
     159errno_t bus_device_send_batch_sync(device_t *, usb_target_t,
    160160    usb_direction_t direction, char *, size_t, uint64_t,
    161     const char *);
     161    const char *, size_t *);
    162162
    163163int bus_endpoint_add(device_t *, const usb_endpoint_descriptors_t *, endpoint_t **);
  • uspace/lib/usbhost/src/bus.c

    r239eea41 rfc3dfe6d  
    646646 * @param name Communication identifier (for nicer output).
    647647 */
    648 ssize_t bus_device_send_batch_sync(device_t *device, usb_target_t target,
     648errno_t bus_device_send_batch_sync(device_t *device, usb_target_t target,
    649649    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
    650     const char *name)
     650    const char *name, size_t *transferred_size)
    651651{
    652652        sync_data_t sd = { .done = false };
     
    668668        fibril_mutex_unlock(&sd.done_mtx);
    669669
    670         return (sd.error == EOK)
    671                 ? (ssize_t) sd.transferred_size
    672                 : (ssize_t) sd.error;
     670        if (transferred_size)
     671                *transferred_size = sd.transferred_size;
     672
     673        return sd.error;
    673674}
    674675
  • uspace/lib/usbhost/src/usb2_bus.c

    r239eea41 rfc3dfe6d  
    140140        usb_log_debug("Device(%d): Setting USB address.", address);
    141141        err = bus_device_send_batch_sync(dev, usb2_default_target, USB_DIRECTION_OUT,
    142             NULL, 0, *(uint64_t *)&set_address, "set address");
    143         if (err != 0) {
     142            NULL, 0, *(uint64_t *)&set_address, "set address", NULL);
     143        if (err) {
    144144                usb_log_error("Device(%d): Failed to set new address: %s.",
    145145                    address, str_error(err));
  • uspace/lib/usbhost/src/utility.c

    r239eea41 rfc3dfe6d  
    9494
    9595        usb_log_debug("Requesting first 8B of device descriptor to determine MPS.");
    96         ssize_t got = bus_device_send_batch_sync(dev, control_ep, USB_DIRECTION_IN,
    97             (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
    98             "read first 8 bytes of dev descriptor");
     96        size_t got;
     97        const errno_t err = bus_device_send_batch_sync(dev, control_ep,
     98            USB_DIRECTION_IN, (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE,
     99            *(uint64_t *)&get_device_desc_8,
     100            "read first 8 bytes of dev descriptor", &got);
    99101
    100102        if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
    101                 const int err = got < 0 ? got : EOVERFLOW;
    102103                usb_log_error("Failed to get 8B of dev descr: %s.", str_error(err));
    103104                return err;
     
    133134        usb_log_debug("Device(%d): Requesting full device descriptor.",
    134135            device->address);
    135         ssize_t got = bus_device_send_batch_sync(device, control_ep, USB_DIRECTION_IN,
    136             (char *) desc, sizeof(*desc), *(uint64_t *)&get_device_desc,
    137             "read device descriptor");
    138 
    139         if (got < 0)
    140                 return got;
    141 
    142         return got == sizeof(*desc) ? EOK : EOVERFLOW;
     136        size_t got;
     137        errno_t err = bus_device_send_batch_sync(device, control_ep,
     138            USB_DIRECTION_IN, (char *) desc, sizeof(*desc),
     139            *(uint64_t *)&get_device_desc, "read device descriptor", &got);
     140
     141        if (!err && got != sizeof(*desc))
     142                err = EOVERFLOW;
     143
     144        return err;
    143145}
    144146
     
    164166        usb_log_debug("Device(%d): Requesting hub descriptor.",
    165167            device->address);
    166         ssize_t got = bus_device_send_batch_sync(device, control_ep, USB_DIRECTION_IN,
    167             (char *) desc, sizeof(*desc), *(uint64_t *)&get_hub_desc,
    168             "get hub descriptor");
    169 
    170         if (got < 0)
    171                 return got;
    172 
    173         return got == sizeof(*desc) ? EOK : EOVERFLOW;
     168
     169        size_t got;
     170        errno_t err = bus_device_send_batch_sync(device, control_ep,
     171            USB_DIRECTION_IN, (char *) desc, sizeof(*desc),
     172            *(uint64_t *)&get_hub_desc, "get hub descriptor", &got);
     173
     174        if (!err && got != sizeof(*desc))
     175                err = EOVERFLOW;
     176
     177        return err;
    174178}
    175179
Note: See TracChangeset for help on using the changeset viewer.