Skip to content

Commit

Permalink
libusb0/1: Use nut_usb_get_string() instead of libusb functions
Browse files Browse the repository at this point in the history
Fixes networkupstools#1925

Signed-off-by: Tormod Volden <[email protected]>
  • Loading branch information
tormodvolden committed Aug 28, 2024
1 parent 0e4f31e commit 632199b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions drivers/libusb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,23 +397,23 @@ static int libusb_open(usb_dev_handle **udevp,
#endif

if (dev->descriptor.iManufacturer) {
ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer,
ret = nut_usb_get_string(udev, dev->descriptor.iManufacturer,
string, sizeof(string));
if (ret > 0) {
curDevice->Vendor = xstrdup(string);
}
}

if (dev->descriptor.iProduct) {
ret = usb_get_string_simple(udev, dev->descriptor.iProduct,
ret = nut_usb_get_string(udev, dev->descriptor.iProduct,
string, sizeof(string));
if (ret > 0) {
curDevice->Product = xstrdup(string);
}
}

if (dev->descriptor.iSerialNumber) {
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber,
ret = nut_usb_get_string(udev, dev->descriptor.iSerialNumber,
string, sizeof(string));
if (ret > 0) {
curDevice->Serial = xstrdup(string);
Expand Down Expand Up @@ -876,7 +876,7 @@ static int libusb_get_string(
# pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare"
#endif
/*
* usb.h:int usb_get_string_simple(usb_dev_handle *dev, int index,
* usb.h:int nut_usb_get_string(usb_dev_handle *dev, int index,
* usb.h- char *buf, size_t buflen);
*/
if (!udev
Expand All @@ -889,7 +889,7 @@ static int libusb_get_string(
return -1;
}

ret = usb_get_string_simple(udev, StringIdx, buf, (size_t)buflen);
ret = nut_usb_get_string(udev, StringIdx, buf, (size_t)buflen);

#ifdef WIN32
errno = -ret;
Expand All @@ -899,7 +899,7 @@ static int libusb_get_string(
* logging below - also tends to happen */
if (ret == 0) {
size_t len = strlen(buf);
upsdebugx(2, "%s: usb_get_string_simple() returned "
upsdebugx(2, "%s: nut_usb_get_string() returned "
"0 (might be just success code), "
"actual buf length is %" PRIuSIZE, __func__, len);
/* if (len) */
Expand Down
18 changes: 9 additions & 9 deletions drivers/libusb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
curDevice->bcdDevice = dev_desc.bcdDevice;

if (dev_desc.iManufacturer) {
ret = libusb_get_string_descriptor_ascii(udev, dev_desc.iManufacturer,
(unsigned char*)string, sizeof(string));
ret = nut_usb_get_string(udev, dev_desc.iManufacturer,
string, sizeof(string));
if (ret > 0) {
curDevice->Vendor = strdup(string);
if (curDevice->Vendor == NULL) {
Expand All @@ -403,8 +403,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
}

if (dev_desc.iProduct) {
ret = libusb_get_string_descriptor_ascii(udev, dev_desc.iProduct,
(unsigned char*)string, sizeof(string));
ret = nut_usb_get_string(udev, dev_desc.iProduct,
string, sizeof(string));
if (ret > 0) {
curDevice->Product = strdup(string);
if (curDevice->Product == NULL) {
Expand All @@ -415,8 +415,8 @@ static int nut_libusb_open(libusb_device_handle **udevp,
}

if (dev_desc.iSerialNumber) {
ret = libusb_get_string_descriptor_ascii(udev, dev_desc.iSerialNumber,
(unsigned char*)string, sizeof(string));
ret = nut_usb_get_string(udev, dev_desc.iSerialNumber,
string, sizeof(string));
if (ret > 0) {
curDevice->Serial = strdup(string);
if (curDevice->Serial == NULL) {
Expand Down Expand Up @@ -1007,14 +1007,14 @@ static int nut_libusb_get_string(
return -1;
}

ret = libusb_get_string_descriptor_ascii(udev, (uint8_t)StringIdx,
(unsigned char*)buf, (int)buflen);
ret = nut_usb_get_string(udev, (uint8_t)StringIdx,
buf, (int)buflen);

/** 0 can be seen as an empty string, or as LIBUSB_SUCCESS for
* logging below - also tends to happen */
if (ret == 0) {
size_t len = strlen(buf);
upsdebugx(2, "%s: libusb_get_string_descriptor_ascii() returned "
upsdebugx(2, "%s: nut_usb_get_string() returned "
"0 (might be just LIBUSB_SUCCESS code), "
"actual buf length is %" PRIuSIZE, __func__, len);
/* if (len) */
Expand Down

0 comments on commit 632199b

Please sign in to comment.