Skip to content

Commit 2d8b39a

Browse files
committed
ACPI: processor: Avoid NULL pointer dereferences at init time
If there are neither processor objects nor processor device objects in the ACPI tables, the per-CPU processors table will not be initialized and attempting to dereference pointers from there will cause the kernel to crash. This happens in acpi_processor_ppc_init() and acpi_thermal_cpufreq_init() after commit d15ce41 ("ACPI: cpufreq: Switch to QoS requests instead of cpufreq notifier") which didn't add the requisite NULL pointer checks in there. Add the NULL pointer checks to acpi_processor_ppc_init() and acpi_thermal_cpufreq_init(), and to the corresponding "exit" routines. While at it, drop redundant return instructions from acpi_processor_ppc_init() and acpi_thermal_cpufreq_init(). Fixes: d15ce41 ("ACPI: cpufreq: Switch to QoS requests instead of cpufreq notifier") Reported-by: Srinivas Pandruvada <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Viresh Kumar <[email protected]>
1 parent 65650b3 commit 2d8b39a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

drivers/acpi/processor_perflib.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,23 @@ void acpi_processor_ppc_init(int cpu)
162162
struct acpi_processor *pr = per_cpu(processors, cpu);
163163
int ret;
164164

165+
if (!pr)
166+
return;
167+
165168
ret = dev_pm_qos_add_request(get_cpu_device(cpu),
166169
&pr->perflib_req, DEV_PM_QOS_MAX_FREQUENCY,
167170
INT_MAX);
168-
if (ret < 0) {
171+
if (ret < 0)
169172
pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu,
170173
ret);
171-
return;
172-
}
173174
}
174175

175176
void acpi_processor_ppc_exit(int cpu)
176177
{
177178
struct acpi_processor *pr = per_cpu(processors, cpu);
178179

179-
dev_pm_qos_remove_request(&pr->perflib_req);
180+
if (pr)
181+
dev_pm_qos_remove_request(&pr->perflib_req);
180182
}
181183

182184
static int acpi_processor_get_performance_control(struct acpi_processor *pr)

drivers/acpi/processor_thermal.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,23 @@ void acpi_thermal_cpufreq_init(int cpu)
130130
struct acpi_processor *pr = per_cpu(processors, cpu);
131131
int ret;
132132

133+
if (!pr)
134+
return;
135+
133136
ret = dev_pm_qos_add_request(get_cpu_device(cpu),
134137
&pr->thermal_req, DEV_PM_QOS_MAX_FREQUENCY,
135138
INT_MAX);
136-
if (ret < 0) {
139+
if (ret < 0)
137140
pr_err("Failed to add freq constraint for CPU%d (%d)\n", cpu,
138141
ret);
139-
return;
140-
}
141142
}
142143

143144
void acpi_thermal_cpufreq_exit(int cpu)
144145
{
145146
struct acpi_processor *pr = per_cpu(processors, cpu);
146147

147-
dev_pm_qos_remove_request(&pr->thermal_req);
148+
if (pr)
149+
dev_pm_qos_remove_request(&pr->thermal_req);
148150
}
149151
#else /* ! CONFIG_CPU_FREQ */
150152
static int cpufreq_get_max_state(unsigned int cpu)

0 commit comments

Comments
 (0)