Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796056073; b=ljJU1NwrhjXGO9ziaK2mwjI9l4YJhkRZANxhQHsPUMBLQvuHkZ9oFhzugUUhUsiJSvZA QXfttRQNc4zy0CCbnMlrgh2+zvk9mAvR6Zia5muUHv5U8DDIaT4FsuyX0MUuNNsVjB/pi baqFRzMqXVlF4B7EjNg98BB7O0y1j+TsVqeA5Yl41PqXEFWzEMF7i2mZjUGIMp1y7hGjN LZ4MTPefeG7P87FQtai4UJdtsoGHk+HtmmYNpkHeNrqANk2ARylUspTvDdhKaXH1oso4U 0meqwSkeJwXNvOfcfmMmJS9cnbMtPfG24F+K1+SXoBSF/5Fur3z4GIxzkEhVH9ETAgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796056073; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=vFe2TL4TOSOkxyhT5RqNNn13ZTGAr+zeEWOUltWMAJQ=; b=2hXDBjGzUQKpYj36bciY91I4MSTB0d6z9o7AP/1MTun98YK9JAWAjRDxtQnN/wMvyiNa 4yRSzPgDS2tC3uPWZYW2Z9ovWImlp+02BzPcGOOyhwe6B3pMSivyMHdF09egkC9EjEvyt /hSAc34M9xXuGrN7GpB5VfdjGZvvvR8XGbC9gT3p7L7IW0zshxjfACRWv1ngs+Ejey4xT enye8bxYkSwdl0Dkxf184eGMa2bXm/TwImBuj0lWkxAWqs5WC+CDw2QpvDmTMoPYbC2Dp 12S6kSnpPMsdlXZCrwz/pJI7rV50Em2g30ZWZ3hijZYI6o+LpStAZS/WRCgqy/0FX3A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="Ei/A+36f"; arc=none smtp.remote-ip=74.125.82.45 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D8BD606A31C for ; Mon, 30 Nov 2026 16:27:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9D8BD606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Ei/A+36f Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-1a2af4c8d00so2475980c88.0 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=vger.kernel.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=Ei/A+36fB+NOP87lnosE4v9W5ofMwkoCISO2VWegGhdk3gmzwDlfxKiC/s7RKuJrXs AaBfFtt8avcn9NMmUFyEJQkJq0419LfFpiDmbZINxGk6A/taYZJdRPSpECT5xQKYuLrP W1dGAI7s3HR+HvL8lmocDUUEgU1uZiMQhAYhtCETFvg86aT9lEgsNqISqvF8cXPfjkA4 L3KLZc2FMX+qJLM7H3yl0Gs/LqAOv4fJhbCGyOGj0fsMqCpjVEcf4olFtcNWZdotTGb3 KIUN6n/diMba2nrs8kPnE+8kzIu/AGsw98yUNxyHUyFr50zz6aywbMSX1h1hz9zO1oSf Joxg== 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=; b=o3vrKQ0ZeACzRGUmciuY62R104uWe7FmKsKr21NEdJp/UzPW08UDW1v6lfoOdepWdA 9xB8BH+D+yWi8N267jAjUXofmbkeRM1j960Zy+cKDVCdCHsuQt3OnADz/GPsykH/RFvo 6EDnXmchFSC1OCPiCWV5z+bHIWvVM7c997Ir8mL079X0qUg/rDzi6AeuvhuiRfnKrbhz GKusdxGYe2tPvBnvs08Shm/3qT1g3W8XVbMdOEB5HdA9wF+UPUDcj4OchlhH9lQl60uG yZaQi1eESR9ztpTjADAQNR+dVOCMwd54Pjt66xYm/Ok1KsCZNR1y1uDdwezhuiPC1jrx SroA== X-Forwarded-Encrypted: i=1; AL+hErGdyYRt3AuMXA4hXdmLQ5LHxccjxpyHhodwAyUSpbc5Q0qox6FjVc43yCNLoC/irZ0AkUxiC0jbjqI=@vger.kernel.org X-Gm-Message-State: APuU4Z8M8csOy/7m6S1khnD7y5RzXDHvuLDG5t6JoDV31kitI2NBnp7O zb97zlNh0N/N9vONH0kI9TZZEBrbmtPz21FlOF+6DZGD2K1MU3pyycXp X-Gm-Gg: AZFdTZc0n3PqROonxJpC2UWsrkP2dqJsn8CHsnJdvyhKSJ6p9A/d7wK35tI28kNY1TX KaQMRsYwa4vx1oaj/LKhRjw8+QzXEM21tFtTGCSZzx06Dt+23PNY7SBV03BNy06daMtiBBPvqnU 7DDLBSInR0VY0D4pFlFwCwHdDUQBKvQIqTQzOYN7vWH0GKJAIA4hxf2MKqzGO1L4UuNx6jj3WwW TvKHeoPF9J7OwicBqNvQUQmF20LGk7LlhTo7X3S7RX3FqEhegZnEt0ccIg3PZsSbgdp6zpSNM3x z742TVT0zYnciBb8ZiHZkiR9Im6SKMdZSmTVb2EUx2D2hmad8dJ3+hSbqPeDT+4L7/73W3AHZMt kvFi8P8nY3FgK64TEEMyLnXDboxZRSrIlWZHxBrFWhMMB9o5PocoOQmxNDiQX5hXqqLx2BwO3aE jPq/y95ug8JhiLrUz2EzvUbjiieQZxF/SFrgxfYqnPI7c52CwWzBOFrGe3IOdlTNdn2PYJ0XwJf nNzGKQBLUCU8/zB719y0cLjjvGCS/OfyX9oOeox2t/Qw+/GUszx8FVzBIknZmDGmT8s8z1h9R4v I8A242sPDW8lNAVx8ASr+GhT7ZV7Okv9pYKt7mhE1nGgweuuRHA= 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-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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