summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-04-17 12:07:38 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2020-04-17 12:07:38 -0700
commitf07af6458f9eb9b932112d12840039e321dac500 (patch)
tree470b44094638f8e520f527def56fc2e0464762b7
parent95b60dc3f5146a739911907ab452433b9bd8d6d7 (diff)
downloadlibusb-f07af6458f9eb9b932112d12840039e321dac500.tar.gz
core: Remove usbi_parse_descriptor() function
The Linux backend was the only caller of this function, but with the packed structures introduced in commit d06cc52851 its use is no longer necessary. Convert the function to static and remove the return type as no callers paid attention to it. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--libusb/descriptor.c38
-rw-r--r--libusb/libusbi.h2
-rw-r--r--libusb/os/linux_usbfs.c45
-rw-r--r--libusb/version_nano.h2
4 files changed, 42 insertions, 45 deletions
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index d7ec5e2..4e38f0f 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -37,7 +37,7 @@
/* set host_endian if the w values are already in host endian format,
* as opposed to bus endian. */
-int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
+static void parse_descriptor(const unsigned char *source, const char *descriptor,
void *dest, int host_endian)
{
const unsigned char *sp = source;
@@ -83,8 +83,6 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
break;
}
}
-
- return (int) (sp - source);
}
static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint)
@@ -119,9 +117,9 @@ static int parse_endpoint(struct libusb_context *ctx,
return parsed;
}
if (header->bLength >= ENDPOINT_AUDIO_DESC_LENGTH)
- usbi_parse_descriptor(buffer, "bbbbwbbb", endpoint, host_endian);
+ parse_descriptor(buffer, "bbbbwbbb", endpoint, host_endian);
else if (header->bLength >= ENDPOINT_DESC_LENGTH)
- usbi_parse_descriptor(buffer, "bbbbwb", endpoint, host_endian);
+ parse_descriptor(buffer, "bbbbwb", endpoint, host_endian);
else {
usbi_err(ctx, "invalid endpoint bLength (%d)", header->bLength);
return LIBUSB_ERROR_IO;
@@ -232,7 +230,7 @@ static int parse_interface(libusb_context *ctx,
usb_interface->altsetting = altsetting;
ifp = altsetting + usb_interface->num_altsetting;
- usbi_parse_descriptor(buffer, "bbbbbbbbb", ifp, 0);
+ parse_descriptor(buffer, "bbbbbbbbb", ifp, 0);
if (ifp->bDescriptorType != LIBUSB_DT_INTERFACE) {
usbi_err(ctx, "unexpected descriptor %x (expected %x)",
ifp->bDescriptorType, LIBUSB_DT_INTERFACE);
@@ -377,7 +375,7 @@ static int parse_configuration(struct libusb_context *ctx,
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer, "bbwbbbbb", config, host_endian);
+ parse_descriptor(buffer, "bbwbbbbb", config, host_endian);
if (config->bDescriptorType != LIBUSB_DT_CONFIG) {
usbi_err(ctx, "unexpected descriptor %x (expected %x)",
config->bDescriptorType, LIBUSB_DT_CONFIG);
@@ -575,7 +573,7 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(tmp, "bbw", &_config, host_endian);
+ parse_descriptor(tmp, "bbw", &_config, host_endian);
buf = malloc(_config.wTotalLength);
if (!buf)
return LIBUSB_ERROR_NO_MEM;
@@ -628,7 +626,7 @@ int API_EXPORTED libusb_get_config_descriptor(libusb_device *dev,
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(tmp, "bbw", &_config, host_endian);
+ parse_descriptor(tmp, "bbw", &_config, host_endian);
buf = malloc(_config.wTotalLength);
if (!buf)
return LIBUSB_ERROR_NO_MEM;
@@ -774,7 +772,7 @@ int API_EXPORTED libusb_get_ss_endpoint_companion_descriptor(
*ep_comp = malloc(sizeof(**ep_comp));
if (*ep_comp == NULL)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor(buffer, "bbbbw", *ep_comp, 0);
+ parse_descriptor(buffer, "bbbbw", *ep_comp, 0);
return LIBUSB_SUCCESS;
}
return LIBUSB_ERROR_NOT_FOUND;
@@ -808,7 +806,7 @@ static int parse_bos(struct libusb_context *ctx,
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer, "bbwb", &bos_header, host_endian);
+ parse_descriptor(buffer, "bbwb", &bos_header, host_endian);
if (bos_header.bDescriptorType != LIBUSB_DT_BOS) {
usbi_err(ctx, "unexpected descriptor %x (expected %x)",
bos_header.bDescriptorType, LIBUSB_DT_BOS);
@@ -829,7 +827,7 @@ static int parse_bos(struct libusb_context *ctx,
if (!_bos)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor(buffer, "bbwb", _bos, host_endian);
+ parse_descriptor(buffer, "bbwb", _bos, host_endian);
buffer += bos_header.bLength;
size -= bos_header.bLength;
@@ -840,7 +838,7 @@ static int parse_bos(struct libusb_context *ctx,
size, LIBUSB_DT_DEVICE_CAPABILITY_SIZE);
break;
}
- usbi_parse_descriptor(buffer, "bbb", &dev_cap, host_endian);
+ parse_descriptor(buffer, "bbb", &dev_cap, host_endian);
if (dev_cap.bDescriptorType != LIBUSB_DT_DEVICE_CAPABILITY) {
usbi_warn(ctx, "unexpected descriptor %x (expected %x)",
dev_cap.bDescriptorType, LIBUSB_DT_DEVICE_CAPABILITY);
@@ -908,7 +906,7 @@ int API_EXPORTED libusb_get_bos_descriptor(libusb_device_handle *dev_handle,
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(bos_header, "bbwb", &_bos, host_endian);
+ parse_descriptor(bos_header, "bbwb", &_bos, host_endian);
usbi_dbg("found BOS descriptor: size %d bytes, %d capabilities",
_bos.wTotalLength, _bos.bNumDeviceCaps);
bos_data = calloc(_bos.wTotalLength, 1);
@@ -982,8 +980,8 @@ int API_EXPORTED libusb_get_usb_2_0_extension_descriptor(
if (!_usb_2_0_extension)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor((unsigned char *)dev_cap, "bbbd",
- _usb_2_0_extension, host_endian);
+ parse_descriptor((unsigned char *)dev_cap, "bbbd",
+ _usb_2_0_extension, host_endian);
*usb_2_0_extension = _usb_2_0_extension;
return LIBUSB_SUCCESS;
@@ -1040,8 +1038,8 @@ int API_EXPORTED libusb_get_ss_usb_device_capability_descriptor(
if (!_ss_usb_device_cap)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor((unsigned char *)dev_cap, "bbbbwbbw",
- _ss_usb_device_cap, host_endian);
+ parse_descriptor((unsigned char *)dev_cap, "bbbbwbbw",
+ _ss_usb_device_cap, host_endian);
*ss_usb_device_cap = _ss_usb_device_cap;
return LIBUSB_SUCCESS;
@@ -1098,8 +1096,8 @@ int API_EXPORTED libusb_get_container_id_descriptor(struct libusb_context *ctx,
if (!_container_id)
return LIBUSB_ERROR_NO_MEM;
- usbi_parse_descriptor((unsigned char *)dev_cap, "bbbbu",
- _container_id, host_endian);
+ parse_descriptor((unsigned char *)dev_cap, "bbbbu",
+ _container_id, host_endian);
*container_id = _container_id;
return LIBUSB_SUCCESS;
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 9622768..db9c919 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -620,8 +620,6 @@ int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
int usbi_handle_transfer_cancellation(struct usbi_transfer *itransfer);
void usbi_signal_transfer_completion(struct usbi_transfer *itransfer);
-int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
- void *dest, int host_endian);
int usbi_device_cache_descriptor(libusb_device *dev);
int usbi_get_config_index_by_value(struct libusb_device *dev,
uint8_t bConfigurationValue, int *idx);
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 31304d6..4dd5337 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -613,10 +613,10 @@ int linux_get_device_address(struct libusb_context *ctx, int detached,
static int seek_to_next_descriptor(struct libusb_context *ctx,
uint8_t descriptor_type, unsigned char *buffer, int size)
{
- struct usbi_descriptor_header header;
+ struct usbi_descriptor_header *header;
int i;
- for (i = 0; size >= 0; i += header.bLength, size -= header.bLength) {
+ for (i = 0; size >= 0; i += header->bLength, size -= header->bLength) {
if (size == 0)
return LIBUSB_ERROR_NOT_FOUND;
@@ -624,9 +624,9 @@ static int seek_to_next_descriptor(struct libusb_context *ctx,
usbi_err(ctx, "short descriptor read %d/2", size);
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer + i, "bb", &header, 0);
- if (i && header.bDescriptorType == descriptor_type)
+ header = (struct usbi_descriptor_header *)(buffer + i);
+ if (i && header->bDescriptorType == descriptor_type)
return i;
}
usbi_err(ctx, "bLength overflow by %d bytes", -size);
@@ -639,7 +639,8 @@ static int seek_to_next_config(struct libusb_device *dev,
{
struct libusb_context *ctx = DEVICE_CTX(dev);
struct linux_device_priv *priv = usbi_get_device_priv(dev);
- struct libusb_config_descriptor config;
+ struct usbi_configuration_descriptor *config;
+ uint16_t config_len;
if (size == 0)
return LIBUSB_ERROR_NOT_FOUND;
@@ -650,15 +651,16 @@ static int seek_to_next_config(struct libusb_device *dev,
return LIBUSB_ERROR_IO;
}
- usbi_parse_descriptor(buffer, "bbwbbbbb", &config, 0);
- if (config.bDescriptorType != LIBUSB_DT_CONFIG) {
+ config = (struct usbi_configuration_descriptor *)buffer;
+ if (config->bDescriptorType != LIBUSB_DT_CONFIG) {
usbi_err(ctx, "descriptor is not a config desc (type 0x%02x)",
- config.bDescriptorType);
+ config->bDescriptorType);
return LIBUSB_ERROR_IO;
}
+ config_len = libusb_le16_to_cpu(config->wTotalLength);
/*
- * In usbfs the config descriptors are config.wTotalLength bytes apart,
+ * In usbfs the config descriptors are wTotalLength bytes apart,
* with any short reads from the device appearing as holes in the file.
*
* In sysfs wTotalLength is ignored, instead the kernel returns a
@@ -673,20 +675,20 @@ static int seek_to_next_config(struct libusb_device *dev,
if (next < 0)
return next;
- if (next != config.wTotalLength)
+ if (next != config_len)
usbi_warn(ctx, "config length mismatch wTotalLength %u real %d",
- config.wTotalLength, next);
+ config_len, next);
return next;
} else {
- if (config.wTotalLength < LIBUSB_DT_CONFIG_SIZE) {
- usbi_err(ctx, "invalid wTotalLength %u", config.wTotalLength);
+ if (config_len < LIBUSB_DT_CONFIG_SIZE) {
+ usbi_err(ctx, "invalid wTotalLength %u", config_len);
return LIBUSB_ERROR_IO;
- } else if (config.wTotalLength > size) {
+ } else if (config_len > size) {
usbi_warn(ctx, "short descriptor read %d/%u",
- size, config.wTotalLength);
+ size, config_len);
return size;
} else {
- return config.wTotalLength;
+ return config_len;
}
}
}
@@ -697,7 +699,7 @@ static int op_get_config_descriptor_by_value(struct libusb_device *dev,
struct linux_device_priv *priv = usbi_get_device_priv(dev);
unsigned char *descriptors = priv->descriptors;
int size = priv->descriptors_len;
- struct libusb_config_descriptor *config;
+ struct usbi_configuration_descriptor *config;
*buffer = NULL;
/* Unlike the device desc. config descs. are always in raw format */
@@ -713,7 +715,7 @@ static int op_get_config_descriptor_by_value(struct libusb_device *dev,
if (next < 0)
return next;
- config = (struct libusb_config_descriptor *)descriptors;
+ config = (struct usbi_configuration_descriptor *)descriptors;
if (config->bConfigurationValue == value) {
*buffer = descriptors;
return next;
@@ -917,11 +919,10 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
usbi_warn(ctx, "Missing rw usbfs access; cannot determine "
"active configuration descriptor");
if (priv->descriptors_len >= (DEVICE_DESC_LENGTH + LIBUSB_DT_CONFIG_SIZE)) {
- struct libusb_config_descriptor config;
+ struct usbi_configuration_descriptor *config;
- usbi_parse_descriptor(priv->descriptors + DEVICE_DESC_LENGTH,
- "bbwbbbbb", &config, 0);
- priv->active_config = config.bConfigurationValue;
+ config = (struct usbi_configuration_descriptor *)(priv->descriptors + DEVICE_DESC_LENGTH);
+ priv->active_config = config->bConfigurationValue;
} else {
priv->active_config = -1; /* No config dt */
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 2aa9119..5454846 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11503
+#define LIBUSB_NANO 11504