Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp138880pxp; Fri, 11 Mar 2022 00:52:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAYUsrI17ZmaNg2Q9+DGfDjRwkzut6RhXUnT9cXFfnhymjJDoZhYIf81M+4Z2K+cSEYVOp X-Received: by 2002:a05:6402:51c7:b0:416:401c:cd7c with SMTP id r7-20020a05640251c700b00416401ccd7cmr7933975edd.224.1646988746600; Fri, 11 Mar 2022 00:52:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646988746; cv=none; d=google.com; s=arc-20160816; b=t+FEaFI8fJ39iBfZNdJApAydFL9cjtVM4Eu0MlN19pb7XDs7GEceO+qm7OfjOXV62O U6THjEWSQFYSkVgSz4GeEsQDCFYaCA18KbX45T7id1S5qz6NHK72iIuuEUu3IMdJLWvs Zdbzoh2k2pF0bx11wr8/nPEmuRv26+9kT1+DSA1//d0srLU9N4FWnJ5KsGRpc2UYqeKv LjpKYcU9JTbPtDGXfHADyAhJokaTPk3vjpqx5n5al7DTUw3zylmLcE5vtdw1+SJ2hQds 6kzGrLaYEDGDZ2ilEMFmWfPVq379uqYvQ9ufGB/jAW9nDBboZUA1xax/sjh583sDMxG/ llFw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c5IT3PbDgaeY8qmsercAMGNkkxjzO2Aj3HUs/2+UID8=; b=WmPFX0TJwiuI8QR3/CsaqkhNfy1lrWWOLCLFo+1urTDgk6AqsuM/zQ0B/7nIfRzypu PuxslOa8HQh9xVUJC1PukVCYyuN6y1WRtvsB3zzmODmPiyREZHxxhnv3K1JcIwoWDdbh JxkHipT5VjgPt4iB39IusqxBxxJj0Jxz1pmUOn+O2IJoyYj/pdu690JkfcR/XKCQMVyz R+XZyqg5e5912IMETQgYL65AjDtDJOL2/SLbt1ukowcPpPn9VhNfc00ldqRzOw6AjSkj 4vhJoT7H0pXHqMwvdmnYnaoROYjqJpWL9HdfkutFMG6pQNPR2qD5c9FMo4KtM6pViAZz w9/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="I8gC/ZR5"; 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 q17-20020a056402519100b00416a4482abcsi1410620edd.121.2022.03.11.00.52.01; Fri, 11 Mar 2022 00:52:26 -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="I8gC/ZR5"; 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 S1345996AbiCKD2W (ORCPT + 99 others); Thu, 10 Mar 2022 22:28:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239978AbiCKD2V (ORCPT ); Thu, 10 Mar 2022 22:28:21 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36B71A2735; Thu, 10 Mar 2022 19:27:19 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id h5so5269279plf.7; Thu, 10 Mar 2022 19:27:19 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=c5IT3PbDgaeY8qmsercAMGNkkxjzO2Aj3HUs/2+UID8=; b=I8gC/ZR5OTbu1QF7F/SSzj98hGkRp/bJfRkJTANyUlPrycfofYDfEF2fvzXH092+ki +7t3oiMEjkt54UlIHrGLn4ZVbIAmOTLcFBb7ahVfHdNgLxWeA7vAbUR8BQSnooiXwQmy xB6n606rXuBGu/GMhzRLGTjID8INq8IM/9Ds3CDjSlluyANsf6hs7eEyos+PIFd62b37 5PTPS8DY733+m4n61+1rLqwp49OP65JVyi4JFaa3YejC+nW6Q3o/j1k+zm4VAyzqcbRe 5WAlijr6xqwBZfBiI5uSH47YKANt+dPTm9itnVe4JUTEzt/1ukzM5sLsiuaslbWcZ5ow c5Sw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=c5IT3PbDgaeY8qmsercAMGNkkxjzO2Aj3HUs/2+UID8=; b=Cdpyx/HTpGAGtaNyEL9Nx1boTmvw97Vd2cb554Nq6EKXvAqNoBj6J0ebD/g5ocq3ZX mojkj9EoHlL6qPHIms3+WajsYxY7dCRdqq0z/U+RNbcfvvkStga+FCDwXNlD+ZNFrWtR POhL0OizJFgjk8l0SJqb8lnpBPpOecge2KjeP5h+2O/J4M903QhTPzgThwNOSQI2KX3X p72GRxBRo++0f64YS/tJqyaD5tHI+ERc8W1ZjRGnNAFP4nzsfoDFkj+9xoQi3AKbYF1r C02yaO/8HDQ0dta88CwOlffmSfIf7xXQ8t9+M1TzgHI92ubiKdG68nWMJD6bgRcfdsqu HdRQ== X-Gm-Message-State: AOAM532uXX9s6tsTt3CM8Xc7XXh2pGLXUejKYLxruBTN1fkmmQ9cT6aa 3dBtvV5JXVNRJ3phT6yBZfyfdCnLk49tcRvt X-Received: by 2002:a17:902:ea0d:b0:151:df90:779f with SMTP id s13-20020a170902ea0d00b00151df90779fmr8608184plg.1.1646969238816; Thu, 10 Mar 2022 19:27:18 -0800 (PST) Received: from localhost.localdomain (114-24-95-63.dynamic-ip.hinet.net. [114.24.95.63]) by smtp.gmail.com with ESMTPSA id b2-20020a056a000a8200b004e1414f0bb1sm9204254pfl.135.2022.03.10.19.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 19:27:18 -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 v2] usb: raw-gadget: return -EINVAL if no proper ep address available Date: Fri, 11 Mar 2022 11:22:38 +0800 Message-Id: <20220311032238.3978-1-jj251510319013@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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, because -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 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c index d86c3a36441e..e5707626c4d4 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_props_matched = false; desc = memdup_user((void __user *)value, sizeof(*desc)); if (IS_ERR(desc)) @@ -787,13 +788,14 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) for (i = 0; i < dev->eps_num; i++) { ep = &dev->eps[i]; - if (ep->state != STATE_EP_DISABLED) - continue; if (ep->addr != usb_endpoint_num(desc) && ep->addr != USB_RAW_EP_ADDR_ANY) continue; if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL)) continue; + ep_props_matched = true; + if (ep->state != STATE_EP_DISABLED) + continue; ep->ep->desc = desc; ret = usb_ep_enable(ep->ep); if (ret < 0) { @@ -815,8 +817,13 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value) goto out_unlock; } - dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n"); - ret = -EBUSY; + if (!ep_props_matched) { + dev_dbg(&dev->gadget->dev, "fail, bad endpoint descriptor\n"); + ret = -EINVAL; + } else { + dev_dbg(&dev->gadget->dev, "fail, no endpoints available\n"); + ret = -EBUSY; + } out_free: kfree(desc); -- 2.25.1