blob: 86b2089c5ab8700cc522ffc5fb4249c60f1a5788 [file] [log] [blame]
developerfd40db22021-04-29 10:08:25 +08001From patchwork Tue Sep 22 11:49:02 2020
2Content-Type: text/plain; charset="utf-8"
3MIME-Version: 1.0
4Content-Transfer-Encoding: 7bit
5X-Patchwork-Submitter: Chuanhong Guo <gch981213@gmail.com>
6X-Patchwork-Id: 11792387
7Return-Path:
8 <SRS0=i66O=C7=lists.infradead.org=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@kernel.org>
9Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org
10 [172.30.200.123])
11 by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21EB0618
12 for <patchwork-linux-arm@patchwork.kernel.org>;
13 Tue, 22 Sep 2020 11:51:33 +0000 (UTC)
14Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134])
15 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
16 (No client certificate requested)
17 by mail.kernel.org (Postfix) with ESMTPS id E15FF221EB
18 for <patchwork-linux-arm@patchwork.kernel.org>;
19 Tue, 22 Sep 2020 11:51:32 +0000 (UTC)
20Authentication-Results: mail.kernel.org;
21 dkim=pass (2048-bit key) header.d=lists.infradead.org
22 header.i=@lists.infradead.org header.b="KBg/skkC";
23 dkim=fail reason="signature verification failed" (2048-bit key)
24 header.d=gmail.com header.i=@gmail.com header.b="Gtqp4rrT"
25DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E15FF221EB
26Authentication-Results: mail.kernel.org;
27 dmarc=fail (p=none dis=none) header.from=gmail.com
28Authentication-Results: mail.kernel.org;
29 spf=none
30 smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org
31DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
32 d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding:
33 Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive:
34 List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From:
35 Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender
36 :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner;
37 bh=Xg61WV47qNPjINdHDPnF6T3q8GN8f9evwhTMdYR0Zqs=; b=KBg/skkCvnF7/8AlleTay0p/H2
38 hC4Lzo+slWhX5/eepUEXzhTr5ORf4Dx9gD65UEuordKQKFpg6Y9ApoGaYtmBJ0vABdAZt+oVG4sFf
39 K3z3CYV6EZ5qvwsZt53Xm3YsHojgu+Lnc/MGgGWBRjCtTP7gshm480pZ0w6ADgHvrym5hNajUF6+5
40 zMm5Wwq34jxUApGU7k5FAPsvO5ctYCuhECq/mLB6tplCVh3/+XLdSiHMUlY17fh+xs732kgaDotuQ
41 QYgXtDmMB1pVKCq5cf3Bcuz7Ww47vLSx4rBxtdB/vpp2w9SdrU6K8Q7DuJ3+XrGfbMhKtBU5ektA8
42 GxEUUaKw==;
43Received: from localhost ([::1] helo=merlin.infradead.org)
44 by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux))
45 id 1kKgo2-0000Ze-Fb; Tue, 22 Sep 2020 11:50:00 +0000
46Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543])
47 by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux))
48 id 1kKgnr-0000Vv-6z; Tue, 22 Sep 2020 11:49:49 +0000
49Received: by mail-pg1-x543.google.com with SMTP id o25so6798387pgm.0;
50 Tue, 22 Sep 2020 04:49:46 -0700 (PDT)
51DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
52 h=from:to:cc:subject:date:message-id:mime-version
53 :content-transfer-encoding;
54 bh=EJwpKrbgqo/Jc/SWHvyAGB9CrpkZ5L1Hzq9tInFHTYk=;
55 b=Gtqp4rrTgM1+bYxfUQXe+lfPcgHRW6GccdN42Iszl6ozMbezvftl1BUcKE22S6eFW3
56 Vs+lcKZN9Eh9C53YAAd0cuZYhJ2GqlfGNLA/9SyB7s/gIwHqO9Cuu17YpB9dAFfEUxoS
57 825uUcTeRe6BTagZAh2/MBluiMY3TszRi94MbOftxUg+wSqp0wMAPe9RN0gAEc/l2xgK
58 8PhXbZv3uItI4QqoKYiz93vrF/zYhj+oGTI44g2li2fpAgCNL7lXCpSE2C9NsEe+YqTw
59 aO5A3W8t4jvp8oCJEvr/MWY1ZZLd1fVJ17W3aGXoDi/7EUcAvX9G5Ee7U68UXGMtty/d
60 z5Nw==
61X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
62 d=1e100.net; s=20161025;
63 h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
64 :content-transfer-encoding;
65 bh=EJwpKrbgqo/Jc/SWHvyAGB9CrpkZ5L1Hzq9tInFHTYk=;
66 b=XhcpP16zYyJr/qCT9JbO3fn8RyfI44xJL3hvgNrlcr4ljkEZ4TF6OfyhjdEZYeeA3C
67 kLlWuAqrSn6mweuhS2LZ0BV5QL/YYaVO4wP4B/y3j+tNbnW3JNM0NtEY19pOtaM4vYK/
68 tPuNxld5RvJWxQ9BLs8hH6y7j/ob6oDug170P5YkwK6Wa/FLCi2bw92/vldhdnFP/Nny
69 1bbiWRVls1Ra/Q3z90tGViMkBdlcff6MI9DR5M6a1HTQN7kN9rLDCMGs3r9XVComY07N
70 ECbrZbL+iJwuRuT43RAUxE72X/Pn0WYD20unzITf8bta92usNDRgEuxc1bLyL+uHxgUk
71 YQKA==
72X-Gm-Message-State: AOAM531Xr1Bg4uwupCAPpH4eBWVrXGALjIWa+5AVNZ8w6ltS4BGgWv6b
73 e4g6ycKnUp/KalpJhOMi90o=
74X-Google-Smtp-Source:
75 ABdhPJx36OliaaLkiX3ZeZNNWgd/qSKiRor2X0eeHScDrjMSi5bTiEzAfX5j7hkQgqz8ZUT0qqLRNA==
76X-Received: by 2002:a63:1863:: with SMTP id 35mr3131307pgy.413.1600775385014;
77 Tue, 22 Sep 2020 04:49:45 -0700 (PDT)
78Received: from guoguo-omen.lan ([156.96.148.94])
79 by smtp.gmail.com with ESMTPSA id r4sm2223750pjf.4.2020.09.22.04.49.42
80 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
81 Tue, 22 Sep 2020 04:49:44 -0700 (PDT)
82From: Chuanhong Guo <gch981213@gmail.com>
83To: linux-spi@vger.kernel.org
84Subject: [PATCH v2] spi: spi-mtk-nor: fix timeout calculation overflow
85Date: Tue, 22 Sep 2020 19:49:02 +0800
86Message-Id: <20200922114905.2942859-1-gch981213@gmail.com>
87X-Mailer: git-send-email 2.26.2
88MIME-Version: 1.0
89X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3
90X-CRM114-CacheID: sfid-20200922_074948_345420_69207EBE
91X-CRM114-Status: GOOD ( 12.60 )
92X-Spam-Score: 2.6 (++)
93X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary:
94 Content analysis details: (2.6 points)
95 pts rule name description
96 ---- ----------------------
97 --------------------------------------------------
98 2.6 RCVD_IN_SBL RBL: Received via a relay in Spamhaus SBL
99 [156.96.148.94 listed in zen.spamhaus.org]
100 -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/,
101 no trust [2607:f8b0:4864:20:0:0:0:543 listed in]
102 [list.dnswl.org]
103 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
104 provider [gch981213[at]gmail.com]
105 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends
106 in digit [gch981213[at]gmail.com]
107 -0.0 SPF_PASS SPF: sender matches SPF record
108 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
109 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
110 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from
111 author's domain
112 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
113 envelope-from domain
114 0.1 DKIM_SIGNED Message has a DKIM or DK signature,
115 not necessarily
116 valid
117X-BeenThere: linux-arm-kernel@lists.infradead.org
118X-Mailman-Version: 2.1.29
119Precedence: list
120List-Id: <linux-arm-kernel.lists.infradead.org>
121List-Unsubscribe:
122 <http://lists.infradead.org/mailman/options/linux-arm-kernel>,
123 <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe>
124List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/>
125List-Post: <mailto:linux-arm-kernel@lists.infradead.org>
126List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help>
127List-Subscribe:
128 <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>,
129 <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe>
130Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
131 Mark Brown <broonie@kernel.org>, linux-mediatek@lists.infradead.org,
132 bayi.cheng@mediatek.com, Matthias Brugger <matthias.bgg@gmail.com>,
133 Chuanhong Guo <gch981213@gmail.com>, linux-arm-kernel@lists.infradead.org
134Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org>
135Errors-To:
136 linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org
137
138CLK_TO_US macro is used to calculate potential transfer time for various
139timeout handling. However it overflows on transfer bigger than 512 bytes
140because it first did (len * 8 * 1000000).
141This controller typically operates at 45MHz. This patch did 2 things:
1421. calculate clock / 1000000 first
1432. add a 4M transfer size cap so that the final timeout in DMA reading
144 doesn't overflow
145
146Fixes: 881d1ee9fe81f ("spi: add support for mediatek spi-nor controller")
147Cc: <stable@vger.kernel.org>
148Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
149---
150
151Change since v1: fix transfer size cap to 4M
152
153 drivers/spi/spi-mtk-nor.c | 6 +++++-
154 1 file changed, 5 insertions(+), 1 deletion(-)
155
156diff --git a/drivers/spi/spi-mtk-nor.c b/drivers/spi/spi-mtk-nor.c
157index 6e6ca2b8e6c82..62f5ff2779884 100644
158--- a/drivers/spi/spi-mtk-nor.c
159+++ b/drivers/spi/spi-mtk-nor.c
160@@ -89,7 +89,7 @@
161 // Buffered page program can do one 128-byte transfer
162 #define MTK_NOR_PP_SIZE 128
163
164-#define CLK_TO_US(sp, clkcnt) ((clkcnt) * 1000000 / sp->spi_freq)
165+#define CLK_TO_US(sp, clkcnt) DIV_ROUND_UP(clkcnt, sp->spi_freq / 1000000)
166
167 struct mtk_nor {
168 struct spi_controller *ctlr;
169@@ -177,6 +177,10 @@ static int mtk_nor_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
170 if ((op->addr.nbytes == 3) || (op->addr.nbytes == 4)) {
171 if ((op->data.dir == SPI_MEM_DATA_IN) &&
172 mtk_nor_match_read(op)) {
173+ // limit size to prevent timeout calculation overflow
174+ if (op->data.nbytes > 0x400000)
175+ op->data.nbytes = 0x400000;
176+
177 if ((op->addr.val & MTK_NOR_DMA_ALIGN_MASK) ||
178 (op->data.nbytes < MTK_NOR_DMA_ALIGN))
179 op->data.nbytes = 1;