Skip to content

Commit b5d68f8

Browse files
spandruvadarafaeljw
authored andcommitted
thermal: intel: powerclamp: Fix NULL pointer access issue
If cur_state for the powerclamp cooling device is set to the default minimum state of 0, without setting first to cur_state > 0, this results in NULL pointer access. This NULL pointer access happens in the powercap core idle-inject function idle_inject_set_duration() as there is no NULL check for idle_inject_device pointer. This pointer must be allocated by calling idle_inject_register() or idle_inject_register_full(). In the function powerclamp_set_cur_state(), idle_inject_device pointer is allocated only when the cur_state > 0. But setting 0 without changing to any other state, idle_inject_set_duration() will be called with a NULL idle_inject_device pointer. To address this, just return from powerclamp_set_cur_state() if the current cooling device state is the same as the last one. Since the power-up default cooling device state is 0, changing the state to 0 again here will return without calling idle_inject_set_duration(). Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Fixes: 8526eb7 ("thermal: intel: powerclamp: Use powercap idle-inject feature") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=217386 Tested-by: Risto A. Paju <teknohog@iki.fi> Cc: 6.3+ <stable@kernel.org> # 6.3+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 667de5c commit b5d68f8

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

drivers/thermal/intel/intel_powerclamp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
703703

704704
new_target_ratio = clamp(new_target_ratio, 0UL,
705705
(unsigned long) (max_idle - 1));
706+
707+
if (powerclamp_data.target_ratio == new_target_ratio)
708+
goto exit_set;
709+
706710
if (!powerclamp_data.target_ratio && new_target_ratio > 0) {
707711
pr_info("Start idle injection to reduce power\n");
708712
powerclamp_data.target_ratio = new_target_ratio;

0 commit comments

Comments
 (0)