From nobody Tue Apr 7 21:45:15 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