From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 71F0A13B59A; Mon, 6 Jan 2025 15:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736179138; cv=none; b=Of8VhqWJQAex+vTnDS2YU63VQK+NqGvrg2bg1K4ehYCZ5+URG36APRE0To86JG6YuCQzzwzUHsaEcxujCyreDfwKfCRcjPJbAbFGHMbmFIoJHKUeuQAdtMhq9TiI4Js9CyJAhMOh8osqApixVEu0DZ35DV3PPwzfluXXuZDxV+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736179138; c=relaxed/simple; bh=Xr0Q6tp/HBSPedeE9gPdgeMo/AJzi+K7hE/f4lYRi9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EqUW5al40t1pdS+PzrYTv4SBY25BIvidbxTvG+n/xjOuVerPAVeaWr397upZtM+mhDlHUzL0Jw9lkpdalBCQ2+iRUnufBWkPout5pClf2goqaLQuldu9pjO8EJlPPgBhynPLRgqCArKLF0P02VLLNpTWciJKktzeBoelxVkM4BQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TGLVYppE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="TGLVYppE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 691CAC4CEE1; Mon, 6 Jan 2025 15:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736179138; bh=Xr0Q6tp/HBSPedeE9gPdgeMo/AJzi+K7hE/f4lYRi9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGLVYppEmmsTMXv1waOvXufe1o4TlL0YQqFgkDbiI0/fPcZ4l67HIe+uTJAKX/n3Y L2cpCBARPXl7kZxJs61Aor667ZhUdUx0/n3vn/JVNRK5bkOz73+PSQq0NrUnuyzzz9 B673SSfBWapfjKuoFI+vhi+d6bU6J/QgcQftvXsA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Johan Hovold , Zijun Hu , Vinod Koul Subject: [PATCH 5.4 38/93] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() Date: Mon, 6 Jan 2025 16:17:14 +0100 Message-ID: <20250106151130.140331755@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151128.686130933@linuxfoundation.org> References: <20250106151128.686130933@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zijun Hu commit a2d633cb1421e679b56f1a9fe1f42f089706f1ed upstream. For macro for_each_child_of_node(parent, child), refcount of @child has been increased before entering its loop body, so normally needs to call of_node_put(@child) before returning from the loop body to avoid refcount leakage. of_phy_provider_lookup() has such usage but does not call of_node_put() before returning, so cause leakage of the OF node refcount. Fix by simply calling of_node_put() before returning from the loop body. The APIs affected by this issue are shown below since they indirectly invoke problematic of_phy_provider_lookup(). phy_get() of_phy_get() devm_phy_get() devm_of_phy_get() devm_of_phy_get_by_index() Fixes: 2a4c37016ca9 ("phy: core: Fix of_phy_provider_lookup to return PHY provider for sub node") Cc: stable@vger.kernel.org Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu Link: https://lore.kernel.org/r/20241213-phy_core_fix-v6-5-40ae28f5015a@quicinc.com Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/phy/phy-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -138,8 +138,10 @@ static struct phy_provider *of_phy_provi return phy_provider; for_each_child_of_node(phy_provider->children, child) - if (child == node) + if (child == node) { + of_node_put(child); return phy_provider; + } } return ERR_PTR(-EPROBE_DEFER);