Re: [PATCH] can: gs_usb.c: add usb endpoint address detection at driver probe step

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

 



On 03.09.2024 13:15:15, Vincent Mailhol wrote:
> From the discussion you had with Marc, it seems that this patch is a
> bug fix, right? Then, it is important to put the Fixes tag so that
> this patch gets picked by the stable team so that the stable releases
> also get the fix. The fix tag syntax is also explained in the link
> which Marc previously shared with you:
> 
>   https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes

I've added the Fixes tag.

> 
> > Signed-off-by: Alexander Kozhinov <ak.alexander.kozhinov@xxxxxxxxx>
> > ---
> >  drivers/net/can/usb/gs_usb.c | 36 ++++++++++++++++++++++++++++++------
> >  1 file changed, 30 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> > index bc86e9b329fd..5f10cd9bced5 100644
> > --- a/drivers/net/can/usb/gs_usb.c
> > +++ b/drivers/net/can/usb/gs_usb.c
> > @@ -43,9 +43,6 @@
> >  #define USB_XYLANTA_SAINT3_VENDOR_ID 0x16d0
> >  #define USB_XYLANTA_SAINT3_PRODUCT_ID 0x0f30
> >
> > -#define GS_USB_ENDPOINT_IN 1
> > -#define GS_USB_ENDPOINT_OUT 2
> > -
> >  /* Timestamp 32 bit timer runs at 1 MHz (1 µs tick). Worker accounts
> >   * for timer overflow (will be after ~71 minutes)
> >   */
> > @@ -336,6 +333,9 @@ struct gs_usb {
> >
> >         unsigned int hf_size_rx;
> >         u8 active_channels;
> > +
> > +       u8 ep_in;
> > +       u8 ep_out;
> >  };
> >
> >  /* 'allocate' a tx context.
> > @@ -687,7 +687,7 @@ static void gs_usb_receive_bulk_callback(struct urb *urb)
> >
> >  resubmit_urb:
> >         usb_fill_bulk_urb(urb, parent->udev,
> > -                         usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN),
> > +                         usb_rcvbulkpipe(parent->udev, parent->ep_in),
> >                           hf, dev->parent->hf_size_rx,
> >                           gs_usb_receive_bulk_callback, parent);
> >
> > @@ -819,7 +819,7 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
> >         }
> >
> >         usb_fill_bulk_urb(urb, dev->udev,
> > -                         usb_sndbulkpipe(dev->udev, GS_USB_ENDPOINT_OUT),
> > +                         usb_sndbulkpipe(dev->udev, dev->parent->ep_out),
> >                           hf, dev->hf_size_tx,
> >                           gs_usb_xmit_callback, txc);
> >
> > @@ -926,7 +926,7 @@ static int gs_can_open(struct net_device *netdev)
> >                         usb_fill_bulk_urb(urb,
> >                                           dev->udev,
> >                                           usb_rcvbulkpipe(dev->udev,
> > -                                                         GS_USB_ENDPOINT_IN),
> > +                                                         dev->parent->ep_in),
> >                                           buf,
> >                                           dev->parent->hf_size_rx,
> >                                           gs_usb_receive_bulk_callback, parent);
> > @@ -1421,6 +1421,26 @@ static int gs_usb_probe(struct usb_interface *intf,
> >         struct gs_device_config dconf;
> >         unsigned int icount, i;
> >         int rc;
> > +       struct usb_host_interface *host_iface;
> > +       u8 ep_in = 0, ep_out = 0;
> > +
> > +       host_iface = intf->cur_altsetting;
> > +
> > +       /* check interface endpoint addresses */
> > +       for (i = 0; i < host_iface->desc.bNumEndpoints; i++) {
> > +               struct usb_endpoint_descriptor *ep = &host_iface->endpoint[i].desc;
> > +
> > +               if (usb_endpoint_is_bulk_in(ep)) {
> > +                       ep_in = ep->bEndpointAddress;
> > +               } else if (usb_endpoint_is_bulk_out(ep)) {
> > +                       ep_out = ep->bEndpointAddress;
> > +               }
> > +       }
> 
> The usb_find_common_endpoints() and
> usb_find_common_endpoints_reverse() helper functions do something
> similar to what you are trying to achieve here:
> 
>   https://elixir.bootlin.com/linux/v6.10.7/source/drivers/usb/core/usb.c#L118
> 
> Can you refactor your code to use these helpers instead?

Thanks for pointing to the helpers, I'll rework the code.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux