usb: gadget: eem: fix echo command packet response issue
PATCH v3 1/1 usb: gadget: eem: fix echo command packet response issue
From: Linyu Yuan <[email protected]>
when receive eem echo command, it will send a response, but queue this response to the usb request which allocate from gadget device endpoint zero,
and transmit the request to IN endpoint of eem interface.
on dwc3 gadget, it will trigger following warning in function __dwc3_gadget_ep_queue(),
if (WARN(req->dep != dep, "request %pK belongs to '%s'\n", &req->request, req->dep->name)) return -EINVAL;
fix it by allocating a usb request from IN endpoint of eem interface, and transmit the usb request to same IN endpoint of eem interface.
---
v3: use exist goto label 'next'
v2: fix mail format and expand commit message
drivers/usb/gadget/function/f_eem.c | 43 ++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-)
drivers/usb/gadget/function/f_eem.c +39 -4
@@ -30,6 +30,11 @@ struct f_eem {u8 ctrl_id; }; +struct in_context { +struct sk_buff *skb; +struct usb_ep *ep; +}; +static inline struct f_eem *func_to_eem (struct usb_function *f) { return container_of(f, struct f_eem, port.func);
@@ -320,9 +325,12 @@ static int eem_bind(struct usb_configuration *c, struct usb_function *f)static void eem_cmd_complete (struct usb_ep *ep,struct usb_request *req) { -struct sk_buff *skb = (struct sk_buff *)req->context; +struct in_context *ctx = req->context; -dev_kfree_skb_any (skb); +dev_kfree_skb_any (ctx->skb); +kfree (req->buf); +usb_ep_free_request (ctx->ep, req); +kfree (ctx); }/*
@@ -410,7 +418,9 @@ static int eem_unwrap(struct gether *port,* b15: bmType (0 == data, 1 == command) */ if (header &BIT (15 )) { -struct usb_request *req = cdev->req; +struct usb_request *req; +struct in_context *ctx; +struct usb_ep *ep;u16 bmEEMCmd;/* EEM command packet format:
@@ -439,11 +449,36 @@ static int eem_unwrap(struct gether *port,skb_trim (skb2, len);put_unaligned_le16 (BIT (15 ) |BIT (11 ) | len,skb_push (skb2,2 )); + + ep = port->in_ep; + req =usb_ep_alloc_request (ep,GFP_ATOMIC ); +if (!req) { +dev_kfree_skb_any (skb2); + goto next; + } + + req->buf =kmalloc (skb2->len,GFP_KERNEL ); +if (!req->buf) { +usb_ep_free_request (ep, req); +dev_kfree_skb_any (skb2); + goto next; + } + + ctx =kmalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) { +kfree (req->buf); +usb_ep_free_request (ep, req); +dev_kfree_skb_any (skb2); + goto next; + } + ctx->skb = skb2; + ctx->ep = ep; +skb_copy_bits (skb2,0 , req->buf, skb2->len); req->length = skb2->len; req->complete = eem_cmd_complete; req->zero =1 ; - req->context = skb2; + req->context = ctx;if (usb_ep_queue (port->in_ep, req,GFP_ATOMIC ))DBG (cdev,"echo response queue fail\n" );break ;
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 7 lines · Linyu Yuan
From: Linyu Yuan <[email protected]>
when receive eem echo command, it will send a response, but queue this response to the usb request which allocate from gadget device endpoint zero,
and transmit the request to IN endpoint of eem interface.
Quoted 6 lines
on dwc3 gadget, it will trigger following warning in function
__dwc3_gadget_ep_queue(),if (WARN(req->dep != dep, "request %pK belongs to '%s'\n", &req->request, req->dep->name)) return -EINVAL;
Is this really a problem? I am guessing the request will not work at all? Or just warn and continue with it?
How was this ever working?
Quoted 6 lines
fix it by allocating a usb request from IN endpoint of eem interface, and transmit the usb request to same IN endpoint of eem interface.
Signed-off-by Linyu Yuan <[email protected]>---
What commit does this fix? Should it be backported to older stable kernels? If so, how far back?
thanks,
greg k-h
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Linyu Yuan
From: Linyu Yuan <[email protected]>
when receive eem echo command, it will send a response, but queue this response to the usb request which allocate from gadget device endpoint zero,
and transmit the request to IN endpoint of eem interface.on dwc3 gadget, it will trigger following warning in function
__dwc3_gadget_ep_queue(),
Quoted 6 lines
Quoted 3 lines
if (WARN(req->dep != dep, "request %pK belongs to '%s'\n", &req->request, req->dep->name)) return -EINVAL;Is this really a problem? I am guessing the request will not work at all? Or just warn and continue with it?
yes, it is a real problem of f_eem driver which request from it will queue fail, which means following error happen.
if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC)) DBG(cdev, "echo response queue fail\n");
Quoted 2 lines
How was this ever working?
i think for eem link command packet, normally we will never seen it if both side arelinux system. as eem driver will add data header and send it to peer.
only it is eem driver bug which read network data as link command packet (this issue fixed in my last change).
Quoted 10 lines
Quoted 7 lines
fix it by allocating a usb request from IN endpoint of eem interface, and transmit the usb request to same IN endpoint of eem interface.
Signed-off-by Linyu Yuan <[email protected]>---
What commit does this fix? Should it be backported to older stable kernels? If so, how far back?
yes, we can backport to all active LTS kernel.
Quoted 4 lines
thanks,
greg k-h