Skip to contentSkip to conversation

cpufreq: Explain the kobject_put() in cpufreq_policy_alloc()

PATCH In review Rafael J. Wysocki 2 participants 2 messages May 10, 2019 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: Explain the kobject_put() in cpufreq_policy_alloc()

From: Rafael J. Wysocki <[email protected]>

It may not be particularly clear why the kobject_put() after failing kobject_init_and_add() in cpufreq_policy_alloc() is not redundant, so add a comment to explain that.

---
 drivers/cpufreq/cpufreq.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/cpufreq/cpufreq.c +5 -0
Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================
@@ -1133,6 +1133,11 @@ static struct cpufreq_policy *cpufreq_po
 				   cpufreq_global_kobject, "policy%u", cpu);
 	if (ret) {
 		pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret);
+		/*
+		 * The entire policy object will be freed below, but the extra
+		 * memory allocated for the kobject name needs to be freed by
+		 * releasing the kobject.
+		 */
 		kobject_put(&policy->kobj);
 		goto err_free_real_cpus;
 	}
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

It may not be particularly clear why the kobject_put() after failing kobject_init_and_add() in cpufreq_policy_alloc() is not redundant, so add a comment to explain that.

---
 drivers/cpufreq/cpufreq.c |    5 +++++
 1 file changed, 5 insertions(+)

Index: linux-pm/drivers/cpufreq/cpufreq.c
===================================================================

drivers/cpufreq/cpufreq.c +0 -0
@@ -1133,6 +1133,11 @@ static struct cpufreq_policy *cpufreq_po
 				   cpufreq_global_kobject, "policy%u", cpu);

drivers/cpufreq/cpufreq.c static struct cpufreq_policy *cpufreq_po · line 1143

Quoted 10 lines
drivers/cpufreq/cpufreq.c +5 -0
 	if (ret) {
 		pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret);
+		/*
+		 * The entire policy object will be freed below, but the extra
+		 * memory allocated for the kobject name needs to be freed by
+		 * releasing the kobject.
+		 */
 		kobject_put(&policy->kobj);
 		goto err_free_real_cpus;
 	}
Signature · 1 line
viresh