Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3760936pxv; Mon, 19 Jul 2021 08:09:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6FCbQOcmKx0i4hQSbOBwu/m6BFEiGJsRQ608VL5pVD59qRLEpliZXYl44vaFnU9p8KqN/ X-Received: by 2002:a05:6402:5250:: with SMTP id t16mr9013784edd.317.1626707352107; Mon, 19 Jul 2021 08:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626707352; cv=none; d=google.com; s=arc-20160816; b=i5ImEw41u3NiWu6lcBZVmKFp5G4mD5hQTlUuc8wvjdp/1c0pZht+vTOMkZ86wti4CI /+4/LzMv/RfMjLdmXQcwAtRFRLO9QYxhBCKxF+G5RZ0TcqP1kLqtSlWczRA1iWk8wVTy SfgJde5T9r+Tfjm1KokqGxACnyOmHAP+OyN630y128oAEJo1NWYditQXQzCpHz2J83QW SsDYHtghTxfKK+D1Vb4CDEebO45aECXAoZtZz/g77+5/Tmldd5DLS+GpV/pngpbyB+IN a4ErongF6weamHBLlXAdWVfwDBBwponwSkwxy+8CPV6GHRhznXtgiM6bGxPm9wuQY2u/ NOgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PxliYtEnvaFLLQnSyh5wr6Vkv4qkEiRgPI8U1Uj5voI=; b=UGzyrmoubLFl+wECHzV+oLkoWK3XVEhZG1QO7M84uRKkL4cQV11e+kP8nfNcAQBCZr 0aN+AXYn1Q650RgmNvGDjNgUyl9sANn8ZxYAeAd4afp5IxTqX2Fug8DuEEf4CtBE2ifR cwP7LR/vBVY0EXyBHxCfsw77sXiI3+MTKE47yRQTBuQ40C+uSL9w+gCQgLau3b8vsTZr ezkWhEiPE/psSmefGiOSWPGZHxm+z2ENbfJOWCsJAhLXY0RuEmFN/QNhPV1PQc1ww+Ol YvetBCsKEdw3vUDgh2JS6Z29IRxsTzKSMuTnvuRiLUtISSiaQSJ/Yf1oSAB3rH3ARs6C mXNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nEHDp7Sh; 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 d9si20337531ejy.334.2021.07.19.08.08.49; Mon, 19 Jul 2021 08:09:12 -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=nEHDp7Sh; 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 S243682AbhGSO1M (ORCPT + 99 others); Mon, 19 Jul 2021 10:27:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:56900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244071AbhGSOYr (ORCPT ); Mon, 19 Jul 2021 10:24:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 435AA61165; Mon, 19 Jul 2021 15:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707099; bh=eqFzWPayNPoCKCso05YLOeuq6dcQHUmQ9xy1a69Asxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nEHDp7ShvknubN3+Pbsep4B5w+2qRYBG9R/fuT8ijEV305R9dHhkhKfl659Bkfwgv W7+lVuWNHbH6eAVmBa0kKPaH36BwtbP8pNswVez97ulczHB16Bl2eD7PxvmydXyBzz HfwHaezrT+4RV0dHzt0C3K+6J748u2cYaxTgrzQc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linyu Yuan Subject: [PATCH 4.9 005/245] usb: gadget: eem: fix echo command packet response issue Date: Mon, 19 Jul 2021 16:49:07 +0200 Message-Id: <20210719144940.549460572@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linyu Yuan commit 4249d6fbc10fd997abdf8a1ea49c0389a0edf706 upstream. 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 Cc: stable Link: https://lore.kernel.org/r/20210616115142.34075-1-linyyuan@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_eem.c | 43 ++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) --- a/drivers/usb/gadget/function/f_eem.c +++ b/drivers/usb/gadget/function/f_eem.c @@ -34,6 +34,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); @@ -327,9 +332,12 @@ fail: 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); } /* @@ -417,7 +425,9 @@ static int eem_unwrap(struct gether *por * 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: @@ -446,11 +456,36 @@ static int eem_unwrap(struct gether *por 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;