Skip to content

Commit 0334906

Browse files
committed
cpufreq: kryo: Release OPP tables on module removal
Commit 5ad7346 ("cpufreq: kryo: Add module remove and exit") made it possible to build the kryo cpufreq driver as a module, but it failed to release all the resources, i.e. OPP tables, when the module is unloaded. This patch fixes it by releasing the OPP tables, by calling dev_pm_opp_put_supported_hw() for them, from the qcom_cpufreq_kryo_remove() routine. The array of pointers to the OPP tables is also allocated dynamically now in qcom_cpufreq_kryo_probe(), as the pointers will be required while releasing the resources. Compile tested only. Cc: 4.18+ <stable@vger.kernel.org> # v4.18+ Fixes: 5ad7346 ("cpufreq: kryo: Add module remove and exit") Reviewed-by: Georgi Djakov <georgi.djakov@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent d3c1e33 commit 0334906

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/cpufreq/qcom-cpufreq-kryo.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static enum _msm8996_version qcom_cpufreq_kryo_get_msm_id(void)
7575

7676
static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
7777
{
78-
struct opp_table *opp_tables[NR_CPUS] = {0};
78+
struct opp_table **opp_tables;
7979
enum _msm8996_version msm8996_version;
8080
struct nvmem_cell *speedbin_nvmem;
8181
struct device_node *np;
@@ -133,6 +133,10 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
133133
}
134134
kfree(speedbin);
135135

136+
opp_tables = kcalloc(num_possible_cpus(), sizeof(*opp_tables), GFP_KERNEL);
137+
if (!opp_tables)
138+
return -ENOMEM;
139+
136140
for_each_possible_cpu(cpu) {
137141
cpu_dev = get_cpu_device(cpu);
138142
if (NULL == cpu_dev) {
@@ -151,8 +155,10 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
151155

152156
cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1,
153157
NULL, 0);
154-
if (!IS_ERR(cpufreq_dt_pdev))
158+
if (!IS_ERR(cpufreq_dt_pdev)) {
159+
platform_set_drvdata(pdev, opp_tables);
155160
return 0;
161+
}
156162

157163
ret = PTR_ERR(cpufreq_dt_pdev);
158164
dev_err(cpu_dev, "Failed to register platform device\n");
@@ -163,13 +169,23 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
163169
break;
164170
dev_pm_opp_put_supported_hw(opp_tables[cpu]);
165171
}
172+
kfree(opp_tables);
166173

167174
return ret;
168175
}
169176

170177
static int qcom_cpufreq_kryo_remove(struct platform_device *pdev)
171178
{
179+
struct opp_table **opp_tables = platform_get_drvdata(pdev);
180+
unsigned int cpu;
181+
172182
platform_device_unregister(cpufreq_dt_pdev);
183+
184+
for_each_possible_cpu(cpu)
185+
dev_pm_opp_put_supported_hw(opp_tables[cpu]);
186+
187+
kfree(opp_tables);
188+
173189
return 0;
174190
}
175191

0 commit comments

Comments
 (0)