Received: by 2002:ac2:48a3:0:0:0:0:0 with SMTP id u3csp553006lfg; Fri, 11 Mar 2022 13:03:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHH4A6pLytisokjC20HGP0bERw/jxzr4c+aaBb9sPMui8C6mgkQEf3KRAsW70FNfHGT0vg X-Received: by 2002:a17:902:f54f:b0:152:7e6:c32d with SMTP id h15-20020a170902f54f00b0015207e6c32dmr12104242plf.125.1647032623432; Fri, 11 Mar 2022 13:03:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647032623; cv=none; d=google.com; s=arc-20160816; b=fz68x1MmBr8K17Q6hKx8WIIdH25wZUlB1IFgTkgBxc4tkH9j118YDHk8951wP2rXXF hcOZpaBVObbYv3A4z/JQodXOvd5WskdWNQ+TwKDzjE0ebmZu0ijEcom1NB4DStaIDggt 2euKd1UfWr7LsFqTR1GxdF8f1qOnH8bHu/CG9xgLv6OImjQiisq9r0CUP6L+Cn66+Hjs yEUL9rEx1huTpzmmTAnL+CjpuXryZRnf88FE52KhtDKDpWAUdi/IQAazKk6JIUCwRY0A tIf+wVm5iQtd/n87YVlz2G5rQavv1OAWnCe8loEUXLQg0cAF7ETMgrKlh538A8N0xmmh snEQ== 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=EVR/EXEx8VwYMh+Mq3TbIRbAjTsCwpmkb5RBazMVbfs=; b=LJ85bDBljonQB/L+BvIaAW98PzuCEmiZnHtsRhjCPHvQWRa0hbzowyCO4ipzkkwVuL PgUCS6oqNjcqT5Ljq39vugbN0asMmfPHX/IwpjyRoYEFo7mMGpQoB+D4hls2GHx2J45S moZTP8sqfrTxzHoq3lKgfBpiKKKdc3jv+7ZWGWNqZdEXFYShwcdVBPf/ADd9XNpRvOQn AWZvRwjfuAKIohRnxFn3P+s6xfts+KlEheB4mKSUbrRkRT8egqMvpVC7BC+le3g4sZu7 G5F3VyUhHgq8XZBc1OjjdaliBQuvoFelFSxmEhiouVfXU+HC9jRCOKCrEyC32P7A+EJO t3nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GNLK00oL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g191-20020a636bc8000000b00380a06365fbsi8224449pgc.766.2022.03.11.13.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 13:03:43 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GNLK00oL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1A7E156961; Fri, 11 Mar 2022 12:49:11 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237252AbiCKIbs (ORCPT + 99 others); Fri, 11 Mar 2022 03:31:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240221AbiCKIbp (ORCPT ); Fri, 11 Mar 2022 03:31:45 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A5F1B98BF; Fri, 11 Mar 2022 00:30:42 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id q29so5928343pgn.7; Fri, 11 Mar 2022 00:30:42 -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=EVR/EXEx8VwYMh+Mq3TbIRbAjTsCwpmkb5RBazMVbfs=; b=GNLK00oLX064vIX+r2kYl2hpm4t94e+rXiqn1qZ9hWMFVkY6aHlbSH8BEbBAsY0Ldy KB7UpyqDEx+aEAnMxJl6Nl3E9H4wxWU1Knh/dmR4kXxg9JgjkKp2s5gTO7PazmLZm4F5 ug9oi8DNyH2TidnPshxULWDwMziBs1Mm74UGEhni4KCZZ1F/pvAGs2QLTee/o+NXCoPx e1Q8+zNhSL0HH2j5cNAHuMhmyya2h5bpdxFqEFGQOT0lbo0Qt4U+F3IZQRIZLr+ufMzv YFN8l03fX2C2ydQiW4D5SBwzqbWJs2F18393kuDS6aObl/l9t9Qp8YIQQ+TU6u5Jq1RJ PRtA== 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=EVR/EXEx8VwYMh+Mq3TbIRbAjTsCwpmkb5RBazMVbfs=; b=ROxHzxYKwUG7U1MvD9CVgnLhrtel81QgBS4TdwZ8MvfHR8oK1V46peJmfqlt/DZ94j 3HPNHd1+SaQRXfS6J9FgrJ2ul6TWrViFnyFnMUxbx/36wAPeyI0JIQ2f0L7OpTP9fUeM E0bJXtxmqHKPrGIaj655/timaGnNio/jKn9JmQEtGLmy2ceDCHARMmizcXFCsZnLL+YX 03PWXX6+iGr6Doo9aMnbviTRb/d9GzPbcOLc0fLRkhBSWqEsat+COFKYjKFtE9VPb7i9 blgztyJjk2LSsmOq2V7ABMZ/7+/3jSaimSYne/aBuBEvt+8JHIYhLQLUiTVRTWAhhEz6 IN4g== X-Gm-Message-State: AOAM531aPtMVaw6VcDmEeRCku4sUZdthJHoR7vVGBVhntFTcCX24Rc9u tJqRIJxWv7AdP0RdVquCVcXolPjoMvGpCaG4 X-Received: by 2002:a63:5451:0:b0:378:6b6c:ed83 with SMTP id e17-20020a635451000000b003786b6ced83mr7469585pgm.446.1646987441896; Fri, 11 Mar 2022 00:30:41 -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 q8-20020a056a00150800b004f7948d14e7sm785465pfu.191.2022.03.11.00.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 00:30:41 -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 16:29:45 +0800 Message-Id: <20220311082944.4881-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.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 --- Changes in v2: - Rename variable from ep_num_matched to ep_props_matched - Incorporate the patch from Andrey Konovalov that cover the foloowing cases: 1. If there are no endpoints that match the provided descriptor, return EINVAL. 2. If there are matching endpoints, but they are all already enabled, return EBUSY. 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