Skip to content

Commit d776790

Browse files
Hector.Yuanvireshk
authored andcommitted
cpufreq: mediatek-hw: Fix double devm_remap in hotplug case
When hotpluging policy cpu, cpu policy init will be called multiple times. Unplug CPU7 -> CPU6 -> CPU5 -> CPU4, then plug CPU4 again. In this case, devm_remap will double remap and resource allocate fail. So replace devm_remap to ioremap and release resources in cpu policy exit. Signed-off-by: Hector.Yuan <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent 8f5783a commit d776790

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

drivers/cpufreq/mediatek-cpufreq-hw.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ enum {
3636
struct mtk_cpufreq_data {
3737
struct cpufreq_frequency_table *table;
3838
void __iomem *reg_bases[REG_ARRAY_SIZE];
39+
struct resource *res;
40+
void __iomem *base;
3941
int nr_opp;
4042
};
4143

@@ -156,6 +158,7 @@ static int mtk_cpu_resources_init(struct platform_device *pdev,
156158
{
157159
struct mtk_cpufreq_data *data;
158160
struct device *dev = &pdev->dev;
161+
struct resource *res;
159162
void __iomem *base;
160163
int ret, i;
161164
int index;
@@ -170,9 +173,26 @@ static int mtk_cpu_resources_init(struct platform_device *pdev,
170173
if (index < 0)
171174
return index;
172175

173-
base = devm_platform_ioremap_resource(pdev, index);
174-
if (IS_ERR(base))
175-
return PTR_ERR(base);
176+
res = platform_get_resource(pdev, IORESOURCE_MEM, index);
177+
if (!res) {
178+
dev_err(dev, "failed to get mem resource %d\n", index);
179+
return -ENODEV;
180+
}
181+
182+
if (!request_mem_region(res->start, resource_size(res), res->name)) {
183+
dev_err(dev, "failed to request resource %pR\n", res);
184+
return -EBUSY;
185+
}
186+
187+
base = ioremap(res->start, resource_size(res));
188+
if (!base) {
189+
dev_err(dev, "failed to map resource %pR\n", res);
190+
ret = -ENOMEM;
191+
goto release_region;
192+
}
193+
194+
data->base = base;
195+
data->res = res;
176196

177197
for (i = REG_FREQ_LUT_TABLE; i < REG_ARRAY_SIZE; i++)
178198
data->reg_bases[i] = base + offsets[i];
@@ -187,6 +207,9 @@ static int mtk_cpu_resources_init(struct platform_device *pdev,
187207
policy->driver_data = data;
188208

189209
return 0;
210+
release_region:
211+
release_mem_region(res->start, resource_size(res));
212+
return ret;
190213
}
191214

192215
static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
@@ -233,9 +256,13 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
233256
static int mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy)
234257
{
235258
struct mtk_cpufreq_data *data = policy->driver_data;
259+
struct resource *res = data->res;
260+
void __iomem *base = data->base;
236261

237262
/* HW should be in paused state now */
238263
writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]);
264+
iounmap(base);
265+
release_mem_region(res->start, resource_size(res));
239266

240267
return 0;
241268
}

0 commit comments

Comments
 (0)