Message ID | 4551531.LvFx2qVVIh@kreacher |
---|---|
Headers | show |
Series | thermal: Store trips table and ops in thermal_zone_device | expand |
On 14/02/2024 13:28, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > The current code expects thermal zone creators to pass a pointer to a > writable trips table to thermal_zone_device_register_with_trips() and > that trips table is then used by the thermal core going forward. > > Consequently, the callers of thermal_zone_device_register_with_trips() > are required to hold on to the trips table passed to it until the given > thermal zone is unregistered, at which point the trips table can be > freed, but at the same time they are not expected to access that table > directly. This is both error prone and confusing. > > To address it, turn the trips table pointer in struct thermal_zone_device > into a flex array (counted by its num_trips field), allocate it during > thermal zone device allocation and copy the contents of the trips table > supplied by the zone creator (which can be const now) into it, which > will allow the callers of thermal_zone_device_register_with_trips() to > drop their trip tables right after the zone registration. > > This requires the imx thermal driver to be adjusted to store the new > temperature in its internal trips table in imx_set_trip_temp(), because > it will be separate from the core's trips table now and it has to be > explicitly kept in sync with the latter. > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
On 14/02/2024 13:42, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Because the thermal core creates and uses its own copy of the trips > table passed to thermal_zone_device_register_with_trips(), it is not > necessary to hold on to a local copy of it any more after the given > thermal zone has been registered. > > Accordingly, modify Intel thermal drivers to discard the trips tables > passed to thermal_zone_device_register_with_trips() after thermal zone > registration, for example by storing them in local variables which are > automatically discarded when the zone registration is complete. > > Also make some additional code simplifications unlocked by the above > changes. > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
On 14/02/2024 13:48, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Because thermal zone operations are now stored directly in struct > thermal_zone_device, acpi_thermal_zone_ops need not be modified by > the thermal core and so it can be const. > > Adjust the code accordingly. > > No functional impact. > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > --- Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
On 22/02/2024 14:10, Rafael J. Wysocki wrote: [ ... ] > Index: linux-pm/drivers/thermal/thermal_of.c > =================================================================== > --- linux-pm.orig/drivers/thermal/thermal_of.c > +++ linux-pm/drivers/thermal/thermal_of.c > @@ -440,12 +440,10 @@ static int thermal_of_unbind(struct ther > */ > static void thermal_of_zone_unregister(struct thermal_zone_device *tz) > { > - struct thermal_trip *trips = tz->trips; > struct thermal_zone_device_ops *ops = tz->ops; > > thermal_zone_device_disable(tz); > thermal_zone_device_unregister(tz); > - kfree(trips); thermal_of_zone_register() must free the allocated trip points after registering the thermal zone. > kfree(ops); > }
On Thu, Feb 22, 2024 at 2:38 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 22/02/2024 14:10, Rafael J. Wysocki wrote: > > [ ... ] > > > Index: linux-pm/drivers/thermal/thermal_of.c > > =================================================================== > > --- linux-pm.orig/drivers/thermal/thermal_of.c > > +++ linux-pm/drivers/thermal/thermal_of.c > > @@ -440,12 +440,10 @@ static int thermal_of_unbind(struct ther > > */ > > static void thermal_of_zone_unregister(struct thermal_zone_device *tz) > > { > > - struct thermal_trip *trips = tz->trips; > > struct thermal_zone_device_ops *ops = tz->ops; > > > > thermal_zone_device_disable(tz); > > thermal_zone_device_unregister(tz); > > - kfree(trips); > > thermal_of_zone_register() must free the allocated trip points after > registering the thermal zone. > > > kfree(ops); > > } Good point. Let me send another update, then.