Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp142852rwe; Fri, 26 Aug 2022 02:18:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6avZxOQ8S88w26sdlnpqJLuakiy9j+ijRMNaXN0BXZq+T8QiCVBS5aHcBZTN+wlWjVqy0S X-Received: by 2002:a17:90b:4d8a:b0:1fb:5e0c:67fd with SMTP id oj10-20020a17090b4d8a00b001fb5e0c67fdmr3476356pjb.75.1661505483572; Fri, 26 Aug 2022 02:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661505483; cv=none; d=google.com; s=arc-20160816; b=RcwiwYLV78pqdSKNZ73AlMa34oIEzSB6G02XiUTce2+YfbDmmwkwAlQFm/sZomdPZQ zXt8LQ3Y2Hik0bZKqPZ/x8tc4/oWxS+CoAISNW1zHcXZbWSDFFiO2dq1RmazfxPE0yR3 Rkswt6rWmcpUz1z9bpjMnxl0r81jjrVMm4QYYlf+lAQtkjmoN6ijsMbhUIguuWOtjjvj 2zecKOdBPNVVPdIU0mWNPg+H6/uyjuG+atLj64E6a3S2cjRPoyu76OKwV5Ar95zY0fGM TI96I7YJEnkQ6vWUy2PLs1bUjj9p4MXA2z9P+FNJGRId4YV1R6YPyLQeylPStJnjdVW6 V8Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=bWmtCR9K7g8WGM5dbPXeabsChqiWPGxtgX1i922KQpo=; b=tfA2enNUw23aRtmOL+cinhKgLplDR1hQee2zFTDp4SWoXLRuC8xJcjTg7+bj6Fm96b HKKhs9VWA5Hd/VvSER1zDloWyxqZqOoo+bz0kR1vPqblrjcO+U3q4HNtwQQxIxK4erEq 1i+joZGkVukrxtoLvepvpmTgff+6frFWdx7Nimt6goZoefZkR1GN0KUT9FmzRp6p+s9V 84p0780c/Dkn/EttsXwd5zuBOVEJvEQ26SY3y+P1dNgH14wf1QKjvMVSsF3l06yyYb05 TStIhm8vXqlM35iuQGO3Y2b04KCXRseSX4o/v03dVNPAhuzUkVABWE6aVWE032RnZlHC UI2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=VnrvzOJW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DoKhqbgd; 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=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a170902650d00b0016d15070027si1166566plk.352.2022.08.26.02.17.52; Fri, 26 Aug 2022 02:18:03 -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=@linutronix.de header.s=2020 header.b=VnrvzOJW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DoKhqbgd; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245601AbiHZJGm (ORCPT + 99 others); Fri, 26 Aug 2022 05:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245227AbiHZJGi (ORCPT ); Fri, 26 Aug 2022 05:06:38 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED03DD6304; Fri, 26 Aug 2022 02:06:36 -0700 (PDT) Date: Fri, 26 Aug 2022 11:06:32 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1661504795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bWmtCR9K7g8WGM5dbPXeabsChqiWPGxtgX1i922KQpo=; b=VnrvzOJWE1hyoW45ywyZ99N/BWqSF9eAuSZuxEMJxti8RImvw7Lt+CD9mNVet84Ip5N0gG C2LadHZuBIaJRh6PULR17EDSLJ1eRFXI6kUfVWma7hVCLDEeVojvIzhxu9z5HHKR/MNXjp eBpQp4riVw1IuKqyC9xLuVSRevAKWvMB3d5ovkVks++Shw3VW4TqsufjjnCJsavI0jFOlK +buAl2R8h995WOW4HGYqGD+fIly0Kt4+zCpmoyxHnqDSE+1TJFAWLMZDfhu1ptBjVMCynL mBBFVgufrJHU+6mrCDPDTIVjkaUftayTEcIVLeUtTss4L8AKuXY4vYQQHOrB9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1661504795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bWmtCR9K7g8WGM5dbPXeabsChqiWPGxtgX1i922KQpo=; b=DoKhqbgdm7w9bGMz/o276aFnYc4vVcFHzC9Pns3HMgBTlVPB/ajJmpSfvqpcndATAhMEZo +crRx60ffDudEcCw== From: Sebastian Andrzej Siewior To: Thinh Nguyen Cc: Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: Re: [PATCH v2 21/25] usb: gadget: f_tcm: Get stream by tag Message-ID: References: <3fbae6ecb8e9f31807635152a377b076e86fb12e.1658192351.git.Thinh.Nguyen@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3fbae6ecb8e9f31807635152a377b076e86fb12e.1658192351.git.Thinh.Nguyen@synopsys.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 2022-07-18 18:28:16 [-0700], Thinh Nguyen wrote: > diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c > index 084143213176..a10e74290664 100644 > --- a/drivers/usb/gadget/function/f_tcm.c > +++ b/drivers/usb/gadget/function/f_tcm.c > @@ -506,6 +506,22 @@ static void uasp_cleanup_old_alt(struct f_uas *fu) > uasp_free_cmdreq(fu); > } > > +static struct uas_stream *uasp_get_stream_by_tag(struct f_uas *fu, u16 tag) > +{ > + /* > + * For simplicity, we use mod operation to quickly find an in-progress > + * matching command tag to check for overlapped command. The assumption > + * is that the UASP class driver will limit to using tag id from 1 to > + * USBG_NUM_CMDS. This is based on observation from the Windows and > + * Linux UASP storage class driver behavior. If an unusual UASP class > + * driver uses a tag greater than USBG_NUM_CMDS, then this method may no > + * longer work due to possible stream id collision. In that case, we > + * need to use a proper algorithm to fetch the stream (or simply walk > + * through all active streams to check for overlap). > + */ > + return &fu->stream[tag % USBG_NUM_CMDS]; Could you please avoid the assumption what tag actually is? Please take a look at hashtable.h, hash_add(), hash_del(), hash_for_each_possible_safe() is probably all you need. That % looks efficient but gcc will try and remove the div operation which is something the hash implementation (as of hash_min()) avoids. So the only additional costs here is the additional hashtable which worth the price given that you don't assume what tag can be. Sebastian