From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3211C531CC for ; Thu, 23 Jul 2026 06:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References: Message-Id:MIME-Version:Subject:Date:From:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QuG2eVaYc1Up4ychQlPRmAyCadBgDGbyexkrkt+6kQA=; b=vD57zgr5M5Exik /dcsD86yOWKN5+NC79SmjU3UndbOCeDRXMOzoa/4GVICuUasfYeBEJk0ATfe+WeU/oO1ZrWM62hY1 eHCJ7bPpJGxaXzgTN9SFeXk816PVTIu/5K3ZephZBYotqgM6TI0Jrl09SdSF5Izwu0jTXKZO/EXzl 8pammJNxdycZt6W9JAI2EA8aoeQK2pAqBdNdxdgPXsR5SS+0Mxc7z6PjKtb/nEqnv5xzasc/ed7NZ 6tZ3TsAtaF9kug/lW7jTIk4TwG2WGfO4aGcCoiQk/wIogIrOIcb2D/O7ik/fJzl3Vm3RmXuUl5ThE glHQhoVS/yARKSKBI6Ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wmn9x-0000000DZIA-3EvW; Thu, 23 Jul 2026 06:43:57 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wmn9v-0000000DZHX-3b1J for linux-amlogic@lists.infradead.org; Thu, 23 Jul 2026 06:43:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 7B41745158; Thu, 23 Jul 2026 06:43:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 58C4EC2BCFB; Thu, 23 Jul 2026 06:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1784789035; bh=rq/tb46DP924L/FjVCUkL1FIttRHuK8j2ySAzVvIQZM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XbYL4BSGZAv0WxaCtL8jmrjVRgzC0CFAE9Ab1JbksIpmQyf0ciXvgt/KkwPfqGsqO KWe1O+xA3Q+TzUGlZtKuTRO06vuHMiGiwPqSNZh7UzANxWHzxzFQfg1ND7JyM0RFlU gqst3UuxImXzGRzxqtOB7WKv2/piiyqlR+7pLB9N9cw0XaGmJiiKfstFac+ikguCua sh+di3XtXZDvnC6G9sIzivoXbzgq2E34noVl0T0VnZC/F/2+hR63oC9A630iRqlcJ2 Gqz54e9VIEy7Zw2ar6Qbcq30Okdup7ixrobCDZ6HyPv+BUd6N+CVxz4wFVT4JkAbBS v6l077mDNEYDA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E053C531CC; Thu, 23 Jul 2026 06:43:55 +0000 (UTC) From: Xianwei Zhao via B4 Relay Date: Thu, 23 Jul 2026 06:43:43 +0000 Subject: [PATCH v2 2/4] spi: amlogic: spisg: Fix transfer size limit and timeout handling MIME-Version: 1.0 Message-Id: <20260723-a9-spisg-v2-2-9fc39106b7e2@amlogic.com> References: <20260723-a9-spisg-v2-0-9fc39106b7e2@amlogic.com> In-Reply-To: <20260723-a9-spisg-v2-0-9fc39106b7e2@amlogic.com> To: Sunny Luo , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-amlogic@lists.infradead.org, linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Xianwei Zhao X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784789030; l=1947; i=xianwei.zhao@amlogic.com; s=20251216; h=from:subject:message-id; bh=BRq2nLOiEjtiR+0vj/uM6L8HPr1w32uaAGwS/r33K78=; b=PgCQZw3mX0UQF39rzre8XLicz8qQXc+g7Wvu8j+DV8pNFDId2rQQuwKINbqgS1PSUnglS1j7Y rUOXJreyVG8Aj2RH0Hk9o4kRGLtkgtqyt+v3Unci8I/MoDGBXl26Svo X-Developer-Key: i=xianwei.zhao@amlogic.com; a=ed25519; pk=dWwxtWCxC6FHRurOmxEtr34SuBYU+WJowV/ZmRJ7H+k= X-Endpoint-Received: by B4 Relay for xianwei.zhao@amlogic.com/20251216 with auth_id=578 X-Original-From: Xianwei Zhao X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: xianwei.zhao@amlogic.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org From: Xianwei Zhao The CFG_BLOCK_NUM field can encode at most 20 bits, so reduce SPISG_BLOCK_MAX to 0xfffff to avoid programming a zero-length transfer. Perform the delay calculation in 64-bit arithmetic to avoid overflow when converting nanoseconds to SPI clock cycles. Stop the controller on transfer timeout by clearing the descriptor list register before returning an error. Fixes: cef9991e04ae ("spi: Add Amlogic SPISG driver") Signed-off-by: Xianwei Zhao --- drivers/spi/spi-amlogic-spisg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-amlogic-spisg.c b/drivers/spi/spi-amlogic-spisg.c index afc8af04638d..a6123975a37c 100644 --- a/drivers/spi/spi-amlogic-spisg.c +++ b/drivers/spi/spi-amlogic-spisg.c @@ -95,7 +95,7 @@ #define SPISG_MAX_REG 0x40 -#define SPISG_BLOCK_MAX 0x100000 +#define SPISG_BLOCK_MAX 0xFFFFF #define SPISG_OP_MODE_WRITE_CMD 0 #define SPISG_OP_MODE_READ_STS 1 @@ -175,7 +175,7 @@ static int spi_delay_to_sclk(u32 slck_speed_hz, struct spi_delay *delay) if (ns < 0) return 0; - return DIV_ROUND_UP_ULL(slck_speed_hz * ns, NSEC_PER_SEC); + return DIV_ROUND_UP_ULL((u64)slck_speed_hz * ns, NSEC_PER_SEC); } static inline u32 aml_spisg_sem_down_read(struct spisg_device *spisg) @@ -565,10 +565,13 @@ static int aml_spisg_transfer_one_message(struct spi_controller *ctlr, aml_spisg_pending(spisg, descs_paddr, false, true); if (wait_for_completion_timeout(&spisg->completion, spi_controller_is_target(spisg->controller) ? - MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(ms))) + MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(ms))) { ret = spisg->status ? -EIO : 0; - else + } else { + /* stop transfer */ + regmap_write(spisg->map, SPISG_REG_DESC_LIST_H, 0); ret = -ETIMEDOUT; + } dma_unmap_single(dev, descs_paddr, descs_len, DMA_TO_DEVICE); end: -- 2.52.0 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic