Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1398569rwb; Fri, 13 Jan 2023 11:42:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXt7OWXy38v2O++CGJYfnKHs5sF9SSQ+ZhZ4tnLW+v61tvtHLL+0J8LwXRe2vewCaud0WDSd X-Received: by 2002:a17:90a:ce04:b0:229:1fe8:4955 with SMTP id f4-20020a17090ace0400b002291fe84955mr4159755pju.37.1673638960269; Fri, 13 Jan 2023 11:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673638960; cv=none; d=google.com; s=arc-20160816; b=J8NfBPfwY7CxKnv8prhcCBIf7bX+AJPLwJoj/pLo2Gg+AFCBKbaLIN5kPhlp8YzlZl kor/qRkZNLRPVqRvhscJfpTQjK6E9M25DPsybX4azbcq1wD0oj+QWhrKXgIbaXT+Tb0q zq06v+NPp4LS8biBb8NW7JJsoOWUy4vZFRW7yCFo53/UbHDqjeB9G5rkPaAobrIdguwt lzLzoqPkOOgN5uzUXUj+8WMO0MK8Pu+McJCnNOb7uVoisQQUI1iqfgMN2wkqAi4lz5xF tDl54GsDpdKGEoNOzzK5H8xfoz5KhbAsqmBd3dC9/9aNFsObcqhFczhfYz0FTVVxKOU7 F3nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=WZ5VKI3zYh/SbRacwrHLrqYODry0dNYCgWCiXlm5j3I=; b=n3q+ZduGNZTf7P6+dtFZEWG+9nN81ekMvLd2jJD1JxubXvvxKD7EuPdX2KReNkY0nC JiaF3aUdlkIdXg8Evv3mQ9F2gbhmHc+drGhU874mCtyLO1bIyY8eLd4g4YNCZRdBcxlj QQBedDEF1f4hrV9AuJcAE2s0/qAJqk51Uzso2B2cES1C4/L9KC5CciqIhCUhzKVCy/n7 5m7BE6ILzxpoxNlTRExbMPHVlvD0+dm7DU852hsvP3NnCUqVdIuzhqw1DPNE3WfWpQTz HKq+6mbTrQG7t1d4V9bQb42kjgw16sKe2BROdGb5p+7lPZxy9hfye3Jf7qJBCnOSSilg Ak+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BzdEDlTp; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d23-20020a17090ad99700b0022915b6dd7asi3998470pjv.145.2023.01.13.11.42.33; Fri, 13 Jan 2023 11:42:40 -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=@intel.com header.s=Intel header.b=BzdEDlTp; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbjAMTRo (ORCPT + 52 others); Fri, 13 Jan 2023 14:17:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbjAMTRi (ORCPT ); Fri, 13 Jan 2023 14:17:38 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83EC26276; Fri, 13 Jan 2023 11:17:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673637457; x=1705173457; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=1SvtVZGvdj95Oi+1TLhuCqJ/YRqPXF2Bnfx5f3NXlBU=; b=BzdEDlTpxQz+A1mfetCB/v6uJ5oVbn3OCXPvSuCdbee5ya/ZMj/7+7Lc yNP9pMV3G5z/Yifdh86f632sBuzU6Ey22W/eCSzbKThBKaw7CjcosULdz CHzR9jzbQ+ahTdsgtVuaTBSRGh2xSv/0uFnPZqdyFop2TMFjx1PzRLSTA Mmid28UDYySua21rkFETanxBPpslL8iTHLL4kb3F5LRZxniUA8tVa/0Ba 3xPyo0X/GN3yAoQXCY3n5JHc2XqVSvw0qcfW1zh4IgtoG4UOuw7exCT0q 9ninN5OubibK15CFGRdt4dRUJa64U5zLofH0kSN0/+wBLsl1RYvjrkP8y A==; X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="322774246" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="322774246" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2023 11:17:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="608254838" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="608254838" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga003.jf.intel.com with ESMTP; 13 Jan 2023 11:17:34 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pGPYS-008mKf-2G; Fri, 13 Jan 2023 21:17:32 +0200 Date: Fri, 13 Jan 2023 21:17:32 +0200 From: Andy Shevchenko To: Serge Semin Cc: Serge Semin , Mark Brown , Alexey Malahov , Pavel Parkhomenko , Sergey Nazarov , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] spi: dw: Fix wrong FIFO level setting for long xfers Message-ID: References: <20230113165724.27199-1-Sergey.Semin@baikalelectronics.ru> <20230113185942.2516-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230113185942.2516-1-Sergey.Semin@baikalelectronics.ru> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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, Jan 13, 2023 at 09:59:42PM +0300, Serge Semin wrote: > Due to using the u16 type in the min_t() macros the SPI transfer length > will be cast to word before participating in the conditional statement > implied by the macro. Thus if the transfer length is greater than 64KB the > Tx/Rx FIFO threshold level value will be determined by the leftover of the > truncated after the type-case length. In the worst case it will cause the > dramatical performance drop due to the "Tx FIFO Empty" or "Rx FIFO Full" > interrupts triggered on each xfer word sent/received to/from the bus. > > The problem can be easily fixed by specifying the unsigned int type in the > min_t() macros thus preventing the possible data loss. LGTM, Reviewed-by: Andy Shevchenko thanks! > Fixes: ea11370fffdf ("spi: dw: get TX level without an additional variable") > Reported-by: Sergey Nazarov > Signed-off-by: Serge Semin > > --- > > Changelog v2: > - Use min_t(unisgned int, ...) macros instead of just min(). (@Andy) > --- > drivers/spi/spi-dw-core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c > index 99edddf9958b..c3bfb6c84cab 100644 > --- a/drivers/spi/spi-dw-core.c > +++ b/drivers/spi/spi-dw-core.c > @@ -366,7 +366,7 @@ static void dw_spi_irq_setup(struct dw_spi *dws) > * will be adjusted at the final stage of the IRQ-based SPI transfer > * execution so not to lose the leftover of the incoming data. > */ > - level = min_t(u16, dws->fifo_len / 2, dws->tx_len); > + level = min_t(unsigned int, dws->fifo_len / 2, dws->tx_len); > dw_writel(dws, DW_SPI_TXFTLR, level); > dw_writel(dws, DW_SPI_RXFTLR, level - 1); > > -- > 2.39.0 > > -- With Best Regards, Andy Shevchenko