Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp338810lqp; Thu, 21 Mar 2024 02:55:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXcyT5JwVQcpKIWfgVFcMHckIb9YTurCbp44KeVzCCJXtiG5CzfOSgSjqweE+mNn+IPPppjNwPio1vtuMBpfJMj6etKxenBm16btXKW5A== X-Google-Smtp-Source: AGHT+IGLGD2dN260a6GCRyYoAhrkgu+ftbB8d0LFZib2nCB6/YwuleXOxAHTLqX5hjs7YaaLhczS X-Received: by 2002:a05:6871:3a1f:b0:222:12dc:8af7 with SMTP id pu31-20020a0568713a1f00b0022212dc8af7mr1656960oac.59.1711014946344; Thu, 21 Mar 2024 02:55:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711014946; cv=pass; d=google.com; s=arc-20160816; b=KYdLrDjqN99zUdR1x3ebIv9MxssHQTm/fPXaMs40PLsqJcdw6uog9DrEQZiXy+g8k7 KTQFUu68RmWhKub2P2a528GjJ0M7wgByXyZL0HASWA9YBFX5d7KZ5cbQ5h1tyDQDxcup ivI0mu0WPV8VB4oNzDMpcTZdQg3rhsgz7zq3+WxoyDH+Q2iXfuJGEP6N8Lq9HtX4D8ch TUfTGk+AfoXn4iEyc1N2NEwd7QMhtqo03YAAthgdwTSy2/T+xOs/HoADxy8g5AnetIfd udOdfiQ4LGOmfN4wgS2AcKWh2Z66/coyOmUsUtJb/B1GdltMBL9qOMj1BGYWLMbEgBcf yuwQ== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=oRdYtRQgQCnEH10wkUIxAuGuQILiDbkAHuoOc+MadDQ=; fh=/8VHvnV6jqKtivehcE1tLYFWa1Xh4YgQKH5tMt8Z5J8=; b=EGQDHFeGLBfMAkxphQ9tZeG4Z+/K6KN3ARJEW9saGCWknSN0po5ChVirEgqNhSaNsA XsxMu7Stw28STU2lM2563CEmSH6iIV0tFg5MU/ttjmaBgrG1sIK4z8FA4JOSEi8qzkTZ 9VQQXohFg36qjE5uSgadG8q+sOX1k0TPpsFWPOzUBU7arCvXNXOvRDUTi8Bsi6OfmQIT kkB+P4LYktldpZzL4glCS0o1xaKPeJMmGfSwMik/mjwl6MJEHb/HSSf6yyy9MGlbTmmG gih2nFGT7XT1SFH4SggDNfZph9GarFk6a8TTQ+euVyruuIGsuV8ap11dv1TlsYmI9tzp CcBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X+IPc+xy; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-109870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e18-20020aa79812000000b006e6c736da26si14772386pfl.79.2024.03.21.02.55.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 02:55:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X+IPc+xy; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-109870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 045F6283AD7 for ; Thu, 21 Mar 2024 09:55:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8150054FBE; Thu, 21 Mar 2024 09:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X+IPc+xy" Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (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 F29BB4F1E5; Thu, 21 Mar 2024 09:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711014939; cv=none; b=u1tev3mNvnDNHOHbaFGut673iHF4WS1CX8MXf1TVZ/Lf4iQ6I2VZzZrU6Pm/U2awAR5yk6hZUXg5R4oUDPOQocWsI8TPcrLdqtnSZUmpVjAiASmDEr/HfE2JqE9KZ4TwVMG7nbVOZZnT8YJRypvQlnDWTT66O5XTPXYvMsxh3IM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711014939; c=relaxed/simple; bh=a7nyevS6kXHl1cnaRea9FJK70FgEPAKs8q8JMOY4PzQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=O4WP69Qn8wXVW6ovetcXm0u/4zeeMMqpJCPQvXZsH7WKI55hhiDr05bYQ0h1AdkZQuBjf7hBb3YeLvJQX/R4VPzCLSvJ7WA1jj/TcAUCQt9vtLeApKHlzA2minuKJu+7HyFcq7fAXF6suyk5RRztTTfwLmJ5iqzTr3lEVszMdiw= 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=X+IPc+xy; arc=none smtp.client-ip=209.85.208.174 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-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d68c6a4630so10133351fa.3; Thu, 21 Mar 2024 02:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711014936; x=1711619736; 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; bh=oRdYtRQgQCnEH10wkUIxAuGuQILiDbkAHuoOc+MadDQ=; b=X+IPc+xyNrbCVqmF9xYtiA4d919djJ4rSw6EGHDTylPRcAd2uFAiVs/2HQ9BN/fLag Xp3lvnuqzwGKT+Q5Hg1MuI3f89YAlRNoD9q098C9Y7iahD/s6LRIV4oLBZ31L7dm/yfS rf0dsPok3lIfOJWC/h6BwuR5GSZ6wxv4uazxHKd28Eo1GQnCoA0vSGjPwCbFa+hvTlcF 2gRGY5zlrIGOuLbo3+sfPLjPWTeLc33vnhecNBM1mHbREyY0i4XG1357+uJEEwfHjwaV 17qxdmYUG/+xq0Yg+7uRFoA0Lr3uGWxH5uZ5YOO5mS4lCct5Xclt8qykN/UWz/FW2Dj6 kqZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711014936; x=1711619736; 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=oRdYtRQgQCnEH10wkUIxAuGuQILiDbkAHuoOc+MadDQ=; b=wPnNLirM1H7htGG2JY0+T06elpZnlhXKv94ldyAY6tHhGqfMH8h1NpQkVkLAxDE6kG pEmnWuZopZ1WT+55a/AV8SdmMBKGTowZ6rKoMqoh3A9rvb7BkCId5N216yQU4JmGwQ5Z Wc3HB6qEuUesym67Dgny2OghXvgNZbHmb4JiSoPHKoaZZuMoz8SAWpdDxHRFmRpzhdhy tf8C7Gig26hGy7Xp77Zuq8Yc4JF/cKD/y78h3uelsNtdW32HHSZwxDAr/vixouVOEfTB TO9AR/5Dpd48O7x03bdzRQrZ4vdBOHMglcqY5PUwSMZ6Ruega1fw3genW0zDVY3GFuqq qJRg== X-Forwarded-Encrypted: i=1; AJvYcCXBAvi61MFaBnblv+rD0t7Z609isZ7xLB8dweXefX+dlJC5vzFc37TWEJJKIRhuGiANGBIxzshewic0vY9BU2hrIklwEUki9PJDrJA6YjT323BNe5zhauol8uDY/9aPlQg87uhN X-Gm-Message-State: AOJu0YzNz4cgAPgrD+k/Oz9zfZZcWb+7lgW5vDqlWb1nDUi/rVT4Droo ik85SY/ZUi7DmRuEzM/OOtivTzJ3RmPeJHL7mVERbVVyNUfD8FDS X-Received: by 2002:a2e:944d:0:b0:2d5:122a:4b13 with SMTP id o13-20020a2e944d000000b002d5122a4b13mr5932802ljh.16.1711014935817; Thu, 21 Mar 2024 02:55:35 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id p11-20020a05600c358b00b0041408af4b34sm4987103wmq.10.2024.03.21.02.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 02:55:35 -0700 (PDT) From: Christian Marangi To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Srinivas Kandagatla , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Martin Blumenstingl , Claudiu Beznea , AngeloGioacchino Del Regno , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , stable@vger.kernel.org Subject: [PATCH v2] mtd: limit OTP NVMEM Cell parse to non Nand devices Date: Thu, 21 Mar 2024 10:55:13 +0100 Message-ID: <20240321095522.12755-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- Changes v2: - Use mtd_type_is_nand instead of node name check 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..0de87bc63840 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 = !mtd_type_is_nand(mtd); config.type = NVMEM_TYPE_OTP; config.root_only = true; config.ignore_wp = true; -- 2.43.0