Skip to content

Commit

Permalink
drivers/libusb1.c: reset driver parameters while enumerating
Browse files Browse the repository at this point in the history
With an Arduino Leonardo compatible board attached alongside a
CyberPower CP1500PFCLCD, usbhid-ups would incorrectly conclude that
there was no kernel driver attached to the UPS and then fail subsequent
steps accordingly.

The cause is the global usb_communication_subdriver_t struct; when a
subdriver (e.g. arduino-hid) sets different values during the
enumeration loop, they're not set back to defaults afterwards, causing
issues with other subdrivers (e.g. cps-hid).

So, if a subdriver doesn't match, set a selection of fields back to
their default values using the newly added nut_usb_subdriver_defaults()
before the next attempt.

Signed-off-by: Matt Merhar <[email protected]>
  • Loading branch information
tofurky committed Sep 5, 2024
1 parent 38d8078 commit 93e0b39
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/libusb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ static int nut_usb_set_altinterface(libusb_device_handle *udev)
return ret;
}

static void nut_usb_subdriver_defaults(usb_communication_subdriver_t *subdriver)
{
if (!getval("usb_config_index"))
subdriver->usb_config_index = LIBUSB_DEFAULT_CONF_INDEX;
if (!getval("usb_hid_rep_index"))
subdriver->hid_rep_index = LIBUSB_DEFAULT_INTERFACE;
if (!getval("usb_hid_desc_index"))
subdriver->hid_desc_index = LIBUSB_DEFAULT_DESC_INDEX;
if (!getval("usb_hid_ep_in"))
subdriver->hid_ep_in = LIBUSB_DEFAULT_HID_EP_IN;
if (!getval("usb_hid_ep_out"))
subdriver->hid_ep_out = LIBUSB_DEFAULT_HID_EP_OUT;
}

/* On success, fill in the curDevice structure and return the report
* descriptor length. On failure, return -1.
* Note: When callback is not NULL, the report descriptor will be
Expand Down Expand Up @@ -870,6 +884,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
/* if (if_claimed)
libusb_release_interface(udev, usb_subdriver.hid_rep_index); */
libusb_close(udev);
/* reset any parameters modified by unmatched drivers back to defaults */
nut_usb_subdriver_defaults(&usb_subdriver);
}

*udevp = NULL;
Expand Down

0 comments on commit 93e0b39

Please sign in to comment.