Re: [PATCH] usb: libcomposite: prevent duplicate bEndpointAddress by usb_ep_autoconfig_ss.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Alan,

What do you think if we keep not counter but bitmap in u32 (32 is max
amount of HW endpoints anyway) ?

On Tue, Apr 25, 2023 at 4:32 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Apr 25, 2023 at 02:08:10PM +0200, Wlodzimierz Lipert wrote:
> > usb_ep_autoconfig_ss tries to use endpoint name or internal counters to generate
> > bEndpointAddress - this leads to duplicate addresses. Fix is simple -
> > use only internal counter and dont rely on ep naming scheme.
>
> I don't think that's the right fix.  On some UDCs the endpoint number
> really is determined by the hardware; you can't change it.  That's why
> the number is part of the endpoint's name.
>
> The proper fix would be to check, when using the internal counter,
> whether a particular endpoint number is already reserved, and skip over
> it if it is.
>
> Alan Stern
>
> PS: usb_ep_autoconfig_ss() isn't part of libcomposite.  It's available
> for use by any gadget, whether that gadget uses the composite framework
> or not.
>
> >
> > Signed-off-by: Wlodzimierz Lipert <wlodzimierz.lipert@xxxxxxxxx>
> > ---
> >  drivers/usb/gadget/epautoconf.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
> > index 1eb4fa2e623f..40adf09079ed 100644
> > --- a/drivers/usb/gadget/epautoconf.c
> > +++ b/drivers/usb/gadget/epautoconf.c
> > @@ -93,10 +93,7 @@ struct usb_ep *usb_ep_autoconfig_ss(
> >
> >       /* report address */
> >       desc->bEndpointAddress &= USB_DIR_IN;
> > -     if (isdigit(ep->name[2])) {
> > -             u8 num = simple_strtoul(&ep->name[2], NULL, 10);
> > -             desc->bEndpointAddress |= num;
> > -     } else if (desc->bEndpointAddress & USB_DIR_IN) {
> > +     if (desc->bEndpointAddress & USB_DIR_IN) {
> >               if (++gadget->in_epnum > 15)
> >                       return NULL;
> >               desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum;
> > --
> > 2.39.2
> >



-- 
BR/Pozdrawiam. Wlodzimierz Lipert




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux