Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3703445pxp; Tue, 15 Mar 2022 04:45:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxb0UyKOdal79xKw/sUr49M0eEBjkvQgqPRWzotfn6n574po73a0cUpnfGwsU7h8RNMY6KJ X-Received: by 2002:a05:6a00:2168:b0:4f6:eb64:71dd with SMTP id r8-20020a056a00216800b004f6eb6471ddmr28371882pff.40.1647344704247; Tue, 15 Mar 2022 04:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647344704; cv=none; d=google.com; s=arc-20160816; b=hnYaIDl9RtDq2RIiDuowCpBhqIafgZd41ws15uu21a4vkMaE5+e6Tsa9AxUx5h9xu3 xXCC6rHqJUk0Tg5dif44orCyJlhkf9L2E7rsWONF+esmQFt+5hZGsJ5bwGUzR4ba9DQ+ UKPo45aX6V8GMXV7lHrbHlnpxDwot+SY8VEAHh7fZ/SsERUiuL5wLr/5eKNgjWBPag0l 513BSfazheft8unDsVeM8vy+moRE2c6T8PzO8yYHB+oLdBAs+id7FbuuxVKjYwurae02 4nI3cv90x00OwE/uVr4dAGxry05fff60Gv8UJImyZacvo90Ob91nIrrTGuRE9FLDP2An y+2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=i/XezRwvh2gzL6Ttf5VHhgwtutiLUu4G+QBeYqkcdxc=; b=fl9QC1d+QulhmGx6stLXUwTYRK0ACF0HzcpnJMJouujUhpjWoL8DJuWfQ9v8iyTGg3 Lpv6VcqBvwZsS32W1+pP3k9pHRzx/owpOf0JpkGP6yMy4pahybgaIzZRrPLch9WxzHGM iu9qnow49gw9f2zeSNOzNcrcfKN+9E29I3aRwZTeVt3B14vgBiyV18BGHAzYcPk0H+Wg k/2XJJDV73l0eR2qxQSPZOXYlHLA+Wr45bJL8p9TiiU+KGw4vn9sfpjBwUMjccOEilHb EalNjUCCsV7tSJXLuYzt86YK2J6o69oHetBwgUQmMVDoLr9OLuN09TfS/vIVQthT1ibb Gtww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JlswR+2w; 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-20020a170902f79100b0015169d7b9dfsi17578230pln.504.2022.03.15.04.44.52; Tue, 15 Mar 2022 04:45:04 -0700 (PDT) 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=JlswR+2w; 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 S234695AbiCMOx4 (ORCPT + 99 others); Sun, 13 Mar 2022 10:53:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234636AbiCMOxy (ORCPT ); Sun, 13 Mar 2022 10:53:54 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BCDD888E9; Sun, 13 Mar 2022 07:52:46 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id b16so15484650ioz.3; Sun, 13 Mar 2022 07:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=i/XezRwvh2gzL6Ttf5VHhgwtutiLUu4G+QBeYqkcdxc=; b=JlswR+2w6s45M6iLlDIZMJkpJdKO1GUMNUv2bF5jmu+WIK6sGHxzY8408fzrsdZMCr gNyxbdC4rA/9nhGriZeyQFWJT4gL8H2tLm8EHhLuXbfCVMT9YbCDzp+cU/MbGXSd3HkX lO3iX4hAVSmpCejNwl8qkyoLTGvkItlx0bUkyToXQcclkqebDr0MpMjgH8jBXaNgc3vM NgmbaoaGrJnqcHsvvlBNp/lNPK0HeOM32TyFFIQgMMU7yjo1p7gxbwep7M7RgLfvxd7v cqC4HgyK5VNf9MzPWXtrMx7x1dOE/PAoyNfKndC4e5HxBUlxtRQ0kx+3+I2AkFQJRus6 dtBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=i/XezRwvh2gzL6Ttf5VHhgwtutiLUu4G+QBeYqkcdxc=; b=8Qgkuk0v71tf0imNlIvsfOvcF8EFdR1IZgoNLrO7huxCSi96nSJLjYBh9fzCsRUyFR wAF5X7t7rEgHTHG3COE0pQfByHu4keU2yuX7RQ+HXdfLi6XK0wT6Yy2eDA+a6Nz7po6I MQ9HWELVUwim3BNUJFjYav/EbB/hBdD8vIsyWVnUH23ib6YxCFLvizeLJbmXz2G7axTf 8/1tV3ZlqzjsIXgrKcHetIhYcQMNFVwnpkbdUy3zN05LY1lDzdansMRjmYmUrY/1oKtj G9I941eLglMMI7fFkrsyH284D2mmR5mzhj6jarJbf8048Q0K2e31IWQw3wl5RpArZxPW isNA== X-Gm-Message-State: AOAM533oRskQPTRDehB8pbu83/KDXeHdMKopYz64XFdVRDQbE0hAR4EU oc2ZKK/N/4nP1f+6ExTXgsZ180gHbNFwjdyITvFcolpn X-Received: by 2002:a05:6638:a2f:b0:314:b8b9:1c21 with SMTP id 15-20020a0566380a2f00b00314b8b91c21mr16766450jao.22.1647183165672; Sun, 13 Mar 2022 07:52:45 -0700 (PDT) MIME-Version: 1.0 References: <20220311082944.4881-1-jj251510319013@gmail.com> In-Reply-To: <20220311082944.4881-1-jj251510319013@gmail.com> From: Andrey Konovalov Date: Sun, 13 Mar 2022 15:52:35 +0100 Message-ID: Subject: Re: [PATCH v2] usb: raw-gadget: return -EINVAL if no proper ep address available To: Greg Kroah-Hartman , Wei Ming Chen Cc: LKML , Felipe Balbi , USB list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Fri, Mar 11, 2022 at 9:30 AM Wei Ming Chen wrote: > > 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 > Reviewed-by: Andrey Konovalov Greg, could you consider picking this up? Thanks!