Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 09 Jul 2025 09:08:17 +0800
From:      ShengYi Hung <aokblast@FreeBSD.org>
To:        Kyle Evans <kevans@FreeBSD.org>
Cc:        Adrian Chadd <adrian.chadd@gmail.com>,  src-committers@freebsd.org, dev-commits-src-all@freebsd.org,  dev-commits-src-main@freebsd.org
Subject:   Re: git: f84a0da4e060 - main - libusb: rename bNumDeviceCapabilities to bNumDeviceCaps for compatibility with libusb
Message-ID:  <m2cyaatblq.fsf@FreeBSD.org>
In-Reply-To: <dd8f037e-0350-4b19-acf9-419f18df3471@FreeBSD.org> (Kyle Evans's message of "Tue, 8 Jul 2025 14:44:42 -0500")
References:  <202507081512.568FCeX8049407@gitrepo.freebsd.org> <CAJ-Vmo=42TxJWSFjugcUBucbReumPqeHuw2F=v7WF9ai%2BEi-yA@mail.gmail.com> <dd8f037e-0350-4b19-acf9-419f18df3471@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

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 a=
nyone 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!
>>=20
>
> 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=3Df84a0da4e0608a970c775f3d605f8de2b0b8d322 <https://
>>     cgit.FreeBSD.org/src/commit/?
>>     id=3Df84a0da4e0608a970c775f3d605f8de2b0b8d322>
>>     commit f84a0da4e0608a970c775f3d605f8de2b0b8d322
>>     Author:=C2=A0 =C2=A0 =C2=A0ShengYi Hung <aokblast@FreeBSD.org>
>>     AuthorDate: 2025-06-07 19:43:15 +0000
>>     Commit:=C2=A0 =C2=A0 =C2=A0ShengYi Hung <aokblast@FreeBSD.org>
>>     CommitDate: 2025-07-08 15:11:41 +0000
>>      =C2=A0 =C2=A0 libusb: rename bNumDeviceCapabilities to bNumDeviceCa=
ps for
>>     compatibility with libusb
>>      =C2=A0 =C2=A0 THe member bNumDeviceCapabilities is referred to as
>>     bNumDeviceCaps in
>>      =C2=A0 =C2=A0 the upstream libusb project.
>>      =C2=A0 =C2=A0 To improve compatibility, we are renaming the member
>> accordingly.
>>      =C2=A0 =C2=A0 For backward compatibility, a mocro will be defined t=
o map
>>      =C2=A0 =C2=A0 bNumDeviceCapabilities to bNumDeviceCaps.
>>      =C2=A0 =C2=A0 See: https://github.com/libusb/libusb/
>>     commit/02ebafc85d3f219842cbabaf78abc8100b6656e5 <https://github.com/
>>     libusb/libusb/commit/02ebafc85d3f219842cbabaf78abc8100b6656e5>
>>      =C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 kevans
>>      =C2=A0 =C2=A0 Approved by:=C2=A0 =C2=A0 markj (mentor)
>>      =C2=A0 =C2=A0 MFC after:=C2=A0 =C2=A0 =C2=A0 2 weeks
>>      =C2=A0 =C2=A0 Sponsored by:=C2=A0 =C2=A0FreeBSD Foundation
>>      =C2=A0 =C2=A0 Differential Revision: https://reviews.freebsd.org/D5=
0740
>>     <https://reviews.freebsd.org/D50740>;
>>     ---
>>      =C2=A0lib/libusb/libusb.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 5 ++++-
>>      =C2=A0lib/libusb/libusb10_desc.c | 11 ++++++-----
>>      =C2=A0lib/libusb/libusb20_desc.h |=C2=A0 6 +++++-
>>      =C2=A03 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 {
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t bLength;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t bDescriptorType;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 uint16_t wTotalLength;
>>     -=C2=A0 =C2=A0 =C2=A0 =C2=A0uint8_t bNumDeviceCapabilities;
>>     +#ifndef bNumDeviceCapabilities
>>     +#define bNumDeviceCapabilities bNumDeviceCaps
>>     +#endif
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0uint8_t bNumDeviceCaps;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct libusb_usb_2_0_device_capability=
_descriptor
>>     *usb_2_0_ext_cap;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct libusb_ss_usb_device_capability_=
descriptor *ss_usb_cap;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct libusb_bos_dev_capability_descri=
ptor **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,
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 ptr->bDescriptorType =3D dtype;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 ptr->wTotalLength =3D ((const uint8_t *)buf)[2] |
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (((const uint8_t *)buf)[3] << 8);
>>     -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0ptr->bNumDeviceCapabilities =3D ((const
>>     uint8_t *)buf)[4];
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0ptr->bNumDeviceCaps =3D ((const uint8_t *)buf)[4];
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 ptr->usb_2_0_ext_cap =3D NULL;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 ptr->ss_usb_cap =3D NULL;
>>     -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0ptr->dev_capability =3D calloc(ptr-
>>      >bNumDeviceCapabilities, sizeof(void *));
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0ptr->dev_capability =3D calloc(ptr-
>>      >bNumDeviceCaps,
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sizeof(void *));
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 if (ptr->dev_capability =3D=3D NULL) {
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 free(ptr);
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return (LIBUSB_ERROR_NO_MEM);
>>     @@ -485,7 +486,7 @@ libusb_parse_bos_descriptor(const void *buf, int
>>     len,
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (dlen >=
=3D 3 &&
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 ptr !=3D NULL &&
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 dtype =3D=3D LIBUSB_DT_DEVICE_CAPABILITY) {
>>     -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0if (index !=3D ptr->bNumDeviceCapabilities) {
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0if (index !=3D ptr->bNumDeviceCaps) {
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ptr->dev_capability[index] =3D
>>     malloc(dlen);
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ptr->dev_capability[index=
] =3D=3D
>>     NULL) {
>>                                                 libusb_free_bos_descript=
or(ptr);
>>     @@ -542,7 +543,7 @@ libusb_parse_bos_descriptor(const void *buf, int
>>     len,
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ptr !=3D NULL) {
>>     -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ptr->bNumDev=
iceCapabilities =3D index;
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ptr->bNumDev=
iceCaps =3D index;
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return (0);=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* success */
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>>     @@ -557,7 +558,7 @@ libusb_free_bos_descriptor(struct
>>     libusb_bos_descriptor *bos)
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (bos =3D=3D NULL)
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
>>     -=C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i !=3D bos->bNumDeviceCapa=
bilities; i++)
>>     +=C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i !=3D bos->bNumDeviceCaps=
; i++)
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 free(bos->d=
ev_capability[i]);
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 free(bos->dev_capability);
>>      =C2=A0 =C2=A0 =C2=A0 =C2=A0 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_DE=
SC);
>>      =C2=A0LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);
>>     +#ifndef bNumDeviceCapabilities
>>     +#define bNumDeviceCapabilities bNumDeviceCaps
>>     +#endif
>>     +
>>      =C2=A0#define=C2=A0 =C2=A0 =C2=A0 =C2=A0 LIBUSB20_BOS_DESCRIPTOR(m,=
n) \
>>      =C2=A0 =C2=A0m(n, UINT8_T,=C2=A0 bLength, ) \
>>      =C2=A0 =C2=A0m(n, UINT8_T,=C2=A0 bDescriptorType, ) \
>>      =C2=A0 =C2=A0m(n, UINT16_T, wTotalLength, ) \
>>     -=C2=A0 m(n, UINT8_T,=C2=A0 bNumDeviceCapabilities, ) \
>>     +=C2=A0 m(n, UINT8_T,=C2=A0 bNumDeviceCaps, ) \
>>      =C2=A0LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);
>>=20

--=20
Best Regards.
ShengYi Hung.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m2cyaatblq.fsf>