From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388735; b=XTfrqT65RU8GkUxQnTcUA9dyMY2ULT7/KoDnBG/UYjt5biKQtsy+dpBLVK02J7qU6b0m SeoJBb5S4H0cDIx77jEXXWcc9Q+ibPxJ/YIHw5sT9NVk9f2BjHX0zhlXIqP1UqHem4Ykz cQKf5mX8fDzWdFY0qe3ehikm7a2Mf47zOkHrh91cpUuubO4N65UuDZxWNgpv4erM3mByR 6Ajl+ihJW90lEitcKDhxvD2k1AoclGhE5V4TfsWOe0BjltdMK+Gz06A1oJl4Rd+ecIBQ4 u8ocRV7KyAnk4YNWBm4zp8sYWlCEbkpm2p0yBavd62FZGUPzMxOhMj0nIxlpRlKuz3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388735; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=EJae+Q+PKxsS1CDBC52hw2Gl8THeDNaqIbQTbbtSxTE=; b=CzVzq5fvDRHa5zy1KWmkood/YvwwXuDfj3Gn6x92v7EXOlFK4wYpQ0RiW538qfc5EKpr VravWi3FKd4+MPROiEErZcSGYvreUwF9cR71uuE18mUHnBKH/fx3TLTeeyifijGqFDMy5 cdU5N8jBqP5b0YKgWSB1aibsDlHSShlFYRG2g1CGYRWmwxDDHbNxUaPnIWbLLbX052VXw HF8OYnP4c1L1/5VbPYu3mIA4J2olCUGfEC3xt5PmwhbY7aSWdtB7jF9LB329ZrXm1oxfA S+ecdtEo9VF19KdSANS6ipBWaoytYC0C+QLLLRiMN1fhX8izspscqAOa3KGPyhgyMLw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FJoNfgxM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09711606A32C; Fri, 4 Dec 2026 12:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FJoNfgxM Received: by smtp.kernel.org (Postfix) with ESMTPSA id F08411F000CE; Fri, 4 Dec 2026 12:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388734; bh=EJae+Q+PKxsS1CDBC52hw2Gl8THeDNaqIbQTbbtSxTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FJoNfgxMyvYUjNxdGnBdu8h8hsfurKexzq7e/SYx4dCrvVYiDh23OVM+PrJF3m5ff fB/xClOgWju/YYq7Sixyq4lyAieyfe0k2NOEr7/+XGC0TiXez4/cELKzXP1aXZaQc+ BqDWE2EGffXlZAXtNlOq3A2n9/JucQ5QXCBWSlvI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karl Mehltretter , Miquel Raynal , Sasha Levin Subject: [PATCH 6.1 0733/1059] mtd: core: avoid double-free of OTP NVMEM device Date: Fri, 4 Dec 2026 19:04:24 +0900 Message-ID: <20261204100702.958386450@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Karl Mehltretter [ Upstream commit 26300879cd8e4612dce66bb8f6ff7cd35fcf3e59 ] If factory OTP setup fails after the user OTP NVMEM device has been registered, mtd_otp_nvmem_add() unregisters the user device but leaves mtd->otp_user_nvmem set. On an error, the caller unregisters it again. For -EOPNOTSUPP, registration continues and normal teardown unregisters it again. Clear mtd->otp_user_nvmem after unregistering it. Fixes: e0489f6e221f ("mtd: core: fix error path for nvmem provider") Fixes: fe0b8213c012 ("mtd: core: Don't fail mtd_otp_nvmem_add() if OTP is unsupported") Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Karl Mehltretter Signed-off-by: Miquel Raynal [ sashal: Context differs because this tree lacks the -EOPNOTSUPP handling, so the err: block ends in a plain "return err;" and the added NULL assignment sits before it. ] Signed-off-by: Sasha Levin --- drivers/mtd/mtdcore.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 544ae46d95c25..93280c55381fa 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1004,6 +1004,7 @@ static int mtd_otp_nvmem_add(struct mtd_info *mtd) err: nvmem_unregister(mtd->otp_user_nvmem); + mtd->otp_user_nvmem = NULL; return err; } -- 2.53.0