From patchwork Wed Oct 29 14:20:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 39785 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3AD2924046 for ; Wed, 29 Oct 2014 14:20:54 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id b13sf782266wgh.10 for ; Wed, 29 Oct 2014 07:20:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type; bh=S6IpzMARrUCmTBwJLIc2l0ZrFnXhu64Aa/D3yWvj+/M=; b=AnzYeZiPL4HRBfuy9ilf3IvSTe+2APVDGMiLla/Z1Te+bCp1qcpWiBbKYNxbzf0Hx8 fD51lsYnRdZZMVObrVHeV/GarTh5HRSLj/pzJXHMkTCU9CGbSlewDsPUhC6SLwMvrBJI zsxyjdTgP8f+RSeVo2ZQy9Sz3mUI7cRwxpQQAqaPBlQ8r/cwq2iBzR/V6GZ1Ln8sL/Af TyNAv6kkEyAhv5EY0w2mKewdjB5ca3lC0riMDaXw9d13iurR3UlzdPVjAbbBMUTJPAv7 Q+P3QLDTFCHHXLoj++GQh+uzsha8GvzJG9igRxFrUj6sjCOfU8OdHtyQbCuOLPCYDFJH k1dg== X-Gm-Message-State: ALoCoQmpi44LPDeDqKFtMZ4COUumL4AGH3FuhDrswGEch1MjeIPUbX2lcqbdtqjn4hmMhHFrl4Ng X-Received: by 10.180.74.130 with SMTP id t2mr1926159wiv.4.1414592453418; Wed, 29 Oct 2014 07:20:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.227 with SMTP id v3ls213407lav.91.gmail; Wed, 29 Oct 2014 07:20:53 -0700 (PDT) X-Received: by 10.153.4.44 with SMTP id cb12mr11993533lad.10.1414592453166; Wed, 29 Oct 2014 07:20:53 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id i5si7474892lbd.20.2014.10.29.07.20.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Oct 2014 07:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id w7so2530753lbi.24 for ; Wed, 29 Oct 2014 07:20:53 -0700 (PDT) X-Received: by 10.152.116.102 with SMTP id jv6mr11797309lab.40.1414592453028; Wed, 29 Oct 2014 07:20:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp666539lbz; Wed, 29 Oct 2014 07:20:52 -0700 (PDT) X-Received: by 10.68.211.193 with SMTP id ne1mr5278439pbc.49.1414592451419; Wed, 29 Oct 2014 07:20:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id le15si4188203pab.45.2014.10.29.07.20.50 for ; Wed, 29 Oct 2014 07:20:51 -0700 (PDT) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933203AbaJ2OUs (ORCPT + 3 others); Wed, 29 Oct 2014 10:20:48 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:58310 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932475AbaJ2OUs (ORCPT ); Wed, 29 Oct 2014 10:20:48 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9TEKiar018756; Wed, 29 Oct 2014 09:20:44 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9TEKiwJ000945; Wed, 29 Oct 2014 09:20:44 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 29 Oct 2014 09:20:43 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9TEKhfO028799; Wed, 29 Oct 2014 09:20:43 -0500 From: Felipe Balbi To: Linux USB Mailing List CC: , Felipe Balbi Subject: [PATCH v2] usb: dwc3: gadget: WARN() on bogus usb_ep_queue() Date: Wed, 29 Oct 2014 09:20:20 -0500 Message-ID: <1414592420-18715-1-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.1.0.GIT MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some gadget/function drivers might want to do improper request recycling by allocating a single request from one particular endpoint and queueing it to another completely unrelated endpoint. One such case was found with f_loopback.c. To prevent such cases from happening again, let's WARN() so we get a loud enough failure and persuade users to report errors. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/gadget.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 12f4284..20e4ee9 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1140,8 +1140,14 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, if (!dep->endpoint.desc) { dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", request, ep->name); - spin_unlock_irqrestore(&dwc->lock, flags); - return -ESHUTDOWN; + ret = -ESHUTDOWN; + goto out; + } + + if (WARN(req->dep != dep, "request %p belongs to '%s'\n", + request, req->dep->name)) { + ret = -EINVAL; + goto out; } dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", @@ -1149,6 +1155,8 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, trace_dwc3_ep_queue(req); ret = __dwc3_gadget_ep_queue(dep, req); + +out: spin_unlock_irqrestore(&dwc->lock, flags); return ret;