Skip to content

Commit b49bee3

Browse files
Shawn Guogregkh
authored andcommitted
cpufreq: qcom-hw: drop devm_xxx() calls from init/exit hooks
commit 67fc209 upstream. Commit f17b3e4 ("cpufreq: qcom-hw: Use devm_platform_ioremap_resource() to simplify code") introduces a regression on platforms using the driver, by failing to initialise a policy, when one is created post hotplug. When all the CPUs of a policy are hoptplugged out, the call to .exit() and later to devm_iounmap() does not release the memory region that was requested during devm_platform_ioremap_resource(). Therefore, a subsequent call to .init() will result in the following error, which will prevent a new policy to be initialised: [ 3395.915416] CPU4: shutdown [ 3395.938185] psci: CPU4 killed (polled 0 ms) [ 3399.071424] CPU5: shutdown [ 3399.094316] psci: CPU5 killed (polled 0 ms) [ 3402.139358] CPU6: shutdown [ 3402.161705] psci: CPU6 killed (polled 0 ms) [ 3404.742939] CPU7: shutdown [ 3404.765592] psci: CPU7 killed (polled 0 ms) [ 3411.492274] Detected VIPT I-cache on CPU4 [ 3411.492337] GICv3: CPU4: found redistributor 400 region 0:0x0000000017ae0000 [ 3411.492448] CPU4: Booted secondary processor 0x0000000400 [0x516f802d] [ 3411.503654] qcom-cpufreq-hw 17d43000.cpufreq: can't request region for resource [mem 0x17d45800-0x17d46bff] With that being said, the original code was tricky and skipping memory region request intentionally to hide this issue. The true cause is that those devm_xxx() device managed functions shouldn't be used for cpufreq init/exit hooks, because &pdev->dev is alive across the hooks and will not trigger auto resource free-up. Let's drop the use of device managed functions and manually allocate/free resources, so that the issue can be fixed properly. Cc: v5.10+ <stable@vger.kernel.org> # v5.10+ Fixes: f17b3e4 ("cpufreq: qcom-hw: Use devm_platform_ioremap_resource() to simplify code") Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b3df1ea commit b49bee3

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

‎drivers/cpufreq/qcom-cpufreq-hw.c‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct qcom_cpufreq_soc_data {
3232

3333
struct qcom_cpufreq_data {
3434
void __iomem *base;
35+
struct resource *res;
3536
const struct qcom_cpufreq_soc_data *soc_data;
3637
};
3738

@@ -280,6 +281,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
280281
struct of_phandle_args args;
281282
struct device_node *cpu_np;
282283
struct device *cpu_dev;
284+
struct resource *res;
283285
void __iomem *base;
284286
struct qcom_cpufreq_data *data;
285287
int ret, index;
@@ -303,18 +305,33 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
303305

304306
index = args.args[0];
305307

306-
base = devm_platform_ioremap_resource(pdev, index);
307-
if (IS_ERR(base))
308-
return PTR_ERR(base);
308+
res = platform_get_resource(pdev, IORESOURCE_MEM, index);
309+
if (!res) {
310+
dev_err(dev, "failed to get mem resource %d\n", index);
311+
return -ENODEV;
312+
}
313+
314+
if (!request_mem_region(res->start, resource_size(res), res->name)) {
315+
dev_err(dev, "failed to request resource %pR\n", res);
316+
return -EBUSY;
317+
}
309318

310-
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
319+
base = ioremap(res->start, resource_size(res));
320+
if (IS_ERR(base)) {
321+
dev_err(dev, "failed to map resource %pR\n", res);
322+
ret = PTR_ERR(base);
323+
goto release_region;
324+
}
325+
326+
data = kzalloc(sizeof(*data), GFP_KERNEL);
311327
if (!data) {
312328
ret = -ENOMEM;
313-
goto error;
329+
goto unmap_base;
314330
}
315331

316332
data->soc_data = of_device_get_match_data(&pdev->dev);
317333
data->base = base;
334+
data->res = res;
318335

319336
/* HW should be in enabled state to proceed */
320337
if (!(readl_relaxed(base + data->soc_data->reg_enable) & 0x1)) {
@@ -349,20 +366,27 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
349366

350367
return 0;
351368
error:
352-
devm_iounmap(dev, base);
369+
kfree(data);
370+
unmap_base:
371+
iounmap(data->base);
372+
release_region:
373+
release_mem_region(res->start, resource_size(res));
353374
return ret;
354375
}
355376

356377
static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
357378
{
358379
struct device *cpu_dev = get_cpu_device(policy->cpu);
359380
struct qcom_cpufreq_data *data = policy->driver_data;
360-
struct platform_device *pdev = cpufreq_get_driver_data();
381+
struct resource *res = data->res;
382+
void __iomem *base = data->base;
361383

362384
dev_pm_opp_remove_all_dynamic(cpu_dev);
363385
dev_pm_opp_of_cpumask_remove_table(policy->related_cpus);
364386
kfree(policy->freq_table);
365-
devm_iounmap(&pdev->dev, data->base);
387+
kfree(data);
388+
iounmap(base);
389+
release_mem_region(res->start, resource_size(res));
366390

367391
return 0;
368392
}

0 commit comments

Comments
 (0)