Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1253415rwb; Fri, 13 Jan 2023 09:44:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXvNPcQIQIAUTuYE3ul5Gm2NxHHfGCUcWihEqcSfgo7yQNRGWf6qJDGuaKV1Wklg2Vy/WkEG X-Received: by 2002:a62:a507:0:b0:582:848c:6281 with SMTP id v7-20020a62a507000000b00582848c6281mr31747085pfm.2.1673631857899; Fri, 13 Jan 2023 09:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673631857; cv=none; d=google.com; s=arc-20160816; b=XwADs6JqOs9jwoFJNe94jHvPZCjd6ivXj5KG/BhZjLoTctAmRvP2yCshRHa+uClQ1y okS4QJi2XBcp7oj75GIiabc68eCyvQ9fZ2P78HZ1Qykh0bjX92h7e6oNbyK7I8xmne45 SSApnZ9anVIkFq5l0sR7O1vh1jsQI4gpkw85idK7ZY6Hdmn1eHsXzA+E7XLTGk7gUls2 BRJafGLg8EKYci5wDrfcTTyuMz1sCzHPiZcZjsmDRtS1P2Jrg3E79ghTfOnFKEpa9LPD acZ4JteZaheGwmbHqyrvotCcftgy9XzJ/qj9J6mADg36l7KxvatPfpAnPoPGORfkX1Z4 I1BQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KfWLqD4lsleqxGl5fhcUaT0AK7uehe9XV8KXs5uk4jo=; b=oCdJRQwU7eB2/G3CzobJl4hcwv/ghBDarpK4D5j0cxH0gK6WwKMn+LU6t/QeDBgAJs 3XdRjDGR7ErST6ZygYSZj8zB3Qu28wBWFzdiSQwdZK3C7Rb3QY0YNprpgZUKx7rYsr8+ HCAouucGPo31peBGqzLNSBaxSbRkUUU6u+diwetAEhSPbvhtjprx85Way4Q4MGGHsywi J3QmoQFGoENI02gomFxWEuiLyN24NsJpK4rPqI7GD7IcIPNKjTZpR6wjWaGVKqsW4Sxt Wx4ew1OvimarZauThs7gi7VOUmfaunHpE2O67da8ZNnKWCwLunpflxsykghb59iG6e83 tK/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=post header.b=A8+Rtky3; 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 c11-20020a056a000acb00b0058bc338c9b2si568473pfl.372.2023.01.13.09.44.11; Fri, 13 Jan 2023 09:44:17 -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=A8+Rtky3; 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 S229703AbjAMQ6H (ORCPT + 51 others); Fri, 13 Jan 2023 11:58:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbjAMQ5e (ORCPT ); Fri, 13 Jan 2023 11:57:34 -0500 Received: from post.baikalelectronics.com (post.baikalelectronics.com [213.79.110.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7424E165A9; Fri, 13 Jan 2023 08:57:28 -0800 (PST) Received: from post.baikalelectronics.com (localhost.localdomain [127.0.0.1]) by post.baikalelectronics.com (Proxmox) with ESMTP id B86E4E0F1B; Fri, 13 Jan 2023 19:57:26 +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:message-id :mime-version:reply-to:subject:subject:to:to; s=post; bh=KfWLqD4 lsleqxGl5fhcUaT0AK7uehe9XV8KXs5uk4jo=; b=A8+Rtky3QcX4NK5ta29Lza9 6RCHgqjgs+IdpcLEdXT2aUFZNiYo35jDLM3SwliwHsFVQzkb9LZt3v7S2UWHQXae vWrSv14p/liifHAZw5jVq6ollieFYc2VHH6P0gwkg/frjQmPKRwBFrEhijCQlBAz iFdtQ1ZaakhVwcZ1DEkE= Received: from mail.baikal.int (mail.baikal.int [192.168.51.25]) by post.baikalelectronics.com (Proxmox) with ESMTP id 9C776E0F0F; Fri, 13 Jan 2023 19:57:26 +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 19:57:26 +0300 From: Serge Semin To: Serge Semin , Mark Brown , Andy Shevchenko CC: Serge Semin , Alexey Malahov , Pavel Parkhomenko , Andy Shevchenko , Sergey Nazarov , , Subject: [PATCH] spi: dw: Fix wrong FIFO level setting for long xfers Date: Fri, 13 Jan 2023 19:57:24 +0300 Message-ID: <20230113165724.27199-1-Sergey.Semin@baikalelectronics.ru> X-Mailer: git-send-email 2.39.0 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 having the "Tx FIFO Empty" or "Rx FIFO Full" interrupts triggered on each word sent/received to/from the bus. In its turn it will cause the dramatical performance drop. The problem can be easily fixed by using the min() macros instead of min_t() which doesn't imply any type casting 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 --- 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..b3d287f401cd 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(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