From nobody Tue Apr 7 20:10:08 2026 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE24A3DEADE for ; Wed, 11 Mar 2026 15:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773243662; cv=none; b=SNbuqKuzQOqrpOaDlPJxEh+fULFeUtORrFKgbIURnuzU9OohQHrTF43yOv4rZXo3nxEPzsgoXB/3WHE3PtYvIkpgJVpIVdw2EgS+0WdMcUj/xCMlQTDlzwSwyphd6vVvsdeV2Uw4A4n/RYyQEIaHkmE1KZJhtEJb8EiJxzqmvi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773243662; c=relaxed/simple; bh=l3znLAyCTqL8jwRZZ1IeWlpDuo3LsIIFHJn159id7NI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XEX96qnEhDtt+UWHy7NNoq6KuOEcaq1uuZyIZNggnOObhnBcJTssd/Qaq6brQmAUSX45aThEkWzwsqElp/YbXYURQ4XX+mt5wwyMihLkYvfEsJ/puwEALiDa10TqszM4lhztoeYNy6xPYrqBBKlAI1t1lDzaQr0GUms4HiddCBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: 5kV8ab6ESM2OiyRMjDIbxA== X-CSE-MsgGUID: jdsqy1XARomS7Cl5TnofAw== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 12 Mar 2026 00:40:57 +0900 Received: from demon-pc.localdomain (unknown [10.226.92.22]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id F24CC400ADBE; Thu, 12 Mar 2026 00:40:50 +0900 (JST) From: Cosmin Tanislav To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Cosmin Tanislav , Kees Cook , Weigang He , Daniel Palmer , Benjamin Krill , David Woodhouse Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] mtd: parsers: ofpart: call of_node_put() only in ofpart_fail path Date: Wed, 11 Mar 2026 17:39:56 +0200 Message-ID: <20260311153957.1984446-2-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311153957.1984446-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260311153957.1984446-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ofpart_none can only be reached after the for_each_child_of_node() loop finishes. for_each_child_of_node() correctly calls of_node_put() for all device nodes it iterates over as long as we don't break or jump out of the loop. Calling of_node_put() inside the ofpart_none path will wrongly decrement the ref count of the last node in the for_each_child_of_node() loop. Move the call to of_node_put() under the ofpart_fail label to fix this. Fixes: ebd5a74db74e ("mtd: ofpart: Check availability of reg property inste= ad of name property") Signed-off-by: Cosmin Tanislav Tested-by: Tommaso Merciai --- drivers/mtd/parsers/ofpart_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart= _core.c index 0029bda165bd..181ae9616b2e 100644 --- a/drivers/mtd/parsers/ofpart_core.c +++ b/drivers/mtd/parsers/ofpart_core.c @@ -195,11 +195,11 @@ static int parse_fixed_partitions(struct mtd_info *ma= ster, ofpart_fail: pr_err("%s: error parsing ofpart partition %pOF (%pOF)\n", master->name, pp, mtd_node); + of_node_put(pp); ret =3D -EINVAL; ofpart_none: if (dedicated) of_node_put(ofpart_node); - of_node_put(pp); kfree(parts); return ret; } --=20 2.53.0 From nobody Tue Apr 7 20:10:08 2026 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22F6F3B0ACA for ; Wed, 11 Mar 2026 15:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773243668; cv=none; b=BsvNzrdw+yKYse6JT4zXk1hOpfOeXgUdlnL3Q3KNWAj75dtJnoDnK79mlSYFouzF+PLQZ1/DBb1YA4VsOQFMn7lZavbzgxWkCZQuYuta4CQ84KAXUkrPGL0Io4umwPQSd3v3jHO9aoJcYo2HuoUlV1M4vvCMvVusnjQRvGJ3OdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773243668; c=relaxed/simple; bh=PDlrPcI8evaVnQaIB06v5rg3S4xUymoyhst24988xcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fXGieZYzhST+Dhf7TJsXdQ+J6v+q/EMVaw8wUmdFAEVkIr38YBUI68nZ3/oiYPEJIQiAl1CDHiknQ3sfKVGEIH22fUTPxX8D5Zdr9BSb8g4b9GbNokFZHIotobPaKllAJDF1VEvpU7XpShhDdxqDxR6KRrYBMJOPiblUi4R3ARc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com X-CSE-ConnectionGUID: u/B08nQjRbmhAA6i5QQrEw== X-CSE-MsgGUID: LNCRiv/SRhiWB2JHTIsMJw== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 12 Mar 2026 00:41:00 +0900 Received: from demon-pc.localdomain (unknown [10.226.92.22]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id D7DA2400ADB5; Thu, 12 Mar 2026 00:40:55 +0900 (JST) From: Cosmin Tanislav To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Cosmin Tanislav , Kees Cook , Weigang He , Daniel Palmer , Benjamin Krill , David Woodhouse Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mtd: parsers: ofpart: call of_node_get() for dedicated subpartitions Date: Wed, 11 Mar 2026 17:39:57 +0200 Message-ID: <20260311153957.1984446-3-cosmin-gabriel.tanislav.xa@renesas.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260311153957.1984446-1-cosmin-gabriel.tanislav.xa@renesas.com> References: <20260311153957.1984446-1-cosmin-gabriel.tanislav.xa@renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to parse sub-partitions, add_mtd_partitions() calls parse_mtd_partitions() for all previously found partitions. Each partition will end up being passed to parse_fixed_partitions(), and its of_node will be treated as the ofpart_node. Commit 7cce81df7d26 ("mtd: parsers: ofpart: fix OF node refcount leak in parse_fixed_partitions()") added of_node_put() calls for ofpart_node on all exit paths. In the case where the partition passed to parse_fixed_partitions() has a parent, it is treated as a dedicated partitions node, and of_node_put() is wrongly called for it, even if of_node_get() was not called explicitly. On repeated bind / unbinds of the MTD, the extra of_node_put() ends up decrementing the refcount down to 0, which should never happen, resulting in the following error: OF: ERROR: of_node_release() detected bad of_node_put() on /soc/spi@80007000/flash@0/partitions/partition@0 Call of_node_get() to balance the call to of_node_put() done for dedicated partitions nodes. Fixes: 7cce81df7d26 ("mtd: parsers: ofpart: fix OF node refcount leak in pa= rse_fixed_partitions()") Signed-off-by: Cosmin Tanislav Tested-by: Tommaso Merciai --- drivers/mtd/parsers/ofpart_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart= _core.c index 181ae9616b2e..262c4221d23f 100644 --- a/drivers/mtd/parsers/ofpart_core.c +++ b/drivers/mtd/parsers/ofpart_core.c @@ -75,7 +75,7 @@ static int parse_fixed_partitions(struct mtd_info *master, dedicated =3D false; } } else { /* Partition */ - ofpart_node =3D mtd_node; + ofpart_node =3D of_node_get(mtd_node); } =20 of_id =3D of_match_node(parse_ofpart_match_table, ofpart_node); --=20 2.53.0