Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3136707pxp; Tue, 8 Mar 2022 08:20:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5XGkzBOtRCSm6YGxdiMuJs8c7HQ1TXRukDNz2qTPD9TacCh5E2k1Pjzp2v3WGa9QTX1iX X-Received: by 2002:a17:907:1b08:b0:6da:b62a:762a with SMTP id mp8-20020a1709071b0800b006dab62a762amr13962362ejc.60.1646756458329; Tue, 08 Mar 2022 08:20:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646756458; cv=none; d=google.com; s=arc-20160816; b=KCxaLQZ2sqyIuIav5TeNi3xNnH/ZtaZnOK/dK/cx85kb2xzck3MCj8eS9Tnl5QVEgY sduHrMklECITuC4FL7SGiLgGaf/4X19sq68BMtMybVQouoWot/anLLSYZiJazzUqE1YK NuJ8PC21C0sisrTX+QKbm8IT/D0BjwfZNO57x3804+s/WneccmL9rS7Ome2q/mMu5W8+ tNLJrOlRzh6nEnPmzo0dDJdvcSI22erjCTmRteLD+bGnSdzorbJJNFANuSXuwE8umtOk yN/LxB2Qu3bV/uNRmed1zsvjRIxqj3XTBE/SjZR8b0B+ew5FuKLRVT7wiCnRY6IVl6wE uZPg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=HwYw6UCyoABQdRBRd1yhW2c7K50Bveoo4+Wjmoa50zo=; b=HwQRGklbSp1mrN91vYeijbozwdezc5BCU5AUbHWw8Tq8s9GDr+SAMhe+zLaxDWZrB2 mYOzhD1yPDwsb6I/dvaa6IE44Qc5ITUZ8y2foyFNHSrr2shjcfj0I8NAkZWsZI3/rbqg agh9ANgf9rSQM8UHjtDCO/hI38/1slifDO/p1hjqN3LlobLsYcSNxIuWI4P5JDuBlsgt 4Y1/7rzaXHb7+ojg0rjVgKpeVUAUIHCV3CyQ6603xV1cGN3nGW4abx9rEnTuWDAvJWAl pFSRZf0T7bgsIWz2oqtad5SJYVUy1mHd1QjzJBG/pERjoSd/eudCkNhpiQFV52JRat6m 2jdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dM6KzRJG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id do8-20020a170906c10800b006db2ac19afesi4824882ejc.93.2022.03.08.08.20.33; Tue, 08 Mar 2022 08:20:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dM6KzRJG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245283AbiCHLcK (ORCPT + 99 others); Tue, 8 Mar 2022 06:32:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbiCHLcI (ORCPT ); Tue, 8 Mar 2022 06:32:08 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E232842A34; Tue, 8 Mar 2022 03:31:12 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id p3-20020a17090a680300b001bbfb9d760eso1946350pjj.2; Tue, 08 Mar 2022 03:31:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HwYw6UCyoABQdRBRd1yhW2c7K50Bveoo4+Wjmoa50zo=; b=dM6KzRJGdqy0RZKW65Mmi00X1hYAe56e/tarN+bZUJiIEmmQYK3TnQGUmZdgZuzZ7X ncQGosXHgJslwJJTthS1skxibiQF0/m5woIiTSXnmPLiBM556leLnwotm6S44wGNstER r2oc2IrgQ0g7SA57xnNRIXuME8F8FymVEox+vMIRvFPouUbKQ1HbBBezZ2EvRwhvtGiX 6cl+IbVVaC3cveWq97fV9bnn2PvgWGe8kTg2nPAMQTSomhzHjkzS2O1m9q7t5m+mZqa/ 2EL1CBsozUzKyntfzFEllD8zYlUNU899SihgT1O3ZSQWWtZMmDvgkfVVrQyt7boeN/zl 9aOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HwYw6UCyoABQdRBRd1yhW2c7K50Bveoo4+Wjmoa50zo=; b=xvv7XJdp1kdRHnExcdt6RKgyPScRCry/MrD3qBpVNsAtA+I+i9ATUfhMavCHl0d+v9 U+xhHsifZ6BBBC0nt/khhiHglG06EXdh2g02hRZBicqOzPIqQRWPmLOAC4PSf/45FVRJ vB5AADrRaULIyEzld/dHArh4zhmSoz/Zlv8WyDhTcaVt69jzz9NUB8pPwntOi3WrfNQO oyrJ2/RRifFYI04zc3pBdtpUpCkpCVOAZpjXn4aPMTRxdAOLXL4WqfanJ6SbAKLV39lj 9Qr6U28mH9aD7r22AzZ/SNKoB91VcgOAM1ifjyI9lmzA7StEuUWjAMBurRJeeNqJYdpf Euxg== X-Gm-Message-State: AOAM533w1So9tACyQdy7zM9YM7/pbpVq6pELqReE1LFN9FaWorkYssEA W+ecnOpSZKirJkXMLY4j4x4squot/wjqfQ== X-Received: by 2002:a17:902:d505:b0:151:9e65:b844 with SMTP id b5-20020a170902d50500b001519e65b844mr17452429plg.49.1646739071793; Tue, 08 Mar 2022 03:31:11 -0800 (PST) Received: from localhost.localdomain (114-24-142-127.dynamic-ip.hinet.net. [114.24.142.127]) by smtp.gmail.com with ESMTPSA id v66-20020a622f45000000b004f129e7767fsm18470726pfv.130.2022.03.08.03.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:31:11 -0800 (PST) From: Wei Ming Chen To: linux-kernel@vger.kernel.org Cc: andreyknvl@gmail.com, balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, Wei Ming Chen Subject: [PATCH] usb: gadget: return -EINVAL if no proper ep address available Date: Tue, 8 Mar 2022 19:28:32 +0800 Message-Id: <20220308112832.6170-1-jj251510319013@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that only support from ep1-ep4 for both in and out direction, it will return -EBUSY originally. I think it will be more intuitive if we return -EINVAL, Cuz -EBUSY sounds like ep5in is not available now, but might be available in the future. Signed-off-by: Wei Ming Chen --- drivers/usb/gadget/legacy/raw_gadget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c index d86c3a36441e..b4cc083a7ca6 100644 --- a/drivers/usb/gadget/legacy/raw_gadget.c +++ b/drivers/usb/gadget/legacy/raw_gadget.c @@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) unsigned long flags; struct usb_endpoint_descriptor *desc; struct raw_ep *ep; + bool ep_num_matched = false; desc = memdup_user((void __user *)value, sizeof(*desc)); if (IS_ERR(desc)) @@ -792,6 +793,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) if (ep->addr != usb_endpoint_num(desc) && ep->addr != USB_RAW_EP_ADDR_ANY) continue; + ep_num_matched = true; if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL)) continue; ep->ep->desc = desc; @@ -815,6 +817,12 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) goto out_unlock; } + if (!ep_num_matched) { + dev_dbg(&dev->gadget->dev, "fail, no proper ep address available\n"); + ret = -EINVAL; + goto out_free; + } + dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n"); ret = -EBUSY; -- 2.25.1