Skip to contentSkip to conversation

thermal: gov_power_allocator: Add missing NULL pointer check

PATCH In review Rafael J. Wysocki 2 participants 2 messages Nov 25, 2024 – Nov 26, 2024

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

PATCH 1/1 thermal: gov_power_allocator: Add missing NULL pointer check

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

Commit 0dc23567c206 ("thermal: core: Move lists of thermal instances to trip descriptors") overlooked the case in which the Power Allocator governor attempts to bind to a tripless thermal zone and params->trip_max is NULL in check_power_actors().

No power actors can be found in that case, so check_power_actors() needs to be made return 0 then to restore its previous behavior.

Fixes 0dc23567c206 ("thermal: core: Move lists of thermal instances to trip descriptors")
---
 drivers/thermal/gov_power_allocator.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/thermal/gov_power_allocator.c +6 -1
Index: linux-pm/drivers/thermal/gov_power_allocator.c
===================================================================
@@ -588,10 +588,15 @@ static void allow_maximum_power(struct t
 static int check_power_actors(struct thermal_zone_device *tz,
 			      struct power_allocator_params *params)
 {
-	const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
+	const struct thermal_trip_desc *td;
 	struct thermal_instance *instance;
 	int ret = 0;
 
+	if (!params->trip_max)
+		return 0;
+
+	td = trip_to_trip_desc(params->trip_max);
+
 	list_for_each_entry(instance, &td->thermal_instances, trip_node) {
 		if (!cdev_is_power_actor(instance->cdev)) {
 			dev_warn(&tz->device, "power_allocator: %s is not a power actor\n",
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Rafael J. Wysocki

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

Commit 0dc23567c206 ("thermal: core: Move lists of thermal instances to trip descriptors") overlooked the case in which the Power Allocator governor attempts to bind to a tripless thermal zone and params->trip_max is NULL in check_power_actors().

That corner case sneaked in...

Quoted 17 lines

No power actors can be found in that case, so check_power_actors() needs to be made return 0 then to restore its previous behavior.

Fixes 0dc23567c206 ("thermal: core: Move lists of thermal instances to trip descriptors")
---
  drivers/thermal/gov_power_allocator.c |    7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

Index: linux-pm/drivers/thermal/gov_power_allocator.c
===================================================================

drivers/thermal/gov_power_allocator.c static void allow_maximum_power(struct t · line 596

Quoted 10 lines
drivers/thermal/gov_power_allocator.c +3 -1
@@ -588,10 +588,15 @@ static void allow_maximum_power(struct t
  static int check_power_actors(struct thermal_zone_device *tz,
  			      struct power_allocator_params *params)
  {
-	const struct thermal_trip_desc *td = trip_to_trip_desc(params->trip_max);
+	const struct thermal_trip_desc *td;
  	struct thermal_instance *instance;
  	int ret = 0;
 
+	if (!params->trip_max)
+		return 0;

Yes, 0 is the right thing to return here, since we might get later some trip points.

drivers/thermal/gov_power_allocator.c static void allow_maximum_power(struct t · line 602

Quoted 9 lines
drivers/thermal/gov_power_allocator.c +3 -0
+
+	td = trip_to_trip_desc(params->trip_max);
+
  	list_for_each_entry(instance, &td->thermal_instances, trip_node) {
  		if (!cdev_is_power_actor(instance->cdev)) {
  			dev_warn(&tz->device, "power_allocator: %s is not a power actor\n",