Skip to contentSkip to conversation

int340X/processor_thermal_device: Fix proc_thermal_rapl_remove()

PATCH In review Rafael J. Wysocki 3 participants 3 messages Jul 22, 2019 – Jul 23, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 int340X/processor_thermal_device: Fix proc_thermal_rapl_remove()

From: Rafael J. Wysocki <[email protected]>

Passing 0 to cpuhp_remove_state() triggers the BUG_ON() in __cpuhp_remove_state_cpuslocked() and the argument passed to powercap_unregister_control_type() is expected to be a valid pointer, so avoid calling these functions with incorrect arguments from proc_thermal_rapl_remove().

Fixes 555c45fe0d04 ("int340X/processor_thermal_device: add support for MMIO RAPL")
---
 drivers/thermal/intel/int340x_thermal/processor_thermal_device.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +4 -0
Index: linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
===================================================================
@@ -487,6 +487,7 @@ static int proc_thermal_rapl_add(struct
 				rapl_mmio_cpu_online, rapl_mmio_cpu_down_prep);
 	if (ret < 0) {
 		powercap_unregister_control_type(rapl_mmio_priv.control_type);
+		rapl_mmio_priv.control_type = NULL;
 		return ret;
 	}
 	rapl_mmio_priv.pcap_rapl_online = ret;
@@ -496,6 +497,9 @@ static int proc_thermal_rapl_add(struct
 
 static void proc_thermal_rapl_remove(void)
 {
+	if (IS_ERR_OR_NULL(rapl_mmio_priv.control_type))
+		return;
+
 	cpuhp_remove_state(rapl_mmio_priv.pcap_rapl_online);
 	powercap_unregister_control_type(rapl_mmio_priv.control_type);
 }
#1 lore raw
Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Passing 0 to cpuhp_remove_state() triggers the BUG_ON() in __cpuhp_remove_state_cpuslocked() and the argument passed to powercap_unregister_control_type() is expected to be a valid pointer, so avoid calling these functions with incorrect arguments from proc_thermal_rapl_remove().

Fixes 555c45fe0d04 ("int340X/processor_thermal_device: add support for MMIO RAPL")

Any comments?

If not, I'll queue this up along with the other RAPL-related fix
(https://patchwork.kernel.org/patch/11050999/).

Quoted 29 lines
---
 drivers/thermal/intel/int340x_thermal/processor_thermal_device.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: linux-pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
===================================================================

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +4 -0
@@ -487,6 +487,7 @@ static int proc_thermal_rapl_add(struct
                                rapl_mmio_cpu_online, rapl_mmio_cpu_down_prep);
        if (ret < 0) {
                powercap_unregister_control_type(rapl_mmio_priv.control_type);
+               rapl_mmio_priv.control_type = NULL;
                return ret;
        }
        rapl_mmio_priv.pcap_rapl_online = ret;
@@ -496,6 +497,9 @@ static int proc_thermal_rapl_add(struct
 
 static void proc_thermal_rapl_remove(void)
 {
+       if (IS_ERR_OR_NULL(rapl_mmio_priv.control_type))
+               return;
+
        cpuhp_remove_state(rapl_mmio_priv.pcap_rapl_online);
        powercap_unregister_control_type(rapl_mmio_priv.control_type);
 }
reviewer Acked-by
#2 lore raw
Quoted 15 lines · Rafael J. Wysocki

On Mon, Jul 22, 2019 at 12:23 PM Rafael J. Wysocki <[email protected]

Quoted 14 lines

wrote:

From: Rafael J. Wysocki <[email protected]>

Passing 0 to cpuhp_remove_state() triggers the BUG_ON() in __cpuhp_remove_state_cpuslocked() and the argument passed to powercap_unregister_control_type() is expected to be a valid pointer, so avoid calling these functions with incorrect arguments from proc_thermal_rapl_remove().

Fixes 555c45fe0d04 ("int340X/processor_thermal_device: add support

for MMIO RAPL")

Quoted 43 lines

Any comments?

If not, I'll queue this up along with the other RAPL-related fix
(https://patchwork.kernel.org/patch/11050999/).

Quoted 38 lines

---
 drivers/thermal/intel/int340x_thermal/processor_thermal_device.c |    4 ++++

 1 file changed, 4 insertions(+)

Index: linux- pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
===================================================================
--- linux- pm.orig/drivers/thermal/intel/int340x_thermal/processor_thermal_dev ice.c
+++ linux- pm/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

(quoted diff) +0 -0
@@ -487,6 +487,7 @@ static int proc_thermal_rapl_add(struct
                                 rapl_mmio_cpu_online,
 rapl_mmio_cpu_down_prep);
         if (ret < 0) {

                powercap_unregister_control_type(rapl_mmio_priv.con trol_type);
+               rapl_mmio_priv.control_type = NULL; return ret;
        }
        rapl_mmio_priv.pcap_rapl_online = ret;

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +3 -0
@@ -496,6 +497,9 @@ static int proc_thermal_rapl_add(struct
 
  static void proc_thermal_rapl_remove(void)
  {
+       if (IS_ERR_OR_NULL(rapl_mmio_priv.control_type))
+               return;
+
         cpuhp_remove_state(rapl_mmio_priv.pcap_rapl_online);

        powercap_unregister_control_type(rapl_mmio_priv.control_typ e);
 }