From patchwork Wed Mar 20 16:29:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Christian Marangi (Ansuel)" X-Patchwork-Id: 1914188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=pYUvV2dy; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UcN06aah; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V0DZx1LK4z23r9 for ; Thu, 21 Mar 2024 03:30:01 +1100 (AEDT) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=CsaE68+yznXOVZt1BndOZYhECY17EHvSLhIwW8wEWSw=; b=pYUvV2dyxpaROv TJufKB4mN2UkXCfY6Zt60uCDh62crFx5fyHneq0ugrlm0J/0Eic/oLpPIvr8bsUt4EduWCFlqtvZD QFgBzzOzxlHC48+g/Ng8TPqNHZBTdyprW0kEZdNkvS19s5hpZzYcebuGWGciz6PkOOXGkDAwY6Vad p9jJbdRMuM5TOQfpVyZ6SMX7Jo2SqJVBHGKjNwr4JsL2k+/bojggBqemlm6HsyNNZtHH/JDTJDI/H JFOblaQNrr+4dFaMOntJC/yDEusJqXW/Q8TIpSWz4SZJZH8a0z6HBEf9zYE07NPA6z02ziXavAOrL 9RNUyBtJ/O6wr7icThTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmyp1-00000000JcC-3usk; Wed, 20 Mar 2024 16:29:47 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmyoz-00000000JbA-0vdm for linux-mtd@lists.infradead.org; Wed, 20 Mar 2024 16:29:46 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2d29aad15a5so604071fa.3 for ; Wed, 20 Mar 2024 09:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710952183; x=1711556983; 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; bh=LSz7fQzVFVXAFxgeYQXEQZk+nVYjVrCMtbK7Jhjtun0=; b=UcN06aahmVPODfPc3cGpkP3o1crnAK+Iz309fOFd//HnL4P/fmIW9v9vNQtCr06Dnx uY/2A5B2qyCH/7R2WBkA40TKozd+YZQTR9WvZslZv4D4w02MCmjP2QFtwRsCbgv3MziK vXGWDmMxeiKjth+Kpt4Lou5Vxxh7pDbAtxlWBu0q4ORPgrqphfLrMPnbH0n7uOd2DoBj VrejXbVz9QHDqDMLbnzepyD1iE4eNPEoL0Yj/0bLHMZCfl0Vi/nyk1vhSppHk8W8dIGd 4Xd3AiEyDhZ+uFJGG8DYEDaaP2hoEmDcwUrk3oLo48n4wh0ZDIX65ZCoi60P7umqNXI9 V7WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710952183; x=1711556983; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LSz7fQzVFVXAFxgeYQXEQZk+nVYjVrCMtbK7Jhjtun0=; b=ZMf4+7TI5iRf0Ts5+HqpKCjNAUVk1Jsz2D/AN2YMi3RuTi/V/+x6LnHOPad9rbg0xo 1texb5vOEitA4MAw3eb0DPGin2S6L8TMcRB9ILawKixkkN+P3EnVL1xA1EcNDLW+Z7Aa gzP+aG3s1tiXbhhP+h4Vug2GAbEnz/CHR4DyZFAeiUgL5cD/7xuh8JZatUGef5OLd/ui mSm7dtW6rtou0A9ZM7F2sykaxAYvbaO6A79EwXC7GcZiphzT8Dnd1jK6v3uXiYc5t8f3 2FxJ/pae3+fO+FXIsWdogf5ATYUiNAkSYr9M8T88vDvIXMl9yAcQRwwB4dYcKKoOq2th 77/w== X-Forwarded-Encrypted: i=1; AJvYcCUSBHCy8HfSQvVsO8VttZP6HMxtx2DWjPoDX5AGBi6cttNtt3B2gSO6S/+XnpWoRcWL1oC0Gc3LlYh5QfNCsPrvcB6dOCHvr1PxRNASKg== X-Gm-Message-State: AOJu0YzZjhouz2XN9lI+sPnRm1ff7ASgqeD3mfjIPSiVHwq2GKbnkybQ aSUfqmTC1FRkk+SNAJgPxQAhYCAAzdtG44GRZnrQtqJqzvEnoLHF X-Google-Smtp-Source: AGHT+IGrXcBnTFuQK24EEr9sarEyN5j7+SUWW/AjM5t6F29uCnPCJezOmOuBx2kavAu6gDq7MHe+NA== X-Received: by 2002:ac2:5f9a:0:b0:513:5fb0:c5ad with SMTP id r26-20020ac25f9a000000b005135fb0c5admr12638319lfe.17.1710952182786; Wed, 20 Mar 2024 09:29:42 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc18-20020a05600c525200b00414105c4cd9sm2692710wmb.21.2024.03.20.09.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 09:29:42 -0700 (PDT) From: Christian Marangi To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Jernej Skrabec , Greg Kroah-Hartman , AngeloGioacchino Del Regno , Martin Blumenstingl , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , stable@vger.kernel.org Subject: [PATCH] mtd: limit OTP NVMEM Cell parse to non Nand devices Date: Wed, 20 Mar 2024 17:29:25 +0100 Message-ID: <20240320162927.5015-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240320_092945_284930_90897C46 X-CRM114-Status: GOOD ( 15.43 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: MTD OTP logic is very fragile and can be problematic with some specific kind of devices. NVMEM across the years had various iteration on how Cells could be declared in DT and MTD OTP probably was left behind and add_legacy_fixed_of_cells was enabled without thinking of the consequences. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:235 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ansuelsmth(at)gmail.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org MTD OTP logic is very fragile and can be problematic with some specific kind of devices. NVMEM across the years had various iteration on how Cells could be declared in DT and MTD OTP probably was left behind and add_legacy_fixed_of_cells was enabled without thinking of the consequences. That option enables NVMEM to scan the provided of_node and treat each child as a NVMEM Cell, this was to support legacy NVMEM implementation and don't cause regression. This is problematic if we have devices like Nand where the OTP is triggered by setting a special mode in the flash. In this context real partitions declared in the Nand node are registered as OTP Cells and this cause probe fail with -EINVAL error. This was never notice due to the fact that till now, no Nand supported the OTP feature. With commit e87161321a40 ("mtd: rawnand: macronix: OTP access for MX30LFxG18AC") this changed and coincidentally this Nand is used on an FritzBox 7530 supported on OpenWrt. Alternative and more robust way to declare OTP Cells are already prossible by using the fixed-layout node or by declaring a child node with the compatible set to "otp-user" or "otp-factory". To fix this and limit any regression with other MTD that makes use of declaring OTP as direct child of the dev node, disable add_legacy_fixed_of_cells if we have a node called nand since it's the standard property name to identify Nand devices attached to a Nand Controller. With the following logic, the OTP NVMEM entry is correctly created with no Cells and the MTD Nand is correctly probed and partitions are correctly exposed. Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old syntax fixed OF cells") Cc: Signed-off-by: Christian Marangi --- drivers/mtd/mtdcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 5887feb347a4..6872477a5129 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -900,7 +900,7 @@ static struct nvmem_device *mtd_otp_nvmem_register(struct mtd_info *mtd, config.name = compatible; config.id = NVMEM_DEVID_AUTO; config.owner = THIS_MODULE; - config.add_legacy_fixed_of_cells = true; + config.add_legacy_fixed_of_cells = !of_node_name_eq(mtd->dev.of_node, "nand"); config.type = NVMEM_TYPE_OTP; config.root_only = true; config.ignore_wp = true;