Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3691009pxj; Tue, 15 Jun 2021 06:40:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoeQoJe7cY6+NzWtnq7mkL4pmdRX+PedkY69tsdKAqQou4MXp8wgnxI6wIT29ZlEC2vG5D X-Received: by 2002:a92:b74d:: with SMTP id c13mr2539769ilm.90.1623764422806; Tue, 15 Jun 2021 06:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623764422; cv=none; d=google.com; s=arc-20160816; b=fEbihE+t9ib0ulYln1+itM1YdRpH19qORXrp6ORqTWxVcfJXsmQjdYzPs/kGWI2raO zw6PpaNJUZrfJv+l5oXPIqnmDq3NRMJLnUfmTAGS+u/R9OB4NHA/rjCYG9mcYfdT/uwp 0qFZHP06XFjMXAvzQ4f2Of7J0D3FBrexlRcF+9MbGPniA0OePg5hBbUx3/uNPriHa1kT xIXGb9KHX02ECszOhIp7SLkSnhQyvT7HaGyuMB7SO2jlrFJEQBPy465X5oJWqZFDTkJ0 Et9yllNAvOT7TUv14zVTkqbaAjHoZ8iSKK7GXOdFkNN76tLnru6ZYqv66n6Ag4bHZueM IZHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iZaAZBVkyPNq73c+DUkWPoSGsiCuppffgICjrBjsdek=; b=uiCR9Ema8ni0qgSiUEFHIwJPN+WVBYZt8N2sgH6oRbieFGtPnKF7K2RjgQ0rUNKNHR Dn8pZG7AWfMXHCAbMVw/QGOt6vV/jgdi49AQKhbiy5ecJtUR38DkSsTP5TnYpYaJhT71 3uwSfqrLuNsNm/iqPs2W7uCzEBosmLYz/4hQezeAWAa8R6uvNGVJG0LmmRHlSdAfvyf4 NphXsabaRexFGVskt3CzTvd67q5pMegS2XIkrL645xY+hdFFPdyatZjxoX0Eyi5bFP4X vEhQ1DdS2FchcvCv42iauJT/5rWfGjGqVzhqFAbDn24UsIdhTmyeHs6KmpMhnRiTxfd9 TUBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rl7MmoXO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m36si21464714jav.108.2021.06.15.06.40.10; Tue, 15 Jun 2021 06:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rl7MmoXO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231769AbhFONlE (ORCPT + 99 others); Tue, 15 Jun 2021 09:41:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231748AbhFONko (ORCPT ); Tue, 15 Jun 2021 09:40:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4FA9D61433; Tue, 15 Jun 2021 13:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623764318; bh=O5Y0aKLxP57G6eD4VvQhfLKkS1JXEl1LRNGOPnF/hhg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=rl7MmoXOauyx9rjlIhYd60x5xmj8BZDlXURvfNidi4nP5SfIr6NuUxfhe5bGaNFvq 2ZufZyh25IELO2p+VYaK8c/znj4IOObgd1oiwwSi+BXtFv5RvlensWNQ2ri5O5sBM5 Z4ArQrpofp7/GIE1h2q1G7BJXnN0lcYO4RG9Ixmc= Date: Tue, 15 Jun 2021 15:38:35 +0200 From: Greg Kroah-Hartman To: Linyu Yuan Cc: Felipe Balbi , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Linyu Yuan Subject: Re: [PATCH v2] usb: gadget: eem: fix echo command packet response issue Message-ID: References: <20210614234133.17708-1-linyyuan@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210614234133.17708-1-linyyuan@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 15, 2021 at 07:41:33AM +0800, Linyu Yuan wrote: > From: Linyu Yuan > > 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. > > Signed-off-by: Linyu Yuan > --- > > v2: fix mail format and expand commit message > > drivers/usb/gadget/function/f_eem.c | 44 +++++++++++++++++++++++++---- > 1 file changed, 39 insertions(+), 5 deletions(-) > > diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c > index 2cd9942707b4..7de355c63189 100644 > --- a/drivers/usb/gadget/function/f_eem.c > +++ b/drivers/usb/gadget/function/f_eem.c > @@ -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,13 +449,37 @@ 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) > + goto freeskb; > + > + ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); > + if (!ctx) > + goto freereq; > + ctx->skb = skb2; > + ctx->ep = ep; > + > + req->buf = kmalloc(skb2->len, GFP_KERNEL); > + if (!req->buf) > + goto freectx; > + > skb_copy_bits(skb2, 0, req->buf, skb2->len); > req->length = skb2->len; > req->complete = eem_cmd_complete; > req->zero = 1; > - req->context = skb2; > - if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC)) > + req->context = ctx; > + if (usb_ep_queue(ep, req, GFP_ATOMIC)) { > DBG(cdev, "echo response queue fail\n"); > + kfree(req->buf); > +freectx: > + kfree(ctx); > +freereq: > + usb_ep_free_request(ep, req); > +freeskb: > + dev_kfree_skb_any(skb2); As much fun as it is jumping to the middle of a case statement, are you sure you want to maintain this? And you do not return an error? Why not? What happens then? thanks, greg k-h