Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp279614lqp; Thu, 21 Mar 2024 00:17:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXRIigxKrTO7AKAM2wIgxPNpEufAiiFyd8j2pe7GbkcEgGe5QELC3jtvAAn/RAFVX0shvUqO+5H/C4SgGDovSwjS00OZN50U8N5a5qn9Q== X-Google-Smtp-Source: AGHT+IF6RC62JzFEVI17+jsqrJQYK3oz25KxRdADptGIbMuNyxc7LtIwUBOTOYsg+PapZp4DUUs1 X-Received: by 2002:a50:d48e:0:b0:56b:99f6:b599 with SMTP id s14-20020a50d48e000000b0056b99f6b599mr1192055edi.0.1711005441371; Thu, 21 Mar 2024 00:17:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711005440; cv=pass; d=google.com; s=arc-20160816; b=GbOZD1oy2EUNXQ22/Hc6S9LOyEXG5sD+3+yJjfMRIxOd0xKEUxjl/xyjdssJTN0Ips jeorwuaqb7eqrTZUpD1V3oYCKtrGPm+OjrVpVEQFbazMlOKLUQFToyy0hiphj+4cgRwg 9dbR+nchHFKsM0PQczr4GLurGDgPP8HiPHaSXye96oncT8JkizILEJvZjvFO59m/MKo9 EpfbxUAZfRCl0gCKO+IHQLKF3m1kldHTXX5i0qKK9mFJ0Zw5dlCFptunDpxtxYTYoQIh fZkIIXkxnEZSFqNKyFt+QU1kiUyhm0KIhiIf/DotCfhCn7ZyS4xMpbqdWHYA7yZkl/UF oSSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=nnjl8NwZzgPwQjCkcjCjQ+FVN05+Q4op74BaS+FN5Yc=; fh=xv31PgKVEaG2wVTu9sat69BALlcpjlbezrKN9U+U0C8=; b=wp1i54LOn/AovQA0kNVhJbVpfUBhpmYJB1yEw3qpW3VZpx2eFgi5EE/y0lvKavkYUZ w53aAf2nKCNs3YPdHleWPh7xjNEJHeOqCyjGpZjuVaniB7EemYgODH1V5r7Lr7/T5aIt bN/vuUhKKEy+OhOS5TNC6vh+wwis6lWKym2+c30pxSnHM5Yc1oda4R5wEMsu0pMLdlRD IF7PMfNU+eeZ+Je1e8nqgarfbM2nOci5mYoyn3xJZRqF+l7IaI2gm/oDCRfBnddWQcxz jFpz4gV15n4HIUQdZUXFs2bhGDcHqcxgDsVRkG2LWzgAEPGJ4zLR6BzOIz3UmiZ3fN9m 0qhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="HGvn1b/G"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-109725-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109725-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hp12-20020a1709073e0c00b00a4661500a9csi7334010ejc.902.2024.03.21.00.17.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 00:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109725-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="HGvn1b/G"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-109725-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109725-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 29E9A1F21D31 for ; Thu, 21 Mar 2024 07:17:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E51B51C44; Thu, 21 Mar 2024 07:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="HGvn1b/G" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 96E563A1DE; Thu, 21 Mar 2024 07:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711005432; cv=none; b=HkYzq/eMAKlN+azORVpTkyhmkavwV56qjE2HzBMsadHolQ1Aq9rKJfquqdfJguAkXYZDWUJ+VzqjrCBe3YzODL5Zle0ZV6f7vUno4MS1y667bbxkPPBw4xrAYoB0NlHTsNpsGb++Oh8Ut1cw8RZdw+ZdZU9HBFOQXdKqeeSbaQE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711005432; c=relaxed/simple; bh=GzzWbNc0mT8vlM+yDeqE8rS78bXyatgD86F8aqGRPMI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qAAZ0jdsjDpDXWFfRfzJnK14dAhsimMUnH6aO5kdHBsqTdo/2FqxJfWKbPjSj/GCL3IHZU+AhYfQeahK3PUv56dxLSeHTi9J1EXcKshV9ax1hHRqI+VWB6QYZrQdfaDUo0FaIqJBfGvKz1wblW3eMnUgbvqBke8fCdzqx5pihGU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=HGvn1b/G; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id C3FAD1C0004; Thu, 21 Mar 2024 07:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711005427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nnjl8NwZzgPwQjCkcjCjQ+FVN05+Q4op74BaS+FN5Yc=; b=HGvn1b/GVl4fpnbQxgNZ/Prs0NyYO5wc1PCRytrdhvGE2nXdpuQI3dkSeqmnisYBExgCTS csRHt58eh5FldcAX/GCpFttN4qAyIQlm406ZbwqkD2l/M7KVVTx7dEMo4cyjZAVkleNr3g 41dkjnWhhz/Nx43/lC9sXuXoK8X5dKRALxgynzk1jYW48aQLc8M8J9/43S4q/0Gyl9p09U hJ1GkDbFTxj7wDjjFR8OYHn5DRCl8GUDRGmm9Diwh+iN5bK9fyg/AS0G7YEYel7516m8x0 XoMw8qBq3BXhsreHvxtxXZKFDp6V2k2Vfi76eaHeuihaY7+tRPxWDaDlwZa4lg== Date: Thu, 21 Mar 2024 08:17:05 +0100 From: Miquel Raynal To: Christian Marangi Cc: Richard Weinberger , Vignesh Raghavendra , Jernej Skrabec , Greg Kroah-Hartman , AngeloGioacchino Del Regno , Martin Blumenstingl , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] mtd: limit OTP NVMEM Cell parse to non Nand devices Message-ID: <20240321081705.597f72bf@xps-13> In-Reply-To: <20240320162927.5015-1-ansuelsmth@gmail.com> References: <20240320162927.5015-1-ansuelsmth@gmail.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: miquel.raynal@bootlin.com Hi Christian, ansuelsmth@gmail.com wrote on Wed, 20 Mar 2024 17:29:25 +0100: > MTD OTP logic is very fragile and can be problematic with some specific > kind of devices. >=20 > 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 consequence= s. >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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". >=20 > To fix this and limit any regression with other MTD that makes use of > declaring OTP as direct child of the dev node, disable The beauty of backward compatibility... > 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. >=20 > 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. Thanks for the investigation and the fix. An implementation detail below. >=20 > Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old synta= x fixed OF cells") > Cc: > Signed-off-by: Christian Marangi > --- > drivers/mtd/mtdcore.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > 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(st= ruct mtd_info *mtd, > config.name =3D compatible; > config.id =3D NVMEM_DEVID_AUTO; > config.owner =3D THIS_MODULE; > - config.add_legacy_fixed_of_cells =3D true; > + config.add_legacy_fixed_of_cells =3D !of_node_name_eq(mtd->dev.of_node,= "nand"); Could we use mtd_type_is_nand() instead? > config.type =3D NVMEM_TYPE_OTP; > config.root_only =3D true; > config.ignore_wp =3D true; Thanks, Miqu=C3=A8l