Re: git: f84a0da4e060 - main - libusb: rename bNumDeviceCapabilities to bNumDeviceCaps for compatibility with libusb
Date: Wed, 09 Jul 2025 01:08:17 UTC
Hello. Do you mean LIBUSB20_NO_BACKWARDS_COMPAT applies only to
libusb20, or to both libusb10 and libusb20. Since I don't think there is anyone use
libusb20 directly and the structure in libusb20 is for decoding only.
> On 7/8/25 14:40, Adrian Chadd wrote:
>> hi! Thanks for this!
>> Could we possibly wrap stuff like these compat macros in a #define
>> that we can undefine? So we can make sure no new code shows up that
>> uses the "old" paths?
>> eg LIBUSB10_NO_BACKWARDS_COMPAT / LIBUSB20_NO_BACKWARDS_COMPAT ?
>> Thanks!
>>
>
> The latter, please. +1
>
> Thanks,
>
> Kyle Evans
>
>> -adrian
>> On Tue, 8 Jul 2025 at 08:12, ShengYi Hung <aokblast@freebsd.org
>> <mailto:aokblast@freebsd.org>> wrote:
>> The branch main has been updated by aokblast:
>> URL: https://cgit.FreeBSD.org/src/commit/?
>> id=f84a0da4e0608a970c775f3d605f8de2b0b8d322 <https://
>> cgit.FreeBSD.org/src/commit/?
>> id=f84a0da4e0608a970c775f3d605f8de2b0b8d322>
>> commit f84a0da4e0608a970c775f3d605f8de2b0b8d322
>> Author: ShengYi Hung <aokblast@FreeBSD.org>
>> AuthorDate: 2025-06-07 19:43:15 +0000
>> Commit: ShengYi Hung <aokblast@FreeBSD.org>
>> CommitDate: 2025-07-08 15:11:41 +0000
>> libusb: rename bNumDeviceCapabilities to bNumDeviceCaps for
>> compatibility with libusb
>> THe member bNumDeviceCapabilities is referred to as
>> bNumDeviceCaps in
>> the upstream libusb project.
>> To improve compatibility, we are renaming the member
>> accordingly.
>> For backward compatibility, a mocro will be defined to map
>> bNumDeviceCapabilities to bNumDeviceCaps.
>> See: https://github.com/libusb/libusb/
>> commit/02ebafc85d3f219842cbabaf78abc8100b6656e5 <https://github.com/
>> libusb/libusb/commit/02ebafc85d3f219842cbabaf78abc8100b6656e5>
>> Reviewed by: kevans
>> Approved by: markj (mentor)
>> MFC after: 2 weeks
>> Sponsored by: FreeBSD Foundation
>> Differential Revision: https://reviews.freebsd.org/D50740
>> <https://reviews.freebsd.org/D50740>
>> ---
>> lib/libusb/libusb.h | 5 ++++-
>> lib/libusb/libusb10_desc.c | 11 ++++++-----
>> lib/libusb/libusb20_desc.h | 6 +++++-
>> 3 files changed, 15 insertions(+), 7 deletions(-)
>> diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h
>> index 0aad29aa4ecc..491af3d0a5ec 100644
>> --- a/lib/libusb/libusb.h
>> +++ b/lib/libusb/libusb.h
>> @@ -418,7 +418,10 @@ typedef struct libusb_bos_descriptor {
>> uint8_t bLength;
>> uint8_t bDescriptorType;
>> uint16_t wTotalLength;
>> - uint8_t bNumDeviceCapabilities;
>> +#ifndef bNumDeviceCapabilities
>> +#define bNumDeviceCapabilities bNumDeviceCaps
>> +#endif
>> + uint8_t bNumDeviceCaps;
>> struct libusb_usb_2_0_device_capability_descriptor
>> *usb_2_0_ext_cap;
>> struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap;
>> struct libusb_bos_dev_capability_descriptor **dev_capability;
>> diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c
>> index 3e36009cbb3a..5f4c46740688 100644
>> --- a/lib/libusb/libusb10_desc.c
>> +++ b/lib/libusb/libusb10_desc.c
>> @@ -470,10 +470,11 @@ libusb_parse_bos_descriptor(const void *buf,
>> int len,
>> ptr->bDescriptorType = dtype;
>> ptr->wTotalLength = ((const uint8_t *)buf)[2] |
>> (((const uint8_t *)buf)[3] << 8);
>> - ptr->bNumDeviceCapabilities = ((const
>> uint8_t *)buf)[4];
>> + ptr->bNumDeviceCaps = ((const uint8_t *)buf)[4];
>> ptr->usb_2_0_ext_cap = NULL;
>> ptr->ss_usb_cap = NULL;
>> - ptr->dev_capability = calloc(ptr-
>> >bNumDeviceCapabilities, sizeof(void *));
>> + ptr->dev_capability = calloc(ptr-
>> >bNumDeviceCaps,
>> + sizeof(void *));
>> if (ptr->dev_capability == NULL) {
>> free(ptr);
>> return (LIBUSB_ERROR_NO_MEM);
>> @@ -485,7 +486,7 @@ libusb_parse_bos_descriptor(const void *buf, int
>> len,
>> if (dlen >= 3 &&
>> ptr != NULL &&
>> dtype == LIBUSB_DT_DEVICE_CAPABILITY) {
>> - if (index != ptr->bNumDeviceCapabilities) {
>> + if (index != ptr->bNumDeviceCaps) {
>> ptr->dev_capability[index] =
>> malloc(dlen);
>> if (ptr->dev_capability[index] ==
>> NULL) {
>> libusb_free_bos_descriptor(ptr);
>> @@ -542,7 +543,7 @@ libusb_parse_bos_descriptor(const void *buf, int
>> len,
>> }
>> if (ptr != NULL) {
>> - ptr->bNumDeviceCapabilities = index;
>> + ptr->bNumDeviceCaps = index;
>> return (0); /* success */
>> }
>> @@ -557,7 +558,7 @@ libusb_free_bos_descriptor(struct
>> libusb_bos_descriptor *bos)
>> if (bos == NULL)
>> return;
>> - for (i = 0; i != bos->bNumDeviceCapabilities; i++)
>> + for (i = 0; i != bos->bNumDeviceCaps; i++)
>> free(bos->dev_capability[i]);
>> free(bos->dev_capability);
>> free(bos);
>> diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h
>> index 017148a34b1c..0f7c9294ebc8 100644
>> --- a/lib/libusb/libusb20_desc.h
>> +++ b/lib/libusb/libusb20_desc.h
>> @@ -298,11 +298,15 @@ LIBUSB20_MAKE_STRUCT(LIBUSB20_USB_20_DEVCAP_DESC);
>> LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);
>> +#ifndef bNumDeviceCapabilities
>> +#define bNumDeviceCapabilities bNumDeviceCaps
>> +#endif
>> +
>> #define LIBUSB20_BOS_DESCRIPTOR(m,n) \
>> m(n, UINT8_T, bLength, ) \
>> m(n, UINT8_T, bDescriptorType, ) \
>> m(n, UINT16_T, wTotalLength, ) \
>> - m(n, UINT8_T, bNumDeviceCapabilities, ) \
>> + m(n, UINT8_T, bNumDeviceCaps, ) \
>> LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);
>>
--
Best Regards.
ShengYi Hung.