All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH next] cpupfreq: tegra124: eliminate uses of of_node_put()
@ 2024-04-07 20:15 Javier Carrasco
  2024-04-19  6:28 ` Viresh Kumar
  0 siblings, 1 reply; 2+ messages in thread
From: Javier Carrasco @ 2024-04-07 20:15 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar, Thierry Reding, Jonathan Hunter,
	Julia Lawall
  Cc: linux-pm, linux-tegra, linux-kernel, Javier Carrasco

Make use of the __free() cleanup handler to automatically free nodes
when they get out of scope. Only the probe function is affected by this
modification.

Given that this mechanism requires the node to be initialized, its
initialization and the value check have been moved to the top of the
function.

After removing uses of of_node_put(), the jump to out_put_np is no
longer necessary.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
This patch is a proof of concept to remove uses of of_node_put() in
cpufreq, which can be replaced with the clenaup handler introduced with
54da6a092431 ("locking: Introduce __cleanup() based infrastructure").

This change provides a scope-based cleanup mechanism to avoid potential
memory leaks that can appear if of_node_put() is not used correctly.

The patch is based on the latest linux-next tag (next-20240405).
---
 drivers/cpufreq/tegra124-cpufreq.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/cpufreq/tegra124-cpufreq.c b/drivers/cpufreq/tegra124-cpufreq.c
index aae951d4e77c..514146d98bca 100644
--- a/drivers/cpufreq/tegra124-cpufreq.c
+++ b/drivers/cpufreq/tegra124-cpufreq.c
@@ -52,12 +52,15 @@ static int tegra124_cpu_switch_to_dfll(struct tegra124_cpufreq_priv *priv)
 
 static int tegra124_cpufreq_probe(struct platform_device *pdev)
 {
+	struct device_node *np __free(device_node) = of_cpu_device_node_get(0);
 	struct tegra124_cpufreq_priv *priv;
-	struct device_node *np;
 	struct device *cpu_dev;
 	struct platform_device_info cpufreq_dt_devinfo = {};
 	int ret;
 
+	if (!np)
+		return -ENODEV;
+
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
@@ -66,15 +69,9 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev)
 	if (!cpu_dev)
 		return -ENODEV;
 
-	np = of_cpu_device_node_get(0);
-	if (!np)
-		return -ENODEV;
-
 	priv->cpu_clk = of_clk_get_by_name(np, "cpu_g");
-	if (IS_ERR(priv->cpu_clk)) {
-		ret = PTR_ERR(priv->cpu_clk);
-		goto out_put_np;
-	}
+	if (IS_ERR(priv->cpu_clk))
+		return PTR_ERR(priv->cpu_clk);
 
 	priv->dfll_clk = of_clk_get_by_name(np, "dfll");
 	if (IS_ERR(priv->dfll_clk)) {
@@ -110,8 +107,6 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, priv);
 
-	of_node_put(np);
-
 	return 0;
 
 out_put_pllp_clk:
@@ -122,8 +117,6 @@ static int tegra124_cpufreq_probe(struct platform_device *pdev)
 	clk_put(priv->dfll_clk);
 out_put_cpu_clk:
 	clk_put(priv->cpu_clk);
-out_put_np:
-	of_node_put(np);
 
 	return ret;
 }

---
base-commit: 8568bb2ccc278f344e6ac44af6ed010a90aa88dc
change-id: 20240407-cpufreq_of_node_put-0d1972a33561

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH next] cpupfreq: tegra124: eliminate uses of of_node_put()
  2024-04-07 20:15 [PATCH next] cpupfreq: tegra124: eliminate uses of of_node_put() Javier Carrasco
@ 2024-04-19  6:28 ` Viresh Kumar
  0 siblings, 0 replies; 2+ messages in thread
From: Viresh Kumar @ 2024-04-19  6:28 UTC (permalink / raw)
  To: Javier Carrasco
  Cc: Rafael J. Wysocki, Thierry Reding, Jonathan Hunter, Julia Lawall,
	linux-pm, linux-tegra, linux-kernel

On 07-04-24, 22:15, Javier Carrasco wrote:
> Make use of the __free() cleanup handler to automatically free nodes
> when they get out of scope. Only the probe function is affected by this
> modification.
> 
> Given that this mechanism requires the node to be initialized, its
> initialization and the value check have been moved to the top of the
> function.
> 
> After removing uses of of_node_put(), the jump to out_put_np is no
> longer necessary.
> 
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> This patch is a proof of concept to remove uses of of_node_put() in
> cpufreq, which can be replaced with the clenaup handler introduced with
> 54da6a092431 ("locking: Introduce __cleanup() based infrastructure").
> 
> This change provides a scope-based cleanup mechanism to avoid potential
> memory leaks that can appear if of_node_put() is not used correctly.
> 
> The patch is based on the latest linux-next tag (next-20240405).
> ---
>  drivers/cpufreq/tegra124-cpufreq.c | 19 ++++++-------------
>  1 file changed, 6 insertions(+), 13 deletions(-)

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-19  6:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-07 20:15 [PATCH next] cpupfreq: tegra124: eliminate uses of of_node_put() Javier Carrasco
2024-04-19  6:28 ` Viresh Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.