Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jul 2025 12:40:33 -0700
From:      Adrian Chadd <adrian.chadd@gmail.com>
To:        ShengYi Hung <aokblast@freebsd.org>
Cc:        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:  <CAJ-Vmo=42TxJWSFjugcUBucbReumPqeHuw2F=v7WF9ai%2BEi-yA@mail.gmail.com>
In-Reply-To: <202507081512.568FCeX8049407@gitrepo.freebsd.org>
References:  <202507081512.568FCeX8049407@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000124ea00639702305
Content-Type: text/plain; charset="UTF-8"

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!



-adrian


On Tue, 8 Jul 2025 at 08:12, ShengYi Hung <aokblast@freebsd.org> wrote:

> The branch main has been updated by aokblast:
>
> URL:
> 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
>
>     Reviewed by:    kevans
>     Approved by:    markj (mentor)
>     MFC after:      2 weeks
>     Sponsored by:   FreeBSD Foundation
>     Differential Revision: 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);
>
>

--000000000000124ea00639702305
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>hi! Thanks for this!</div><div><br></div><div>Could w=
e possibly wrap stuff like these compat macros in a #define that we can und=
efine? So we can make sure no new code shows up that uses the &quot;old&quo=
t; paths?</div><div><br></div><div>eg LIBUSB10_NO_BACKWARDS_COMPAT / LIBUSB=
20_NO_BACKWARDS_COMPAT ?</div><div><br></div><div>Thanks!</div><div><br></d=
iv><div><br></div><div><br></div><div>-adrian</div><div><br></div></div><br=
><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D=
"gmail_attr">On Tue, 8 Jul 2025 at 08:12, ShengYi Hung &lt;<a href=3D"mailt=
o:aokblast@freebsd.org">aokblast@freebsd.org</a>&gt; wrote:<br></div><block=
quote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1=
px solid rgb(204,204,204);padding-left:1ex">The branch main has been update=
d by aokblast:<br>
<br>
URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3Df84a0da4e0608a970=
c775f3d605f8de2b0b8d322" rel=3D"noreferrer" target=3D"_blank">https://cgit.=
FreeBSD.org/src/commit/?id=3Df84a0da4e0608a970c775f3d605f8de2b0b8d322</a><b=
r>
<br>
commit f84a0da4e0608a970c775f3d605f8de2b0b8d322<br>
Author:=C2=A0 =C2=A0 =C2=A0ShengYi Hung &lt;aokblast@FreeBSD.org&gt;<br>
AuthorDate: 2025-06-07 19:43:15 +0000<br>
Commit:=C2=A0 =C2=A0 =C2=A0ShengYi Hung &lt;aokblast@FreeBSD.org&gt;<br>
CommitDate: 2025-07-08 15:11:41 +0000<br>
<br>
=C2=A0 =C2=A0 libusb: rename bNumDeviceCapabilities to bNumDeviceCaps for c=
ompatibility with libusb<br>
<br>
=C2=A0 =C2=A0 THe member bNumDeviceCapabilities is referred to as bNumDevic=
eCaps in<br>
=C2=A0 =C2=A0 the upstream libusb project.<br>
<br>
=C2=A0 =C2=A0 To improve compatibility, we are renaming the member accordin=
gly.<br>
<br>
=C2=A0 =C2=A0 For backward compatibility, a mocro will be defined to map<br=
>
=C2=A0 =C2=A0 bNumDeviceCapabilities to bNumDeviceCaps.<br>
<br>
=C2=A0 =C2=A0 See: <a href=3D"https://github.com/libusb/libusb/commit/02eba=
fc85d3f219842cbabaf78abc8100b6656e5" rel=3D"noreferrer" target=3D"_blank">h=
ttps://github.com/libusb/libusb/commit/02ebafc85d3f219842cbabaf78abc8100b66=
56e5</a><br>
<br>
=C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 kevans<br>
=C2=A0 =C2=A0 Approved by:=C2=A0 =C2=A0 markj (mentor)<br>
=C2=A0 =C2=A0 MFC after:=C2=A0 =C2=A0 =C2=A0 2 weeks<br>
=C2=A0 =C2=A0 Sponsored by:=C2=A0 =C2=A0FreeBSD Foundation<br>
=C2=A0 =C2=A0 Differential Revision: <a href=3D"https://reviews.freebsd.org=
/D50740" rel=3D"noreferrer" target=3D"_blank">https://reviews.freebsd.org/D=
50740</a><br>
---<br>
=C2=A0lib/libusb/libusb.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 5 ++++-<br>
=C2=A0lib/libusb/libusb10_desc.c | 11 ++++++-----<br>
=C2=A0lib/libusb/libusb20_desc.h |=C2=A0 6 +++++-<br>
=C2=A03 files changed, 15 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h<br>
index 0aad29aa4ecc..491af3d0a5ec 100644<br>
--- a/lib/libusb/libusb.h<br>
+++ b/lib/libusb/libusb.h<br>
@@ -418,7 +418,10 @@ typedef struct libusb_bos_descriptor {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t bLength;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint8_t bDescriptorType;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 uint16_t wTotalLength;<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0uint8_t bNumDeviceCapabilities;<br>
+#ifndef bNumDeviceCapabilities<br>
+#define bNumDeviceCapabilities bNumDeviceCaps<br>
+#endif<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0uint8_t bNumDeviceCaps;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct libusb_usb_2_0_device_capability_descrip=
tor *usb_2_0_ext_cap;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct libusb_ss_usb_device_capability_descript=
or *ss_usb_cap;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct libusb_bos_dev_capability_descriptor **d=
ev_capability;<br>
diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c<br>
index 3e36009cbb3a..5f4c46740688 100644<br>
--- a/lib/libusb/libusb10_desc.c<br>
+++ b/lib/libusb/libusb10_desc.c<br>
@@ -470,10 +470,11 @@ libusb_parse_bos_descriptor(const void *buf, int len,=
<br>
=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-&gt;bDescriptorType =3D dtype;<br>
=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-&gt;wTotalLength =3D ((const uint8_t *)buf)[2] |<br>
=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] &lt;&lt; 8);<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0ptr-&gt;bNumDeviceCapabilities =3D ((const uint8_t *)buf)[4];<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0ptr-&gt;bNumDeviceCaps =3D ((const uint8_t *)buf)[4];<br>
=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-&gt;usb_2_0_ext_cap =3D NULL;<br>
=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-&gt;ss_usb_cap =3D NULL;<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0ptr-&gt;dev_capability =3D calloc(ptr-&gt;bNumDeviceCapabilities,=
 sizeof(void *));<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0ptr-&gt;dev_capability =3D calloc(ptr-&gt;bNumDeviceCaps,<br>
+=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 *));<br>
=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-&gt;dev_capability =3D=3D NULL) {<br>
=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);<br>
=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);<br>
@@ -485,7 +486,7 @@ libusb_parse_bos_descriptor(const void *buf, int len,<b=
r>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (dlen &gt;=3D 3 =
&amp;&amp;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ptr !=
=3D NULL &amp;&amp;<br>
=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) {<br>
-=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-&gt;bNumDeviceCapabilities) {<br>
+=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-&gt;bNumDeviceCaps) {<br>
=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-&gt;dev_capability[index] =3D ma=
lloc(dlen);<br>
=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-&gt;dev_capability[index] =
=3D=3D NULL) {<br>
=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 =C2=A0 =C2=A0 =C2=A0 =C2=A0 libusb_f=
ree_bos_descriptor(ptr);<br>
@@ -542,7 +543,7 @@ libusb_parse_bos_descriptor(const void *buf, int len,<b=
r>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ptr !=3D NULL) {<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ptr-&gt;bNumDeviceC=
apabilities =3D index;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ptr-&gt;bNumDeviceC=
aps =3D index;<br>
=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 */<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>
<br>
@@ -557,7 +558,7 @@ libusb_free_bos_descriptor(struct libusb_bos_descriptor=
 *bos)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (bos =3D=3D NULL)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>
<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i !=3D bos-&gt;bNumDeviceCapabili=
ties; i++)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0for (i =3D 0; i !=3D bos-&gt;bNumDeviceCaps; i+=
+)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 free(bos-&gt;dev_ca=
pability[i]);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 free(bos-&gt;dev_capability);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 free(bos);<br>
diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h<br>
index 017148a34b1c..0f7c9294ebc8 100644<br>
--- a/lib/libusb/libusb20_desc.h<br>
+++ b/lib/libusb/libusb20_desc.h<br>
@@ -298,11 +298,15 @@ LIBUSB20_MAKE_STRUCT(LIBUSB20_USB_20_DEVCAP_DESC);<br=
>
<br>
=C2=A0LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);<br>
<br>
+#ifndef bNumDeviceCapabilities<br>
+#define bNumDeviceCapabilities bNumDeviceCaps<br>
+#endif<br>
+<br>
=C2=A0#define=C2=A0 =C2=A0 =C2=A0 =C2=A0 LIBUSB20_BOS_DESCRIPTOR(m,n) \<br>
=C2=A0 =C2=A0m(n, UINT8_T,=C2=A0 bLength, ) \<br>
=C2=A0 =C2=A0m(n, UINT8_T,=C2=A0 bDescriptorType, ) \<br>
=C2=A0 =C2=A0m(n, UINT16_T, wTotalLength, ) \<br>
-=C2=A0 m(n, UINT8_T,=C2=A0 bNumDeviceCapabilities, ) \<br>
+=C2=A0 m(n, UINT8_T,=C2=A0 bNumDeviceCaps, ) \<br>
<br>
=C2=A0LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);<br>
<br>
</blockquote></div>

--000000000000124ea00639702305--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-Vmo=42TxJWSFjugcUBucbReumPqeHuw2F=v7WF9ai%2BEi-yA>