Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1364101rwb; Fri, 13 Jan 2023 11:11:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXvci+3qkzfombdFBUkVUYNgx2bz2DGXjQ3Ku0vLkB9Si/S1rkB4yttmuLhkDNuAtYt0ekTZ X-Received: by 2002:a17:907:a501:b0:7c1:700:1e2d with SMTP id vr1-20020a170907a50100b007c107001e2dmr73044324ejc.20.1673637063515; Fri, 13 Jan 2023 11:11:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673637063; cv=none; d=google.com; s=arc-20160816; b=U71TAUmfHABl8zVTUjq3pp95vXzlRAPn5MKww/BfgilpiRO0Il5Dgbk+yn/BcRxtIw V59lvLau0O7um+4Q07DZeNWpi92dFbDj80zj9qx4RAblbTZeY60cJhiA5tLgjvYliwm4 vFAr//B6XOlRalEd3f7I17ioAwA4D9yMYqf0IrwRzL7BzHnpBzgrm1eChjKx5+uSLCRn 7hrrEFKBU9y8TGXqqC4XgZd2+b78/FRgDr8ASLrOgZQSdjPl7S3klx7uFYhc+OvACnF5 x6z6fE7rdEmTxwDRmjTjdo/CSuVMeVUJZn7r56+weeLY7dl/ecl2i8ARM0HDVf2+ax4I A6XA== 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=un4iekTAGShKOgiEqknkF/bWRTvm2tqOhETsV7qQ9zQ=; b=fHm/HO4n0N/mF5W6eAhwnCy01ORKfwYid6WctqoYiTcHYcDHOnEnUiO6hmM4bK2iHk 5lhoKjdFBy7Q/r681WNH8kgkImkbyju8W9659hwqOJ85zHlmFsu18i3EPCVr08i2ft89 /PxRsQFZwNlcq37NnU50T6QtPfy7zGLDBCTy/5PWYzCHkmsN2EHA0eSLzAjtGZtgC62l 2TTXjt5lO1P0d7PInqem8qShSkYsus8ONoYX6KKCFahi9Jd0u2uujhxM8yxRGf2T14SQ fR/07UrAHRkIf0+iZV46LZHqApjy24zz776SEIg8vkzDOFFmWeduAOx0YVyHI+F82yZa 9gvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=post header.b=MY9qAJB7; 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=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt33-20020a1709072da100b007f20a95eae0si25062951ejc.262.2023.01.13.11.10.51; Fri, 13 Jan 2023 11:11:03 -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=@baikalelectronics.ru header.s=post header.b=MY9qAJB7; 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=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229512AbjAMTAi (ORCPT + 52 others); Fri, 13 Jan 2023 14:00:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230406AbjAMTAS (ORCPT ); Fri, 13 Jan 2023 14:00:18 -0500 Received: from post.baikalelectronics.com (post.baikalelectronics.com [213.79.110.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7192660CE5; Fri, 13 Jan 2023 11:00:07 -0800 (PST) Received: from post.baikalelectronics.com (localhost.localdomain [127.0.0.1]) by post.baikalelectronics.com (Proxmox) with ESMTP id 4FBFBE0F1B; Fri, 13 Jan 2023 22:00:06 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= baikalelectronics.ru; h=cc:cc:content-transfer-encoding :content-type:content-type:date:from:from:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=post; bh=un4iekTAGShKOgiEqknkF/bWRTvm2tqOhETsV7qQ9zQ=; b=MY9qAJB7oyPY y4dm2goANNmsf1VV4dDHzjj3CFPROgnbRPs30XVYFQFFe/rj7zGRqngcle8Eqn/S k+ED6LjYJII9Poo+aTAaWnZqccv8/8cLlgH7137W1z+ZrF+/atSBzhr/fYmQTEbE AsToHw/NbzIg8Ndg2otBkha6DWtkyXk= Received: from mail.baikal.int (mail.baikal.int [192.168.51.25]) by post.baikalelectronics.com (Proxmox) with ESMTP id 35029E0F19; Fri, 13 Jan 2023 22:00:06 +0300 (MSK) Received: from localhost (10.8.30.26) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 13 Jan 2023 22:00:05 +0300 From: Serge Semin To: Serge Semin , Mark Brown , Andy Shevchenko CC: Serge Semin , Alexey Malahov , Pavel Parkhomenko , Andy Shevchenko , Sergey Nazarov , , Subject: [PATCH v2] spi: dw: Fix wrong FIFO level setting for long xfers Date: Fri, 13 Jan 2023 21:59:42 +0300 Message-ID: <20230113185942.2516-1-Sergey.Semin@baikalelectronics.ru> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230113165724.27199-1-Sergey.Semin@baikalelectronics.ru> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.8.30.26] X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS 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 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. 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