Skip to content

Commit

Permalink
wip: tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jun 20, 2022
1 parent 0a208b9 commit 9b09429
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
7 changes: 2 additions & 5 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,

fill_device_info_for_device(handle, cur_dev, &desc);

if (res >= 0) {
if (res >= 0)
libusb_close(handle);
}

/* Interface Number */
cur_dev->interface_number = interface_num;
Expand Down Expand Up @@ -931,7 +930,6 @@ static int hidapi_initialize_device(hid_device *dev, char* path, const struct li
dev->device_info = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
dev->device_info->next = NULL;
dev->device_info->path = path;
// dev->device_info->path = make_path(dev->device_handle, intf_desc->bInterfaceNumber, conf_desc->bConfigurationValue);
fill_device_info_for_device(dev->device_handle, dev->device_info, &desc);

#ifdef DETACH_KERNEL_DRIVER
Expand Down Expand Up @@ -1047,9 +1045,8 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
break;
}
good_open = hidapi_initialize_device(dev, dev_path, intf_desc);
if (!good_open) {
if (!good_open)
libusb_close(dev->device_handle);
}

// dev_path is owned by dev now
} else {
Expand Down
12 changes: 4 additions & 8 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ static void get_device_info_for_device( struct udev_device *raw_dev, unsigned sh
const char *sysfs_path;
const char *dev_path;
const char *str;
// struct udev_device *raw_dev; /* The device's hidraw udev node. */
struct udev_device *hid_dev; /* The device's HID udev node. */
struct udev_device *usb_dev; /* The device's USB udev node. */
struct udev_device *intf_dev; /* The device's interface (in the USB sense). */
Expand Down Expand Up @@ -554,7 +553,6 @@ static void get_device_info_for_device( struct udev_device *raw_dev, unsigned sh
/* VID/PID match. Create the record. */
*first_dev = (struct hid_device_info*) calloc(1, sizeof(struct hid_device_info));
cur_dev = *first_dev;
*last_dev = cur_dev;

/* Fill out the record */
cur_dev->next = NULL;
Expand Down Expand Up @@ -654,7 +652,6 @@ static void get_device_info_for_device( struct udev_device *raw_dev, unsigned sh
cur_dev->next = tmp;
prev_dev = cur_dev;
cur_dev = tmp;
*last_dev = tmp;

/* Update fields */
cur_dev->path = strdup(dev_path);
Expand All @@ -677,6 +674,8 @@ static void get_device_info_for_device( struct udev_device *raw_dev, unsigned sh
/* hid_dev, usb_dev and intf_dev don't need to be (and can't be)
unref()d. It will cause a double-free() error. I'm not
sure why. */

*last_dev = cur_dev;
}

struct hid_device_info* get_device_info_for_handle(int device_handle) {
Expand Down Expand Up @@ -772,10 +771,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Get the filename of the /sys entry for the device
and create a udev_device object (dev) representing it */
sysfs_path = udev_list_entry_get_name(dev_list_entry);

raw_dev = udev_device_new_from_syspath(udev, sysfs_path);

// TODO - this is kinda messy...
struct hid_device_info * first_dev;
struct hid_device_info * last_dev;
get_device_info_for_device(raw_dev, vendor_id, product_id, &first_dev, &last_dev);
Expand Down Expand Up @@ -868,12 +865,11 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)

/* If we have a good handle, return it. */
if (dev->device_handle >= 0) {

dev->device_info = get_device_info_for_handle(dev->device_handle);

/* Set device error to none */
register_device_error(dev, NULL);

dev->device_info = get_device_info_for_handle(dev->device_handle);

/* Get the report descriptor */
int res, desc_size = 0;
struct hidraw_report_descriptor rpt_desc;
Expand Down

0 comments on commit 9b09429

Please sign in to comment.