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 DA9DB12C805; Tue, 30 Apr 2024 11:21:37 +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=1714476097; cv=none; b=JhAbcYGQ36JRAKuMApN0GhkyOzDt69UVfQZP2AcCJezvzy+LTP8UkO/vWxaFM73HpsLQYpYuBiW4XNenNg4QHvnvIkvPr5V1i+/O915jZpb7zdP5PbSetxyQltCfO4H+LLXWG4svJu7KFTbkXdcFlHLAZAo5Q8349jcJlx+oQe4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714476097; c=relaxed/simple; bh=yU9VIsD5IOnQNiqbz0cNFqSFpnkrMtdiMLMSh+HpcSE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BWUrczSFOjDrySw+e1ff9gm/GyNOWNtNNV301VYLD2Ko1psAoN3j2yWGqfIfM4BGcfXv3CK/4ZP5tp0BO+vQpYhqM8ufm/lAzQfMPTCNmsDeRAlCefobvdjnCODeBkWhcHH0w61cZXOt+B9+ofVdQvs6/MD19I9qTBhLQM0jHFk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GvBk1N2Q; 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="GvBk1N2Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46F3FC2BBFC; Tue, 30 Apr 2024 11:21:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714476097; bh=yU9VIsD5IOnQNiqbz0cNFqSFpnkrMtdiMLMSh+HpcSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GvBk1N2QDKRhEwx+Bt8yCcPVNabPve46iLCQo/ukYf9CPFjwz6+HqXQ/RAiTA7lO7 D3SofGcI+Jbrf6nHY5DdGYOyIgUfx3JXoHcDVMi9H07Ifx4UrnUqGVjSxhDGb8CPVa kWZEXrYAIoRHaJY4xOYdlyjha3JCQXzfCCf4+pFc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Douglas Anderson , Stephen Boyd , Sasha Levin Subject: [PATCH 5.4 032/107] clk: Initialize struct clk_core kref earlier Date: Tue, 30 Apr 2024 12:39:52 +0200 Message-ID: <20240430103045.609446365@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103044.655968143@linuxfoundation.org> References: <20240430103044.655968143@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org 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: Stephen Boyd [ Upstream commit 9d05ae531c2cff20d5d527f04e28d28e04379929 ] Initialize this kref once we allocate memory for the struct clk_core so that we can reuse the release function to free any memory associated with the structure. This mostly consolidates code, but also clarifies that the kref lifetime exists once the container structure (struct clk_core) is allocated instead of leaving it in a half-baked state for most of __clk_core_init(). Reviewed-by: Douglas Anderson Signed-off-by: Stephen Boyd Link: https://lore.kernel.org/r/20240325184204.745706-4-sboyd@kernel.org Stable-dep-of: e581cf5d2162 ("clk: Get runtime PM before walking tree during disable_unused") Signed-off-by: Sasha Levin --- drivers/clk/clk.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7c92dd209a99d..f887cea057ee4 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3509,8 +3509,6 @@ static int __clk_core_init(struct clk_core *core) } clk_core_reparent_orphans_nolock(); - - kref_init(&core->ref); out: clk_pm_runtime_put(core); unlock: @@ -3720,6 +3718,16 @@ static void clk_core_free_parent_map(struct clk_core *core) kfree(core->parents); } +/* Free memory allocated for a struct clk_core */ +static void __clk_release(struct kref *ref) +{ + struct clk_core *core = container_of(ref, struct clk_core, ref); + + clk_core_free_parent_map(core); + kfree_const(core->name); + kfree(core); +} + static struct clk * __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) { @@ -3740,6 +3748,8 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) goto fail_out; } + kref_init(&core->ref); + core->name = kstrdup_const(init->name, GFP_KERNEL); if (!core->name) { ret = -ENOMEM; @@ -3794,12 +3804,10 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) hw->clk = NULL; fail_create_clk: - clk_core_free_parent_map(core); fail_parents: fail_ops: - kfree_const(core->name); fail_name: - kfree(core); + kref_put(&core->ref, __clk_release); fail_out: return ERR_PTR(ret); } @@ -3879,16 +3887,6 @@ int of_clk_hw_register(struct device_node *node, struct clk_hw *hw) } EXPORT_SYMBOL_GPL(of_clk_hw_register); -/* Free memory allocated for a clock. */ -static void __clk_release(struct kref *ref) -{ - struct clk_core *core = container_of(ref, struct clk_core, ref); - - clk_core_free_parent_map(core); - kfree_const(core->name); - kfree(core); -} - /* * Empty clk_ops for unregistered clocks. These are used temporarily * after clk_unregister() was called on a clock and until last clock -- 2.43.0