Tried to untangle mixing of int, enum libusb_error, kern_return_t, and IOReturn.
authorSean McBride <sean@rogue-research.com>
Sat, 15 Dec 2018 21:26:14 +0000 (16:26 -0500)
committerNathan Hjelm <hjelmn@me.com>
Wed, 9 Jan 2019 01:10:37 +0000 (18:10 -0700)
- Replace all kern_return_t with IOReturn, they are basically the same, but IOReturn is more common in IOUSBLib
- improve consistency by using the name 'kresult' for all IOReturn-type results, and not using that name for libusb_error return values.
- changed a few functions to use real 'bool' (this file already uses C99)
- replaced some raw '0's with LIBUSB_SUCCESS or kIOReturnSuccess.
- replaced some raw 'int's with either IOReturn or enum libusb_error.
- replaced ambiguous "if (kresult)" with more explicit "if (kresult != kIOReturnSuccess)"
- replaced incorrect use of darwin_to_libusb with darwin_transfer_status

Most of these were found by increasing the compiler warning level.

Closes #510

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
libusb/os/darwin_usb.c

index 46f66ff..2eb57c7 100644 (file)
@@ -98,11 +98,11 @@ static int darwin_release_interface(struct libusb_device_handle *dev_handle, int
 static int darwin_reset_device(struct libusb_device_handle *dev_handle);
 static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0);
 
-static int darwin_scan_devices(struct libusb_context *ctx);
-static int process_new_device (struct libusb_context *ctx, io_service_t service);
+static enum libusb_error darwin_scan_devices(struct libusb_context *ctx);
+static enum libusb_error process_new_device (struct libusb_context *ctx, io_service_t service);
 
 #if defined(ENABLE_LOGGING)
-static const char *darwin_error_str (int result) {
+static const char *darwin_error_str (IOReturn result) {
   static char string_buffer[50];
   switch (result) {
   case kIOReturnSuccess:
@@ -142,7 +142,7 @@ static const char *darwin_error_str (int result) {
 }
 #endif
 
-static int darwin_to_libusb (int result) {
+static enum libusb_error darwin_to_libusb (IOReturn result) {
   switch (result) {
   case kIOReturnUnderrun:
   case kIOReturnSuccess:
@@ -208,7 +208,7 @@ static int ep_to_pipeRef(struct libusb_device_handle *dev_handle, uint8_t ep, ui
             *interface_out = cInterface;
 
           usbi_dbg ("pipe %d on interface %d matches", *pipep, iface);
-          return 0;
+          return LIBUSB_SUCCESS;
         }
       }
     }
@@ -220,7 +220,7 @@ static int ep_to_pipeRef(struct libusb_device_handle *dev_handle, uint8_t ep, ui
   return LIBUSB_ERROR_NOT_FOUND;
 }
 
-static int usb_setup_device_iterator (io_iterator_t *deviceIterator, UInt32 location) {
+static IOReturn usb_setup_device_iterator (io_iterator_t *deviceIterator, UInt32 location) {
   CFMutableDictionaryRef matchingDict = IOServiceMatching(darwin_device_class);
 
   if (!matchingDict)
@@ -252,24 +252,25 @@ static int usb_setup_device_iterator (io_iterator_t *deviceIterator, UInt32 loca
 }
 
 /* Returns 1 on success, 0 on failure. */
-static int get_ioregistry_value_number (io_service_t service, CFStringRef property, CFNumberType type, void *p) {
+static bool get_ioregistry_value_number (io_service_t service, CFStringRef property, CFNumberType type, void *p) {
   CFTypeRef cfNumber = IORegistryEntryCreateCFProperty (service, property, kCFAllocatorDefault, 0);
-  int ret = 0;
+  Boolean success = 0;
 
   if (cfNumber) {
     if (CFGetTypeID(cfNumber) == CFNumberGetTypeID()) {
-      ret = CFNumberGetValue(cfNumber, type, p);
+      success = CFNumberGetValue(cfNumber, type, p);
     }
 
     CFRelease (cfNumber);
   }
 
-  return ret;
+  return (success != 0);
 }
 
-static int get_ioregistry_value_data (io_service_t service, CFStringRef property, ssize_t size, void *p) {
+/* Returns 1 on success, 0 on failure. */
+static bool get_ioregistry_value_data (io_service_t service, CFStringRef property, ssize_t size, void *p) {
   CFTypeRef cfData = IORegistryEntryCreateCFProperty (service, property, kCFAllocatorDefault, 0);
-  int ret = 0;
+  bool success = false;
 
   if (cfData) {
     if (CFGetTypeID (cfData) == CFDataGetTypeID ()) {
@@ -279,28 +280,28 @@ static int get_ioregistry_value_data (io_service_t service, CFStringRef property
       }
 
       CFDataGetBytes (cfData, CFRangeMake(0, size), p);
-      ret = 1;
+      success = true;
     }
 
     CFRelease (cfData);
   }
 
-  return ret;
+  return success;
 }
 
 static usb_device_t **darwin_device_from_service (io_service_t service)
 {
   io_cf_plugin_ref_t *plugInInterface = NULL;
   usb_device_t **device;
-  kern_return_t result;
+  IOReturn kresult;
   SInt32 score;
 
-  result = IOCreatePlugInInterfaceForService(service, kIOUSBDeviceUserClientTypeID,
-                                             kIOCFPlugInInterfaceID, &plugInInterface,
-                                             &score);
+  kresult = IOCreatePlugInInterfaceForService(service, kIOUSBDeviceUserClientTypeID,
+                                              kIOCFPlugInInterfaceID, &plugInInterface,
+                                              &score);
 
-  if (kIOReturnSuccess != result || !plugInInterface) {
-    usbi_dbg ("could not set up plugin for service: %s", darwin_error_str (result));
+  if (kIOReturnSuccess != kresult || !plugInInterface) {
+    usbi_dbg ("could not set up plugin for service: %s", darwin_error_str (kresult));
     return NULL;
   }
 
@@ -567,7 +568,7 @@ static int darwin_get_device_descriptor(struct libusb_device *dev, unsigned char
 
   *host_endian = 0;
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
 static int get_configuration_index (struct libusb_device *dev, int config_value) {
@@ -635,12 +636,12 @@ static int darwin_get_config_descriptor(struct libusb_device *dev, uint8_t confi
 }
 
 /* check whether the os has configured the device */
-static int darwin_check_configuration (struct libusb_context *ctx, struct darwin_cached_device *dev) {
+static enum libusb_error darwin_check_configuration (struct libusb_context *ctx, struct darwin_cached_device *dev) {
   usb_device_t **darwin_device = dev->device;
 
   IOUSBConfigurationDescriptorPtr configDesc;
   IOUSBFindInterfaceRequest request;
-  kern_return_t             kresult;
+  IOReturn                  kresult;
   io_iterator_t             interface_iterator;
   io_service_t              firstInterface;
 
@@ -654,7 +655,7 @@ static int darwin_check_configuration (struct libusb_context *ctx, struct darwin
   if (0x05ac == dev->dev_descriptor.idVendor && 0x8005 == dev->dev_descriptor.idProduct) {
     usbi_dbg ("ignoring configuration on root hub simulation");
     dev->active_config = 0;
-    return 0;
+    return LIBUSB_SUCCESS;
   }
 
   /* find the first configuration */
@@ -672,7 +673,7 @@ static int darwin_check_configuration (struct libusb_context *ctx, struct darwin
   request.bAlternateSetting  = kIOUSBFindInterfaceDontCare;
 
   kresult = (*(darwin_device))->CreateInterfaceIterator(darwin_device, &request, &interface_iterator);
-  if (kresult)
+  if (kresult != kIOReturnSuccess)
     return darwin_to_libusb (kresult);
 
   /* iterate once */
@@ -697,10 +698,10 @@ static int darwin_check_configuration (struct libusb_context *ctx, struct darwin
   
   usbi_dbg ("active config: %u, first config: %u", dev->active_config, dev->first_config);
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
-static int darwin_request_descriptor (usb_device_t **device, UInt8 desc, UInt8 desc_index, void *buffer, size_t buffer_size) {
+static IOReturn darwin_request_descriptor (usb_device_t **device, UInt8 desc, UInt8 desc_index, void *buffer, size_t buffer_size) {
   IOUSBDevRequestTO req;
 
   memset (buffer, 0, buffer_size);
@@ -718,12 +719,12 @@ static int darwin_request_descriptor (usb_device_t **device, UInt8 desc, UInt8 d
   return (*device)->DeviceRequestTO (device, &req);
 }
 
-static int darwin_cache_device_descriptor (struct libusb_context *ctx, struct darwin_cached_device *dev) {
+static enum libusb_error darwin_cache_device_descriptor (struct libusb_context *ctx, struct darwin_cached_device *dev) {
   usb_device_t **device = dev->device;
   int retries = 1, delay = 30000;
   int unsuspended = 0, try_unsuspend = 1, try_reconfigure = 1;
   int is_open = 0;
-  int ret = 0, ret2;
+  IOReturn ret = 0, ret2;
   UInt8 bDeviceClass;
   UInt16 idProduct, idVendor;
 
@@ -847,17 +848,18 @@ static int darwin_cache_device_descriptor (struct libusb_context *ctx, struct da
   return LIBUSB_SUCCESS;
 }
 
-static int get_device_port (io_service_t service, UInt8 *port) {
-  kern_return_t result;
+/* Returns 1 on success, 0 on failure. */
+static bool get_device_port (io_service_t service, UInt8 *port) {
+  IOReturn kresult;
   io_service_t parent;
-  int ret = 0;
+  bool ret = false;
 
   if (get_ioregistry_value_number (service, CFSTR("PortNum"), kCFNumberSInt8Type, port)) {
-    return 1;
+    return true;
   }
 
-  result = IORegistryEntryGetParentEntry (service, kIOServicePlane, &parent);
-  if (kIOReturnSuccess == result) {
+  kresult = IORegistryEntryGetParentEntry (service, kIOServicePlane, &parent);
+  if (kIOReturnSuccess == kresult) {
     ret = get_ioregistry_value_data (parent, CFSTR("port"), 1, port);
     IOObjectRelease (parent);
   }
@@ -865,28 +867,29 @@ static int get_device_port (io_service_t service, UInt8 *port) {
   return ret;
 }
 
-static int get_device_parent_sessionID(io_service_t service, UInt64 *parent_sessionID) {
-  kern_return_t result;
+/* Returns 1 on success, 0 on failure. */
+static bool get_device_parent_sessionID(io_service_t service, UInt64 *parent_sessionID) {
+  IOReturn kresult;
   io_service_t parent;
 
   /* Walk up the tree in the IOService plane until we find a parent that has a sessionID */
   parent = service;
-  while((result = IORegistryEntryGetParentEntry (parent, kIOUSBPlane, &parent)) == kIOReturnSuccess) {
+  while((kresult = IORegistryEntryGetParentEntry (parent, kIOUSBPlane, &parent)) == kIOReturnSuccess) {
     if (get_ioregistry_value_number (parent, CFSTR("sessionID"), kCFNumberSInt64Type, parent_sessionID)) {
         /* Success */
-        return 1;
+        return true;
     }
   }
 
   /* We ran out of parents */
-  return 0;
+  return false;
 }
 
-static int darwin_get_cached_device(struct libusb_context *ctx, io_service_t service,
-                                    struct darwin_cached_device **cached_out) {
+static enum libusb_error darwin_get_cached_device(struct libusb_context *ctx, io_service_t service,
+                                                  struct darwin_cached_device **cached_out) {
   struct darwin_cached_device *new_device;
   UInt64 sessionID = 0, parent_sessionID = 0;
-  int ret = LIBUSB_SUCCESS;
+  enum libusb_error ret = LIBUSB_SUCCESS;
   usb_device_t **device;
   UInt8 port = 0;
 
@@ -968,12 +971,12 @@ static int darwin_get_cached_device(struct libusb_context *ctx, io_service_t ser
   return ret;
 }
 
-static int process_new_device (struct libusb_context *ctx, io_service_t service) {
+static enum libusb_error process_new_device (struct libusb_context *ctx, io_service_t service) {
   struct darwin_device_priv *priv;
   struct libusb_device *dev = NULL;
   struct darwin_cached_device *cached_device;
   UInt8 devSpeed;
-  int ret = 0;
+  enum libusb_error ret = LIBUSB_SUCCESS;
 
   do {
     ret = darwin_get_cached_device (ctx, service, &cached_device);
@@ -1043,10 +1046,10 @@ static int process_new_device (struct libusb_context *ctx, io_service_t service)
   return ret;
 }
 
-static int darwin_scan_devices(struct libusb_context *ctx) {
+static enum libusb_error darwin_scan_devices(struct libusb_context *ctx) {
   io_iterator_t deviceIterator;
   io_service_t service;
-  kern_return_t kresult;
+  IOReturn kresult;
 
   kresult = usb_setup_device_iterator (&deviceIterator, 0);
   if (kresult != kIOReturnSuccess)
@@ -1060,7 +1063,7 @@ static int darwin_scan_devices(struct libusb_context *ctx) {
 
   IOObjectRelease(deviceIterator);
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
 static int darwin_open (struct libusb_device_handle *dev_handle) {
@@ -1143,7 +1146,7 @@ static void darwin_close (struct libusb_device_handle *dev_handle) {
     if (priv->is_open) {
       /* close the device */
       kresult = (*(dpriv->device))->USBDeviceClose(dpriv->device);
-      if (kresult) {
+      if (kresult != kIOReturnSuccess) {
         /* Log the fact that we had a problem closing the file, however failing a
          * close isn't really an error, so return success anyway */
         usbi_warn (HANDLE_CTX (dev_handle), "USBDeviceClose: %s", darwin_error_str(kresult));
@@ -1157,10 +1160,10 @@ static int darwin_get_configuration(struct libusb_device_handle *dev_handle, int
 
   *config = (int) dpriv->active_config;
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
-static int darwin_set_configuration(struct libusb_device_handle *dev_handle, int config) {
+static enum libusb_error darwin_set_configuration(struct libusb_device_handle *dev_handle, int config) {
   struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
   IOReturn kresult;
   int i;
@@ -1182,15 +1185,15 @@ static int darwin_set_configuration(struct libusb_device_handle *dev_handle, int
 
   dpriv->active_config = config;
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
-static int darwin_get_interface (usb_device_t **darwin_device, uint8_t ifc, io_service_t *usbInterfacep) {
+static IOReturn darwin_get_interface (usb_device_t **darwin_device, int ifc, io_service_t *usbInterfacep) {
   IOUSBFindInterfaceRequest request;
-  kern_return_t             kresult;
+  IOReturn                  kresult;
   io_iterator_t             interface_iterator;
   UInt8                     bInterfaceNumber;
-  int                       ret;
+  bool                      ret;
 
   *usbInterfacep = IO_OBJECT_NULL;
 
@@ -1201,7 +1204,7 @@ static int darwin_get_interface (usb_device_t **darwin_device, uint8_t ifc, io_s
   request.bAlternateSetting  = kIOUSBFindInterfaceDontCare;
 
   kresult = (*(darwin_device))->CreateInterfaceIterator(darwin_device, &request, &interface_iterator);
-  if (kresult)
+  if (kresult != kIOReturnSuccess)
     return kresult;
 
   while ((*usbInterfacep = IOIteratorNext(interface_iterator))) {
@@ -1219,16 +1222,16 @@ static int darwin_get_interface (usb_device_t **darwin_device, uint8_t ifc, io_s
   /* done with the interface iterator */
   IOObjectRelease(interface_iterator);
 
-  return 0;
+  return kIOReturnSuccess;
 }
 
-static int get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
+static enum libusb_error get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
   struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
 
   /* current interface */
   struct darwin_interface *cInterface = &priv->interfaces[iface];
 
-  kern_return_t kresult;
+  IOReturn kresult;
 
   UInt8 numep, direction, number;
   UInt8 dont_care1, dont_care3;
@@ -1239,7 +1242,7 @@ static int get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
 
   /* retrieve the total number of endpoints on this interface */
   kresult = (*(cInterface->interface))->GetNumEndpoints(cInterface->interface, &numep);
-  if (kresult) {
+  if (kresult != kIOReturnSuccess) {
     usbi_err (HANDLE_CTX (dev_handle), "can't get number of endpoints for interface: %s", darwin_error_str(kresult));
     return darwin_to_libusb (kresult);
   }
@@ -1256,7 +1259,7 @@ static int get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
       UInt8 alt_setting;
 
       kresult = (*(cInterface->interface))->GetAlternateSetting (cInterface->interface, &alt_setting);
-      if (kresult) {
+      if (kresult != kIOReturnSuccess) {
         usbi_err (HANDLE_CTX (dev_handle), "can't get alternate setting for interface");
         return darwin_to_libusb (kresult);
       }
@@ -1279,14 +1282,15 @@ static int get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
 
   cInterface->num_endpoints = numep;
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
 static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int iface) {
   struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
   struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
   io_service_t          usbInterface = IO_OBJECT_NULL;
-  IOReturn kresult;
+  IOReturn              kresult;
+  enum libusb_error     ret;
   IOCFPlugInInterface **plugInInterface = NULL;
   SInt32                score;
 
@@ -1302,14 +1306,14 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
     usbi_info (HANDLE_CTX (dev_handle), "no interface found; setting configuration: %d", dpriv->first_config);
 
     /* set the configuration */
-    kresult = darwin_set_configuration (dev_handle, dpriv->first_config);
-    if (kresult != LIBUSB_SUCCESS) {
+    ret = darwin_set_configuration (dev_handle, dpriv->first_config);
+    if (ret != LIBUSB_SUCCESS) {
       usbi_err (HANDLE_CTX (dev_handle), "could not set configuration");
-      return kresult;
+      return ret;
     }
 
     kresult = darwin_get_interface (dpriv->device, iface, &usbInterface);
-    if (kresult) {
+    if (kresult != kIOReturnSuccess) {
       usbi_err (HANDLE_CTX (dev_handle), "darwin_get_interface: %s", darwin_error_str(kresult));
       return darwin_to_libusb (kresult);
     }
@@ -1327,7 +1331,7 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
   /* ignore release error */
   (void)IOObjectRelease (usbInterface);
 
-  if (kresult) {
+  if (kresult != kIOReturnSuccess) {
     usbi_err (HANDLE_CTX (dev_handle), "IOCreatePlugInInterfaceForService: %s", darwin_error_str(kresult));
     return darwin_to_libusb (kresult);
   }
@@ -1344,25 +1348,25 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
   /* We no longer need the intermediate plug-in */
   /* Use release instead of IODestroyPlugInInterface to avoid stopping IOServices associated with this device */
   (*plugInInterface)->Release (plugInInterface);
-  if (kresult || !cInterface->interface) {
+  if (kresult != kIOReturnSuccess || !cInterface->interface) {
     usbi_err (HANDLE_CTX (dev_handle), "QueryInterface: %s", darwin_error_str(kresult));
     return darwin_to_libusb (kresult);
   }
 
   /* claim the interface */
   kresult = (*(cInterface->interface))->USBInterfaceOpen(cInterface->interface);
-  if (kresult) {
+  if (kresult != kIOReturnSuccess) {
     usbi_err (HANDLE_CTX (dev_handle), "USBInterfaceOpen: %s", darwin_error_str(kresult));
     return darwin_to_libusb (kresult);
   }
 
   /* update list of endpoints */
-  kresult = get_endpoints (dev_handle, iface);
-  if (kresult) {
+  ret = get_endpoints (dev_handle, iface);
+  if (ret) {
     /* this should not happen */
     darwin_release_interface (dev_handle, iface);
     usbi_err (HANDLE_CTX (dev_handle), "could not build endpoint table");
-    return kresult;
+    return ret;
   }
 
   cInterface->cfSource = NULL;
@@ -1383,7 +1387,7 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
 
   usbi_dbg ("interface opened");
 
-  return 0;
+  return LIBUSB_SUCCESS;
 }
 
 static int darwin_release_interface(struct libusb_device_handle *dev_handle, int iface) {
@@ -1407,7 +1411,7 @@ static int darwin_release_interface(struct libusb_device_handle *dev_handle, int
   }
 
   kresult = (*(cInterface->interface))->USBInterfaceClose(cInterface->interface);
-  if (kresult)
+  if (kresult != kIOReturnSuccess)
     usbi_warn (HANDLE_CTX (dev_handle), "USBInterfaceClose: %s", darwin_error_str(kresult));
 
   kresult = (*(cInterface->interface))->Release(cInterface->interface);
@@ -1422,6 +1426,7 @@ static int darwin_release_interface(struct libusb_device_handle *dev_handle, int
 static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting) {
   struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
   IOReturn kresult;
+  enum libusb_error ret;
 
   /* current interface */
   struct darwin_interface *cInterface = &priv->interfaces[iface];
@@ -1434,12 +1439,12 @@ static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_hand
     darwin_reset_device (dev_handle);
 
   /* update list of endpoints */
-  kresult = get_endpoints (dev_handle, iface);
-  if (kresult) {
+  ret = get_endpoints (dev_handle, iface);
+  if (ret) {
     /* this should not happen */
     darwin_release_interface (dev_handle, iface);
     usbi_err (HANDLE_CTX (dev_handle), "could not build endpoint table");
-    return kresult;
+    return ret;
   }
 
   return darwin_to_libusb (kresult);
@@ -1460,7 +1465,7 @@ static int darwin_clear_halt(struct libusb_device_handle *dev_handle, unsigned c
 
   /* newer versions of darwin support clearing additional bits on the device's endpoint */
   kresult = (*(cInterface->interface))->ClearPipeStallBothEnds(cInterface->interface, pipeRef);
-  if (kresult)
+  if (kresult != kIOReturnSuccess)
     usbi_warn (HANDLE_CTX (dev_handle), "ClearPipeStall: %s", darwin_error_str (kresult));
 
   return darwin_to_libusb (kresult);
@@ -1477,7 +1482,7 @@ static int darwin_reset_device(struct libusb_device_handle *dev_handle) {
 
   /* from macOS 10.11 ResetDevice no longer does anything so just use USBDeviceReEnumerate */
   kresult = (*(dpriv->device))->USBDeviceReEnumerate (dpriv->device, 0);
-  if (kresult) {
+  if (kresult != kIOReturnSuccess) {
     usbi_err (HANDLE_CTX (dev_handle), "USBDeviceReEnumerate: %s", darwin_error_str (kresult));
     return darwin_to_libusb (kresult);
   }
@@ -1526,7 +1531,7 @@ static int darwin_kernel_driver_active(struct libusb_device_handle *dev_handle,
   IOReturn kresult;
 
   kresult = darwin_get_interface (dpriv->device, interface, &usbInterface);
-  if (kresult) {
+  if (kresult != kIOReturnSuccess) {
     usbi_err (HANDLE_CTX (dev_handle), "darwin_get_interface: %s", darwin_error_str(kresult));
 
     return darwin_to_libusb (kresult);
@@ -1705,7 +1710,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
 
   /* Last but not least we need the bus frame number */
   kresult = (*(cInterface->interface))->GetBusFrameNumber(cInterface->interface, &frame, &atTime);
-  if (kresult) {
+  if (kresult != kIOReturnSuccess) {
     usbi_err (TRANSFER_CTX (transfer), "failed to get bus frame number: %d", kresult);
     free(tpriv->isoc_framelist);
     tpriv->isoc_framelist = NULL;
@@ -1919,7 +1924,7 @@ static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0)
   usbi_signal_transfer_completion(itransfer);
 }
 
-static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_t result) {
+static enum libusb_transfer_status darwin_transfer_status (struct usbi_transfer *itransfer, IOReturn result) {
   if (itransfer->timeout_flags & USBI_TRANSFER_TIMED_OUT)
     result = kIOUSBTransactionTimeout;
 
@@ -1948,10 +1953,10 @@ static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_
 static int darwin_handle_transfer_completion (struct usbi_transfer *itransfer) {
   struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
   struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
-  int isIsoc      = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS == transfer->type;
-  int isBulk      = LIBUSB_TRANSFER_TYPE_BULK == transfer->type;
-  int isControl   = LIBUSB_TRANSFER_TYPE_CONTROL == transfer->type;
-  int isInterrupt = LIBUSB_TRANSFER_TYPE_INTERRUPT == transfer->type;
+  bool isIsoc      = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS == transfer->type;
+  bool isBulk      = LIBUSB_TRANSFER_TYPE_BULK == transfer->type;
+  bool isControl   = LIBUSB_TRANSFER_TYPE_CONTROL == transfer->type;
+  bool isInterrupt = LIBUSB_TRANSFER_TYPE_INTERRUPT == transfer->type;
   int i;
 
   if (!isIsoc && !isBulk && !isControl && !isInterrupt) {
@@ -1968,7 +1973,7 @@ static int darwin_handle_transfer_completion (struct usbi_transfer *itransfer) {
 
       for (i = 0; i < transfer->num_iso_packets ; i++) {
         struct libusb_iso_packet_descriptor *lib_desc = &transfer->iso_packet_desc[i];
-        lib_desc->status = darwin_to_libusb (tpriv->isoc_framelist[i].frStatus);
+        lib_desc->status = darwin_transfer_status (itransfer, tpriv->isoc_framelist[i].frStatus);
         lib_desc->actual_length = tpriv->isoc_framelist[i].frActCount;
       }
     } else if (!isIsoc)
@@ -2002,7 +2007,7 @@ static int darwin_clock_gettime(int clk_id, struct timespec *tp) {
   tp->tv_sec  = sys_time.tv_sec;
   tp->tv_nsec = sys_time.tv_nsec;
 
-  return 0;
+  return LIBUSB_SUCCESS;
 #else
   switch (clk_id) {
   case USBI_CLOCK_MONOTONIC: