From patchwork Fri Jan 13 16:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13101173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41F61C54EBD for ; Fri, 13 Jan 2023 16:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjAMQ6F (ORCPT ); Fri, 13 Jan 2023 11:58:05 -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 X-Originating-IP: [10.8.30.26] X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Precedence: bulk List-ID: X-Mailing-List: linux-spi@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);