From patchwork Sat Oct 17 19:45:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 3658 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 066841C031A for ; Sat, 17 Oct 2026 21:46:27 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-26728-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-26728-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id F2A1F37A80 for ; Sat, 17 Oct 2026 19:46:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4960B4848BF; Sat, 17 Oct 2026 19:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GwbDWKkJ" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 012F1429037 for ; Sat, 17 Oct 2026 19:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792266377; cv=none; b=UzF0E0MwWK/uSWcvWtyl93yFQ/I04pvzprBX0JfyG/JcG+KHYEOpygu7j7JuwtT83oD5blYj8X0lZbsxFZrufmQC6crXT8kY6zlfiz3f56RYe5Ja4WGrgatXOC8RDF9SUi9v6df0NG3EyrPsX1qNQNYySWFgpHFrMBKSztbrC5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792266377; c=relaxed/simple; bh=mN53hNOFiAzhWVgJjfpGtTS1jmZz/HpF/K3uG0lAfxA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gtbZsrmBQcKFJEF2gj2Vq2NSRGFZeUw59AeNVWdtRMVLmIqDpQ+HovJKTKrRTGGqZJ8hDk8ZKoDXuduqDcnZdjqCRSa+egvJjY/6CnSMw1fbwCRkLMi9GpqWmgiv6Q6VlNeL8dQT7FJ2Xlk+CBJQKaXubz97vwXM7okx7ELs/Ms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GwbDWKkJ; arc=none smtp.client-ip=209.85.167.182 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 Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-4c9859ea2ceso582854b6e.2 for ; Sat, 17 Oct 2026 12:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792266374; x=1792871174; darn=lists.linux.dev; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0p7Kisx6irolstjhcUjO1VMqHlDNV2glsnd/sNiGR4E=; b=GwbDWKkJeKoNJxiZgBGhCN/xXt32p0Frlbrfb9kaJh8Mx4/3vXcQzSxhk+kymDFlA9 ++bc/ihlbW4uLDn0e8jAmSfIvkhPzg6KigTMK0SX5Z1td2y/mHb9O1erq8t+Nqq3kjKq RRnSuFeNbw81UBkEIuX2fgw3Do35vA/7H9+X4O0NRlVdJTFc1bWbUFq2nhyFtYnwRbDV fkg3e8G+xIComwPz4P8B9BlqV9uIIXIM6yqL9oO0eFDhZM6RzgmBl5IhmBxifZk8YDU5 F0HfwJ1pqumflmKRhBhbEI5Sxa+jtG69LyPg0oQCVzPiZG+xxPsVQPVtgyo1fgzKOlcT QxCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792266374; x=1792871174; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0p7Kisx6irolstjhcUjO1VMqHlDNV2glsnd/sNiGR4E=; b=H1P45lECiThjtJECynUuSrvvO8IR/NnE8t3QikV+32jInpexnoGtjXSByZehcM9+4e C0GrOR0Zk/wVMe5CoKnt8vDjaygIg3njkSRMMnwWy4/Qu7r9lIHYUwCznq1Tu0GJznqX 0KVKymLIsp7LvIktJXn1RmD0XYI+SdoqhsOs1QH+ehGJ2RcwteD80Gjy6SB85PVhWaoO kFFkrTljLeRugs1kHCHmT+Z7iH8Mjfoai/wCYCvozkfLQtxYEWdJXARsSjf3AgBW3u37 CgqmQKHjs9g4eVgDrcFQqdUxt8hZpcJklEjI1n02YL9JhFjwyqjia2+qO7OOgQ8RsNgE KL6Q== X-Forwarded-Encrypted: i=1; AKwUvBxGAFLJldvgsEq0kMx76bfMT+Tbrih6itUHP6DU0sM264Ua2rXBBswxlxcGs7m2fCFLlzewWMkcVpsx9Q==@lists.linux.dev X-Gm-Message-State: AFq9FYLy3U/ZzuJZ3ht7IbFE2fJLT7FD8letmBuAkUAr5tSWwFK+lRF2 ztgg5dNqLy3n2FuxLbqJfFSppwJpBsdclbSlcSAGV3hWfB2FZZbeOkb2 X-Gm-Gg: AYBFou2qzYTSOyD+ZWKbgPmgrJPNU/iR9uYE2s2/6KkPicMAhiUhbxPv8JK1DkMVfv+ QUWug85YkCL1SrsWGorYv1/TTWhTmHv48NSNassrGRYl7ICUuvERAQaZmb+EiNLracSrmPKbMed I89lf6CxVb/fJpCPXxB/HUwzm28sgLU2k5tOinGvrMdXYGrfGAN22z1eBziorqTu4+bDkpnPiQj rZiQa9rXx5s3XXOsaCz34TfabfCfkjWGXgn+Se5INviUneit9wlBKaTdrRr25pGoW/sKew00BhM ylmXdefEsHhold4VrmMJLt/szPkP5TFxHo2JYmtyMoBd1ZlqnczDx4E6e/7vyAiXcBVDF7GEnFd yenrmCIj3kqGogfg2kPMLLIhgZFo+8bovR592c+Y1c/j+YgToJA016G4hg/ulPbKkcQ8twBlXt5 vijtLVSHuzBOt5h4txKKYNi7vUV7YtYi0oRGSNYC/vrIiCh+eF0KQkmYlW5iKvHw1JbRXtEGPuw zQ+MlPFDCIJIHs98urRo6If7tPlCPaq0hZ0t+e47Sl41e2h817yzSPuGpzKx+V26Lx5/G5n1fmr jaMmkNBi0TK8L4klphB3HjT5N7VffoBwOLaU1WtcjJkbIkxJeqPVBp4CBf9MkxUrJhkxnijXwXP UkuIvHkt5bnu/6Fsy/rZz X-Received: by 2002:a05:6808:30a1:b0:4f0:a3f9:9f89 with SMTP id 5614622812f47-53ccaf1dc47mr3423128b6e.18.1792266373854; Sat, 17 Oct 2026 12:46:13 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 5614622812f47-5388dd8b5a2sm4025321b6e.12.2026.10.17.12.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2026 12:46:13 -0700 (PDT) From: James Hilliard Date: Sat, 17 Oct 2026 13:45:57 -0600 Subject: [PATCH v9 02/18] mtd: rawnand: sunxi: reject pages exceeding the ECC step limit Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20261017-submit-sunxi-nand-vendor-oob-layout-v1-v9-2-b624c09e3ee5@gmail.com> References: <20261017-submit-sunxi-nand-vendor-oob-layout-v1-v9-0-b624c09e3ee5@gmail.com> In-Reply-To: <20261017-submit-sunxi-nand-vendor-oob-layout-v1-v9-0-b624c09e3ee5@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Maxime Ripard , Richard Genoud , Boris Brezillon , Masahiro Yamada , Brian Norris , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, devicetree@vger.kernel.org, James Hilliard , Sashiko X-Mailer: b4 0.15.2 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-1.16 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.15)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; FORGED_SENDER_MAILLIST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWELVE(0.00)[25]; PRECEDENCE_BULK(0.00)[]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,bootlin.com,socionext.com,lists.infradead.org,lists.linux.dev,vger.kernel.org]; TAGGED_RCPT(0.00)[dt]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:rdns,tor.lore.kernel.org:helo]; RCVD_COUNT_FIVE(0.00)[6]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.90.174.1:received,174.29.1.49:received,209.85.167.182:received]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.105.105.114:from]; FROM_NEQ_ENVFROM(0.00)[jameshilliard1@gmail.com,linux-sunxi@lists.linux.dev]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; MIME_TRACE(0.00)[0:+]; TAGGED_FROM(0.00)[bounces-26728-noreply=patchwork.local]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 066841C031A X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= The controller has 16 ECC status slots on A10/A23 and 32 on H6/H616. Hardware-ECC setup checks the strength and available OOB space, but does not check that the page fits those slots. NAND identification can supply a larger page size, and the NAND core does not enforce this controller-specific limit. If enough OOB space is available, an unsupported geometry can pass attach and reach DMA code that indexes status and user-data registers by ECC step. H6/H616 also represent enabled data blocks with a 32-bit mask. The number of steps must fit the controller even when their user data fits the register bank. Reject excessive step counts before allocating user-data lengths or installing the hardware-ECC callbacks. Check the final step size, after strength maximization and the conversion from 512-byte to 1-KiB steps, so valid geometries retain their existing layout. This also keeps PIO fallback from accepting a page that the controller cannot handle. Fixes: 1fef62c1423b ("mtd: nand: add sunxi NAND flash controller support") Reported-by: Sashiko Closes: https://lore.kernel.org/r/sashiko-outbox-173724@kernel.org Signed-off-by: James Hilliard --- drivers/mtd/nand/raw/sunxi_nand.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c index 80006d1a33d6..bd2193d7259d 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -2230,6 +2230,11 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, ecc->bytes = ALIGN(ecc->bytes, 2); nsectors = mtd->writesize / ecc->size; + if (nsectors > nfc->caps->max_ecc_steps) { + dev_err(nfc->dev, "unsupported number of ECC steps: %d (max %u)\n", + nsectors, nfc->caps->max_ecc_steps); + return -EINVAL; + } ret = sunxi_nand->oob_ops->init_user_data(nand, nsectors); if (ret)