int r;
int parsed = 0;
int interface_number = -1;
- size_t tmp;
struct usb_descriptor_header header;
struct libusb_interface_descriptor *ifp;
unsigned char *begin;
if (ifp->bNumEndpoints > 0) {
struct libusb_endpoint_descriptor *endpoint;
- tmp = ifp->bNumEndpoints * sizeof(struct libusb_endpoint_descriptor);
- endpoint = malloc(tmp);
+ endpoint = calloc(ifp->bNumEndpoints, sizeof(struct libusb_endpoint_descriptor));
ifp->endpoint = endpoint;
if (!endpoint) {
r = LIBUSB_ERROR_NO_MEM;
goto err;
}
- memset(endpoint, 0, tmp);
for (i = 0; i < ifp->bNumEndpoints; i++) {
r = parse_endpoint(ctx, endpoint + i, buffer, size,
host_endian);
{
int i;
int r;
- size_t tmp;
struct usb_descriptor_header header;
struct libusb_interface *usb_interface;
return LIBUSB_ERROR_IO;
}
- tmp = config->bNumInterfaces * sizeof(struct libusb_interface);
- usb_interface = malloc(tmp);
+ usb_interface = calloc(config->bNumInterfaces, sizeof(struct libusb_interface));
config->interface = usb_interface;
- if (!config->interface)
+ if (!usb_interface)
return LIBUSB_ERROR_NO_MEM;
- memset(usb_interface, 0, tmp);
buffer += config->bLength;
size -= config->bLength;
#else
static int arm_timerfd_for_next_timeout(struct libusb_context *ctx)
{
- (void)ctx;
+ UNUSED(ctx);
return 0;
}
#endif
USBI_GET_CONTEXT(ctx);
return usbi_using_timerfd(ctx);
#else
- (void)ctx;
+ UNUSED(ctx);
return 0;
#endif
}
/* attaching/detaching kernel drivers is not currently supported (maybe in the future?) */
static int darwin_attach_kernel_driver (struct libusb_device_handle *dev_handle, int interface) {
- (void)dev_handle;
- (void)interface;
+ UNUSED(dev_handle);
+ UNUSED(interface);
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int darwin_detach_kernel_driver (struct libusb_device_handle *dev_handle, int interface) {
- (void)dev_handle;
- (void)interface;
+ UNUSED(dev_handle);
+ UNUSED(interface);
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static void *linux_netlink_event_thread_main(void *arg);
-struct sockaddr_nl snl = { .nl_family=AF_NETLINK, .nl_groups=KERNEL };
+static struct sockaddr_nl snl = { .nl_family=AF_NETLINK, .nl_groups=KERNEL };
-static int set_fd_cloexec_nb (int fd)
+static int set_fd_cloexec_nb(int fd)
{
int flags;
#if defined(FD_CLOEXEC)
- flags = fcntl (linux_netlink_socket, F_GETFD);
+ flags = fcntl(fd, F_GETFD);
if (0 > flags) {
return -1;
}
if (!(flags & FD_CLOEXEC)) {
- fcntl (linux_netlink_socket, F_SETFD, flags | FD_CLOEXEC);
+ fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
#endif
- flags = fcntl (linux_netlink_socket, F_GETFL);
+ flags = fcntl(fd, F_GETFL);
if (0 > flags) {
return -1;
}
if (!(flags & O_NONBLOCK)) {
- fcntl (linux_netlink_socket, F_SETFL, flags | O_NONBLOCK);
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
return 0;
/* signal device is available (or not) to all contexts */
if (detached)
- linux_device_disconnected(busnum, devaddr, sys_name);
+ linux_device_disconnected(busnum, devaddr);
else
linux_hotplug_enumerate(busnum, devaddr, sys_name);
.events = POLLIN },
};
- /* silence compiler warning */
- (void) arg;
+ UNUSED(arg);
while (poll(fds, 2, -1) >= 0) {
if (fds[0].revents & POLLIN) {
if (strncmp(udev_action, "add", 3) == 0) {
linux_hotplug_enumerate(busnum, devaddr, sys_name);
} else if (detached) {
- linux_device_disconnected(busnum, devaddr, sys_name);
+ linux_device_disconnected(busnum, devaddr);
} else {
usbi_err(NULL, "ignoring udev action %s", udev_action);
}
static int init_count = 0;
/* Serialize hotplug start/stop */
-usbi_mutex_static_t linux_hotplug_startstop_lock = USBI_MUTEX_INITIALIZER;
+static usbi_mutex_static_t linux_hotplug_startstop_lock = USBI_MUTEX_INITIALIZER;
/* Serialize scan-devices, event-thread, and poll */
usbi_mutex_static_t linux_hotplug_lock = USBI_MUTEX_INITIALIZER;
dev->device_address = devaddr;
if (sysfs_dir) {
- priv->sysfs_dir = malloc(strlen(sysfs_dir) + 1);
+ priv->sysfs_dir = strdup(sysfs_dir);
if (!priv->sysfs_dir)
return LIBUSB_ERROR_NO_MEM;
- strcpy(priv->sysfs_dir, sysfs_dir);
/* Note speed can contain 1.5, in this case __read_sysfs_attr
will stop parsing at the '.' and return 1 */
usbi_mutex_static_unlock(&active_contexts_lock);
}
-void linux_device_disconnected(uint8_t busnum, uint8_t devaddr, const char *sys_name)
+void linux_device_disconnected(uint8_t busnum, uint8_t devaddr)
{
struct libusb_context *ctx;
struct libusb_device *dev;
if (handle->dev->attached) {
usbi_dbg("open failed with no device, but device still attached");
linux_device_disconnected(handle->dev->bus_number,
- handle->dev->device_address, NULL);
+ handle->dev->device_address);
}
usbi_mutex_static_unlock(&linux_hotplug_lock);
}
usbi_mutex_static_lock(&linux_hotplug_lock);
if (handle->dev->attached)
linux_device_disconnected(handle->dev->bus_number,
- handle->dev->device_address, NULL);
+ handle->dev->device_address);
usbi_mutex_static_unlock(&linux_hotplug_lock);
if (!(hpriv->caps & USBFS_CAP_REAP_AFTER_DISCONNECT)) {
#endif
void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_name);
-void linux_device_disconnected(uint8_t busnum, uint8_t devaddr, const char *sys_name);
+void linux_device_disconnected(uint8_t busnum, uint8_t devaddr);
int linux_get_device_address (struct libusb_context *ctx, int detached,
uint8_t *busnum, uint8_t *devaddr, const char *dev_node,
-#define LIBUSB_NANO 11010
+#define LIBUSB_NANO 11011