Skip to content

Commit cdc1719

Browse files
yu-chen-surfrafaeljw
authored andcommitted
cpufreq: intel_pstate: Delete intel_pstate sysfs if failed to register the driver
There is a corner case that if the intel_pstate driver fails to be registered (might be due to invalid MSR access) and acpi_cpufreq takse over, the intel_pstate sysfs interface is still populated which may confuse user space (turbostat for example): grep . /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver acpi-cpufreq grep . /sys/devices/system/cpu/intel_pstate/* /sys/devices/system/cpu/intel_pstate/max_perf_pct:0 /sys/devices/system/cpu/intel_pstate/min_perf_pct:0 grep: /sys/devices/system/cpu/intel_pstate/no_turbo: Resource temporarily unavailable grep: /sys/devices/system/cpu/intel_pstate/num_pstates: Resource temporarily unavailable /sys/devices/system/cpu/intel_pstate/status:off grep: /sys/devices/system/cpu/intel_pstate/turbo_pct: Resource temporarily unavailable The mere presence of the intel_pstate sysfs interface does not mean that intel_pstate is in use (for example, echo "off" to "status"), but it should not be created in the failing case. Fix this issue by deleting the intel_pstate sysfs if the driver registration fails. Reported-by: Wendy Wang <wendy.wang@intel.com> Suggested-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Chen Yu <yu.c.chen@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com [ rjw: Refactor code to avoid jumps, change function name, changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 97148d0 commit cdc1719

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

drivers/cpufreq/intel_pstate.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,24 @@ static void __init intel_pstate_sysfs_expose_params(void)
14201420
}
14211421
}
14221422

1423+
static void __init intel_pstate_sysfs_remove(void)
1424+
{
1425+
if (!intel_pstate_kobject)
1426+
return;
1427+
1428+
sysfs_remove_group(intel_pstate_kobject, &intel_pstate_attr_group);
1429+
1430+
if (!per_cpu_limits) {
1431+
sysfs_remove_file(intel_pstate_kobject, &max_perf_pct.attr);
1432+
sysfs_remove_file(intel_pstate_kobject, &min_perf_pct.attr);
1433+
1434+
if (x86_match_cpu(intel_pstate_cpu_ee_disable_ids))
1435+
sysfs_remove_file(intel_pstate_kobject, &energy_efficiency.attr);
1436+
}
1437+
1438+
kobject_put(intel_pstate_kobject);
1439+
}
1440+
14231441
static void intel_pstate_sysfs_expose_hwp_dynamic_boost(void)
14241442
{
14251443
int rc;
@@ -3063,8 +3081,10 @@ static int __init intel_pstate_init(void)
30633081
mutex_lock(&intel_pstate_driver_lock);
30643082
rc = intel_pstate_register_driver(default_driver);
30653083
mutex_unlock(&intel_pstate_driver_lock);
3066-
if (rc)
3084+
if (rc) {
3085+
intel_pstate_sysfs_remove();
30673086
return rc;
3087+
}
30683088

30693089
if (hwp_active) {
30703090
const struct x86_cpu_id *id;

0 commit comments

Comments
 (0)