* [PATCH v1] thermal: gov_power_allocator: Add missing NULL pointer check
@ 2024-11-25 11:24 Rafael J. Wysocki
2024-11-26 9:36 ` Lukasz Luba
0 siblings, 1 reply; 2+ messages in thread
From: Rafael J. Wysocki @ 2024-11-25 11:24 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Daniel Lezcano, Lukasz Luba, Sasha Levin, Rafael J. Wysocki,
Linus Torvalds
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
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")
Closes: https://lore.kernel.org/linux-pm/Z0NeGF4ryCe_b5rr@sashalap/
Reported-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/gov_power_allocator.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
Index: linux-pm/drivers/thermal/gov_power_allocator.c
===================================================================
--- linux-pm.orig/drivers/thermal/gov_power_allocator.c
+++ 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",
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1] thermal: gov_power_allocator: Add missing NULL pointer check
2024-11-25 11:24 [PATCH v1] thermal: gov_power_allocator: Add missing NULL pointer check Rafael J. Wysocki
@ 2024-11-26 9:36 ` Lukasz Luba
0 siblings, 0 replies; 2+ messages in thread
From: Lukasz Luba @ 2024-11-26 9:36 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: LKML, Linux PM, Daniel Lezcano, Sasha Levin, Rafael J. Wysocki,
Linus Torvalds
On 11/25/24 11:24, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> 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...
>
> 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")
> Closes: https://lore.kernel.org/linux-pm/Z0NeGF4ryCe_b5rr@sashalap/
> Reported-by: Sasha Levin <sashal@kernel.org>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/thermal/gov_power_allocator.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> Index: linux-pm/drivers/thermal/gov_power_allocator.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/gov_power_allocator.c
> +++ 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;
Yes, 0 is the right thing to return here, since we might get later some
trip points.
> +
> + 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",
>
>
>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-26 9:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-25 11:24 [PATCH v1] thermal: gov_power_allocator: Add missing NULL pointer check Rafael J. Wysocki
2024-11-26 9:36 ` Lukasz Luba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).