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
[-- Attachment #1 --] 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); > > [-- Attachment #2 --] <div dir="ltr"><div>hi! Thanks for this!</div><div><br></div><div>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?</div><div><br></div><div>eg LIBUSB10_NO_BACKWARDS_COMPAT / LIBUSB20_NO_BACKWARDS_COMPAT ?</div><div><br></div><div>Thanks!</div><div><br></div><div><br></div><div><br></div><div>-adrian</div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, 8 Jul 2025 at 08:12, ShengYi Hung <<a href="mailto:aokblast@freebsd.org">aokblast@freebsd.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The branch main has been updated by aokblast:<br> <br> URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=f84a0da4e0608a970c775f3d605f8de2b0b8d322" rel="noreferrer" target="_blank">https://cgit.FreeBSD.org/src/commit/?id=f84a0da4e0608a970c775f3d605f8de2b0b8d322</a><br> <br> commit f84a0da4e0608a970c775f3d605f8de2b0b8d322<br> Author: ShengYi Hung <aokblast@FreeBSD.org><br> AuthorDate: 2025-06-07 19:43:15 +0000<br> Commit: ShengYi Hung <aokblast@FreeBSD.org><br> CommitDate: 2025-07-08 15:11:41 +0000<br> <br> libusb: rename bNumDeviceCapabilities to bNumDeviceCaps for compatibility with libusb<br> <br> THe member bNumDeviceCapabilities is referred to as bNumDeviceCaps in<br> the upstream libusb project.<br> <br> To improve compatibility, we are renaming the member accordingly.<br> <br> For backward compatibility, a mocro will be defined to map<br> bNumDeviceCapabilities to bNumDeviceCaps.<br> <br> See: <a href="https://github.com/libusb/libusb/commit/02ebafc85d3f219842cbabaf78abc8100b6656e5" rel="noreferrer" target="_blank">https://github.com/libusb/libusb/commit/02ebafc85d3f219842cbabaf78abc8100b6656e5</a><br> <br> Reviewed by: kevans<br> Approved by: markj (mentor)<br> MFC after: 2 weeks<br> Sponsored by: FreeBSD Foundation<br> Differential Revision: <a href="https://reviews.freebsd.org/D50740" rel="noreferrer" target="_blank">https://reviews.freebsd.org/D50740</a><br> ---<br> lib/libusb/libusb.h | 5 ++++-<br> lib/libusb/libusb10_desc.c | 11 ++++++-----<br> lib/libusb/libusb20_desc.h | 6 +++++-<br> 3 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> uint8_t bLength;<br> uint8_t bDescriptorType;<br> uint16_t wTotalLength;<br> - uint8_t bNumDeviceCapabilities;<br> +#ifndef bNumDeviceCapabilities<br> +#define bNumDeviceCapabilities bNumDeviceCaps<br> +#endif<br> + uint8_t bNumDeviceCaps;<br> struct libusb_usb_2_0_device_capability_descriptor *usb_2_0_ext_cap;<br> struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap;<br> struct libusb_bos_dev_capability_descriptor **dev_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> ptr->bDescriptorType = dtype;<br> ptr->wTotalLength = ((const uint8_t *)buf)[2] |<br> (((const uint8_t *)buf)[3] << 8);<br> - ptr->bNumDeviceCapabilities = ((const uint8_t *)buf)[4];<br> + ptr->bNumDeviceCaps = ((const uint8_t *)buf)[4];<br> ptr->usb_2_0_ext_cap = NULL;<br> ptr->ss_usb_cap = NULL;<br> - ptr->dev_capability = calloc(ptr->bNumDeviceCapabilities, sizeof(void *));<br> + ptr->dev_capability = calloc(ptr->bNumDeviceCaps,<br> + sizeof(void *));<br> if (ptr->dev_capability == NULL) {<br> free(ptr);<br> return (LIBUSB_ERROR_NO_MEM);<br> @@ -485,7 +486,7 @@ libusb_parse_bos_descriptor(const void *buf, int len,<br> if (dlen >= 3 &&<br> ptr != NULL &&<br> dtype == LIBUSB_DT_DEVICE_CAPABILITY) {<br> - if (index != ptr->bNumDeviceCapabilities) {<br> + if (index != ptr->bNumDeviceCaps) {<br> ptr->dev_capability[index] = malloc(dlen);<br> if (ptr->dev_capability[index] == NULL) {<br> libusb_free_bos_descriptor(ptr);<br> @@ -542,7 +543,7 @@ libusb_parse_bos_descriptor(const void *buf, int len,<br> }<br> <br> if (ptr != NULL) {<br> - ptr->bNumDeviceCapabilities = index;<br> + ptr->bNumDeviceCaps = index;<br> return (0); /* success */<br> }<br> <br> @@ -557,7 +558,7 @@ libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos)<br> if (bos == NULL)<br> return;<br> <br> - for (i = 0; i != bos->bNumDeviceCapabilities; i++)<br> + for (i = 0; i != bos->bNumDeviceCaps; i++)<br> free(bos->dev_capability[i]);<br> free(bos->dev_capability);<br> 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> LIBUSB20_MAKE_STRUCT(LIBUSB20_SS_USB_DEVCAP_DESC);<br> <br> +#ifndef bNumDeviceCapabilities<br> +#define bNumDeviceCapabilities bNumDeviceCaps<br> +#endif<br> +<br> #define LIBUSB20_BOS_DESCRIPTOR(m,n) \<br> m(n, UINT8_T, bLength, ) \<br> m(n, UINT8_T, bDescriptorType, ) \<br> m(n, UINT16_T, wTotalLength, ) \<br> - m(n, UINT8_T, bNumDeviceCapabilities, ) \<br> + m(n, UINT8_T, bNumDeviceCaps, ) \<br> <br> LIBUSB20_MAKE_STRUCT(LIBUSB20_BOS_DESCRIPTOR);<br> <br> </blockquote></div>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-Vmo=42TxJWSFjugcUBucbReumPqeHuw2F=v7WF9ai%2BEi-yA>
