Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1235720lfc; Wed, 1 Jun 2022 12:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDkyKXN00X5PGmw9l2kbqAYKXAxLFDPD2pz/E5mXuCvEKD86t2sM58gLqMqTJVc1bPQi0C X-Received: by 2002:a17:90a:5d03:b0:1e0:cc5b:4808 with SMTP id s3-20020a17090a5d0300b001e0cc5b4808mr1007451pji.180.1654112200553; Wed, 01 Jun 2022 12:36:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654112200; cv=none; d=google.com; s=arc-20160816; b=TdkeyJFknfsauiPvVF/Igro2lUZtFh62iCKzrnpG8tvA5MB3g8X7+n5ijr18mLWTNd vcMAtHqcYTd7bDVyBbFw580Kg/I49UsjWdXK9auUOwLr68Em8TAYra5GigGwW0KuPOUr EF2dObCVge1XKNctaD0Q80K39GA2awrl0QxT+QvFH3/HuIbdEqp2G/IRVa8oSFMYJPyp jXMjk7F4zS12OCAQktZAtjNB6EQJJcj1evpsaQfwta9tAb8ap35h/08j9ngPlQ1b2VXs RxogF1uBT9iAfcnTZiF0uvvQf7onANkaHqcHHz7OoQ9kSRam9On7c3h1KRJv0o+Lc0My BbVQ== 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=Sq2FUzjdnXuANpbZR+IVbyfs31ZNc8ckL7u/UNxQuao=; b=IBQ6x6mzv2+lFZUOO4XekHnHZWR15CQGBsDHE69k/HhgDlVfNfpkUM18rPEFXRhTtw ISABPdKbBAu9LtW6/1SOu8uEK/qdl0TkCjUVOGuhiUenrCjrRTpGwRmKq12FWx8+URsX XS9wVZ2ovgGVVf+InPT7gdUIttp/LaZ9k1h4/0wCac9YgLw76Es2bVIA2KucdU5ACUDj P+vM8Fp5igSdLiBCZLWLZogoB0X+6QSwN4p7iUKEmhSGkdMfLIOeKi6zRZ4DvXiWFENT xJMivCfG2NEs9TwJfOkhYWsXQj4JIRMXTkpcPYwEwde8fK/mivTICs+yNErnlHVQILrZ O37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="dq9/SXya"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m6-20020a637106000000b0039cb8fe4bddsi3109313pgc.259.2022.06.01.12.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:36:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="dq9/SXya"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 315681B07B3; Wed, 1 Jun 2022 12:05:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243733AbiEaDum (ORCPT + 99 others); Mon, 30 May 2022 23:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243764AbiEaDub (ORCPT ); Mon, 30 May 2022 23:50:31 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B61192D24 for ; Mon, 30 May 2022 20:50:30 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id v5-20020a17090a7c0500b001df84fa82f8so1029037pjf.5 for ; Mon, 30 May 2022 20:50:30 -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=Sq2FUzjdnXuANpbZR+IVbyfs31ZNc8ckL7u/UNxQuao=; b=dq9/SXyaEGDWomJVOjaKba4nM6Z7MZlNHLlIpdet6ErkLlW3nPN9hCZlM4VpnIJuw8 Doe8FmILSs0rmf3Df9lZt7sxInRCO7xqP/+4TI7jFCfsYYoUAGb992F4WqP2dcPvJK9F 5F+xa8bb1kEc/yKjwgOzcRPJuAGjXFSbEgQchNWuSDvx7BGz9K2vvvKC2ARLjTykQQKA j+WI5l6jvH3rO4MWdNDm6hJJJ9o3N4MLYsoV/V3KonX+o7i6xCQ7QZ2moUDsuewFwR9R bwDp41c/fwt6H6fwGS1PXsBImjbCGwV712J5LwyU0f9ov2obiFA13zxbTGj+Vv6BeWDa Bdjg== 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=Sq2FUzjdnXuANpbZR+IVbyfs31ZNc8ckL7u/UNxQuao=; b=wnSWhVA5VDl686gKyEFmMj/onMw1L7uCSh9TmzQNiAWEZ8E4rB0a9ykw4pZMyEZzTN X2Jb7li0P1LDrHZyNGFt+TTvKdli0lngrQTyUGxBJCv/x17myQpPVsB94yUvyUs9fk2O NsvZMFVnNUfhQTeABCBdZItUiolP8CrqesLUW3UJnpokxv8Utxh47WcG0CvLHzcpcbKu ejXdwWJHht50TQmkICmpy2KKqKrqJPShnjCGZhaJKrVOiCC+V/ig0xaqKzjO2tG4H5Zu jsKhDJQYnaJn3F+iaAzPudPu7uyjsu7pjiI9AbXVepqiF7V5sYYjamAslfD91oak5/5s MZdw== X-Gm-Message-State: AOAM532Qg9M38N2rGDfjoNqE27nPYgGZI9j9yCV4XmA3LVaPiaXPC+Cl eEqHPXUNShrlW36FOie34VheP32IEN0AAMFrMw== X-Received: by 2002:a17:90a:b88:b0:1df:2b03:20c with SMTP id 8-20020a17090a0b8800b001df2b03020cmr26343035pjr.46.1653969030095; Mon, 30 May 2022 20:50:30 -0700 (PDT) MIME-Version: 1.0 References: <20220529065839.3817434-1-zheyuma97@gmail.com> <6294DED6.70904@gmail.com> In-Reply-To: <6294DED6.70904@gmail.com> From: Zheyu Ma Date: Tue, 31 May 2022 11:50:18 +0800 Message-ID: Subject: Re: [PATCH v3] char: xillybus: Check endpoint type at probe time To: Eli Billauer Cc: arnd@arndb.de, Greg KH , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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, 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 On Mon, May 30, 2022 at 11:13 PM Eli Billauer wrote: > > On 29/05/22 09:58, Zheyu Ma wrote: > > static int xillyusb_setup_base_eps(struct xillyusb_dev *xdev) > > { > > + int ret; > > + struct usb_endpoint_descriptor *in, *out; > > + > > + ret = usb_find_common_endpoints(xdev->intf->cur_altsetting,&in,&out, NULL, NULL); > > + if (ret) > > + return ret; > > + > > + if (in->bEndpointAddress != (IN_EP_NUM | USB_DIR_IN) || > > + out->bEndpointAddress != (MSG_EP_NUM | USB_DIR_OUT)) > > + return -EINVAL; > > + > > > As far as I understand, this finds the first BULK endpoints in both > directions, and verifies that their addresses are MSG_EP_NUM and > IN_EP_NUM. Because both of these happen to equal 1, I suppose this > indeed checks the right thing. But am I right that this won't work if > either MSG_EP_NUM or IN_EP_NUM have a value that isn't 1? Not that I > think that will ever happen, but still. Indeed, the correctness of this code comes from the fact that both MSG_EP_NUM and IN_EP_NUM are the first bulk endpoint, without such an assumption this check does not hold. I did this just for convenience, we can also use xillyusb_check_endpoint() to check them. > > +static int xillyusb_check_endpoint(struct xillyusb_dev *xdev, u8 addr) > > +{ > > + int i; > > + struct usb_host_interface *if_desc = xdev->intf->altsetting; > > + > > + for (i = 0; i< if_desc->desc.bNumEndpoints; i++) { > > + struct usb_endpoint_descriptor *ep =&if_desc->endpoint[i].desc; > > + > > + if (ep->bEndpointAddress == addr&& usb_endpoint_is_bulk_out(ep)) > > + return 0; > > + } > > + > > + return -EINVAL; > > +} > > + > > > > > Given that you've added this function, why isn't it used in > xillyusb_setup_base_eps()? It is feasible to use this function for checking in xillyusb_setup_base_eps(), perhaps with some modifications. Anyway, I will do so in the next version of the patch. Thanks, Zheyu Ma