From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0B4245A2BC; Fri, 9 Oct 2026 14:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791556559; cv=none; b=qwZj/03HFqp2KQmRtPQkfdi7NtT0frbREIbMAL99JUOycvIIbbieszTlkDM6dnkiJB8ldszOi2gLp2s+8TP+q/lN4QyHNq0bihrOSbhpeL1r8Qu2e1OpF8J8J4YLMesQL21Yy/XOemCzHuXd9Td2p8+kVNOb/BMLlrF7YX+JjJs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791556559; c=relaxed/simple; bh=0N9NqIS37eUnbPgARFH8d7P+uFmTIkHody/gWv11FS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m3yAi5ArvWn84EmGnD7KgszFwHUlrHBNsCglBE7OdA2VybzmJBubJJNUxVGx4CIeld404kQa6SpuhMZzBDQf43hSggOx0559hwljUNF463ZD3tZ5AfmIGMy0y2b10TbwtZjJsDenH1yCrkDehK3NJucMzMTAw2ITjjA/YEnJDJI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=O4d0FhHy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="O4d0FhHy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1953F1F000FF; Fri, 9 Oct 2026 14:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791556558; bh=7HOmX7EoejNMoZmfHHVc4idcvWsA5kiLE+PTbkob4h4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=O4d0FhHyb9Q574Un2CFWkD/xa9AXR4SWr38Go+oy8TdwC6n2ozEiWGlK3MrxcjNCU PjmlxMDh/gU7R2W/OJqN0xoO7/p5TRs/ku4jpLzg4Ywvov/ZInR+x4Ew278cgHef37 J+fh9s3KJFJSAov1NXpVn4TAAqC4NEg3xpT3cEGk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Nuno=20S=C3=A1?= , Miquel Raynal Subject: [PATCH 6.18 255/403] mtd: spinand: fix zero oobavail when no ECC engine is used Date: Fri, 9 Oct 2026 16:10:16 +0200 Message-ID: <20261009140958.138797202@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261009140952.119038291@linuxfoundation.org> References: <20261009140952.119038291@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nuno Sá commit 636fe10d8f3559210ff63108a208d39ea2e9c3bd upstream. Commit 00c15b78b4b4 ("mtd: spinand: Allow the case where there is no ECC engine") made the OOB free bytes count conditional on having an ECC engine so that probing would not fail when none is requested. However mtd->oobavail is still assigned from ret just after that block, and ret is 0 there, so the device ends up advertising no available OOB bytes at all. mtd_oobavail() returns mtd->oobavail for MTD_OPS_AUTO_OOB, so a zero value makes every automatic OOB access fail with -EINVAL. JFFS2 fares worse: it keeps its cleanmarker in the OOB area on NAND and refuses to mount outright, reporting "inconsistent device description". No ECC engine also means no ooblayout was ever installed, which would make the count return -ENOTSUPP, so install the same fallback layout the on-die path already uses before counting unconditionally. Fixes: 00c15b78b4b4 ("mtd: spinand: Allow the case where there is no ECC engine") Cc: stable@vger.kernel.org Signed-off-by: Nuno Sá Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/spi/core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1663,12 +1663,17 @@ static int spinand_init(struct spinand_d goto err_cleanup_ecc_engine; } - if (nand->ecc.engine) { - ret = mtd_ooblayout_count_freebytes(mtd); - if (ret < 0) - goto err_cleanup_ecc_engine; + if (!nand->ecc.engine) { + if (spinand->eccinfo.ooblayout) + mtd_set_ooblayout(mtd, spinand->eccinfo.ooblayout); + else + mtd_set_ooblayout(mtd, &spinand_noecc_ooblayout); } + ret = mtd_ooblayout_count_freebytes(mtd); + if (ret < 0) + goto err_cleanup_ecc_engine; + mtd->oobavail = ret; /* Propagate ECC information to mtd_info */