From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E912606A31C for ; Mon, 30 Nov 2026 16:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=nvXRyT4/; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Yrxrzmbv DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=vFe2TL4TOSOkxyhT5RqNNn13ZTGAr+zeEWOUltWMAJQ=; b=nvXRyT4/xyWVcnCoG8aAZaGmzz 9u2WergX1Rl3kBuDaBRzwsemMWZpluW0CnGQvnPHqwhdJ+pVdFZijEGGq3seVxxb+BCr0+0CqhgN+ 8UgDiNhDAvWolN4EzCtdgeuFlwfNmgMOBXkAFIrcxPgyR9oXKnXr/e5xTEttzIOtm2rMJLVU/0y+R XEVrR6HwiAa8BmAN5+7dkw6Ai2Vc0zqM52BgenpMfcttEqiFkXXFNwXXCHIgAmEsU2b3yJouCQlkV IpFyZmylwAsW+I5MZD0gAP4QPTwTS038wLdFDUr1fvNZRsL4m6WFHndGpi0lBNrS3JZ1DPlLHn6Pq Q27BzxAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY4EO-00000005G4O-0ben; Mon, 30 Nov 2026 16:27:56 +0000 Received: from mail-dl1-x122d.google.com ([2607:f8b0:4864:20::122d]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xY4EK-00000005G3d-3np2 for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 16:27:54 +0000 Received: by mail-dl1-x122d.google.com with SMTP id a92af1059eb24-1b5adf7eacdso2248613c88.1 for ; Mon, 30 Nov 2026 08:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796056072; x=1796660872; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=vFe2TL4TOSOkxyhT5RqNNn13ZTGAr+zeEWOUltWMAJQ=; b=Yrxrzmbv47RJjvZQoSpC49pay2VdVjG36T3NIpAC5JBRsvVcYjst9j1wjRZ4oJBvQW FDUs9U6LSGdtPF5xLloiQTb0DaZCUunaz6yRvaM8uZP5U20LATJI6VIowPaU4Phxqr+e gh5hqbnCxUrmVBqCNm0FOp88V3Ho7jfdSOg32P4CSu77+uiTL4XLqdyRBE3Snu/8YCkl iiFcrgDRLKoKNG5LT0+GJ0kowKGrN024UF+CWw53GDrGThWffA+p8EtE5cZWIjk4NEtJ hB8Qxfrf3rABr+ZHp3mihiEhNcJK20AC8y0QZ5/wwwatnehyToh/pc0d3CaWfzK2yhKn 8XjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796056072; x=1796660872; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vFe2TL4TOSOkxyhT5RqNNn13ZTGAr+zeEWOUltWMAJQ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RyWgbDG2kT6mPOyBz0KgEHuMH73PrvtkvOFGxS0unHMrNY920bk5eyul1 SVcnBYjqBXQTXGEvqezjzPwXK5zWDp+s5aMQ/OpYl38gHA7iIu0i/FS/uLzJa+ScvlBc2VP6TdJ MUkn2VM2FWMvU0590kFwqfQQmcCACYDPD29XE4Z4YuMVhT9A+dA= X-Received: by 2002:a05:7022:ed02:b0:149:50cb:2175 with SMTP id a92af1059eb24-1b5568fda53mr31506760c88.33.1796056071687; Mon, 30 Nov 2026 08:27:51 -0800 (PST) Received: from localhost.localdomain ([146.196.34.22]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385c6830815sm92098746eec.20.2026.11.30.08.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 08:27:51 -0800 (PST) From: Vikrant Yadav To: lorenzo@kernel.org, ray.liu@airoha.com Cc: broonie@kernel.org, mikhail.kshevet@gmail.com, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org, Vikrant Yadav Subject: [PATCH] spi: airoha-snfi: strip plane select bit from dirmap offs Date: Mon, 30 Nov 2026 21:57:43 +0530 Message-Id: <20261130162743.12168-1-vikrantyadav4802@gmail.com> X-Mailer: git-send-email 2.34.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_082752_943462_679E7008 X-CRM114-Status: GOOD ( 14.47 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 When a SPI NAND chip sets SPINAND_HAS_READ_PLANE_SELECT_BIT or SPINAND_HAS_PROG_PLANE_SELECT_BIT (e.g. Macronix MX35LF2GE4AB), the SPI NAND core ORs the plane into the column address it passes to the dirmap callbacks as offs: offs = (plane << fls(page_size)) | column For a 2048-byte page, plane 1 sets bit 12, so offs is 0x1000 for a data or data+OOB access and 0x1800 for an OOB-only read. airoha_snand_dirmap_read() and airoha_snand_dirmap_write() use offs as a plain byte offset into txrx_buf (SPI_NAND_CACHE_SIZE, 4352 bytes) and to size the transfer. With the plane bit left in, on plane 1: - bytes = round_up(offs + len, 64) is inflated (6208 instead of 2112 for an OOB-only read), so the NFI is programmed with an oversized transfer length. - read: memcpy(buf, txrx_buf + offs, len) copies from past the end of txrx_buf. - write: memset()/memcpy() on txrx_buf + offs write past the end of txrx_buf, corrupting memory. The plane is already selected through desc->info.offset (set at dirmap creation as plane << fls(page_size)), which the driver writes to the hardware address registers (REG_SPI_NFI_RD_CTL3 for read, REG_SPI_NFI_PG_CTL2 for write). Only the use of offs as a buffer index and length is wrong. Clear the plane bit from offs at the start of both functions: offs &= ~desc->info.offset; info.offset contains only the plane bit, so the column is unchanged. This is a no-op for plane 0 and for chips without the plane select flags, and works whether the chip sets the read flag, the program flag or both. Fixes: 902c0ea18a97 ("spi: airoha: avoid reading flash page settings from SNFI registers during driver startup") Signed-off-by: Vikrant Yadav --- drivers/spi/spi-airoha-snfi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c index 95bfde7c8e7f..2217df3c3677 100644 --- a/drivers/spi/spi-airoha-snfi.c +++ b/drivers/spi/spi-airoha-snfi.c @@ -565,6 +565,9 @@ static ssize_t airoha_snand_dirmap_read(struct spi_mem_dirmap_desc *desc, as_ctrl = spi_controller_get_devdata(spi->controller); + /* offs may carry the plane select bit, keep only the column */ + offs &= ~desc->info.offset; + /* minimum oob size is 64 */ bytes = round_up(offs + len, 64); @@ -758,6 +761,9 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc, as_ctrl = spi_controller_get_devdata(spi->controller); + /* offs may carry the plane select bit, keep only the column */ + offs &= ~desc->info.offset; + /* minimum oob size is 64 */ bytes = round_up(offs + len, 64); -- 2.34.1