public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Linux PM <linux-pm@vger.kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Zhang Rui <rui.zhang@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH v1 1/6] thermal: core: Store zone trips table in struct thermal_zone_device
Date: Thu, 8 Feb 2024 09:22:09 +0100	[thread overview]
Message-ID: <ZcSPMRH34M5yG/IU@linux.intel.com> (raw)
In-Reply-To: <5762433.DvuYhMxLoT@kreacher>

On Mon, Feb 05, 2024 at 10:14:31PM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The current code requires 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 allowed to access the cells in
> 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.
> 
> This allows the callers of thermal_zone_device_register_with_trips() to
> drop their trip tables right after the zone registration.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>

> ---
>  drivers/thermal/thermal_core.c |   16 +++++++++-------
>  include/linux/thermal.h        |   10 +++++-----
>  2 files changed, 14 insertions(+), 12 deletions(-)
> 
> Index: linux-pm/include/linux/thermal.h
> ===================================================================
> --- linux-pm.orig/include/linux/thermal.h
> +++ linux-pm/include/linux/thermal.h
> @@ -130,7 +130,6 @@ struct thermal_cooling_device {
>   * @trip_hyst_attrs:	attributes for trip points for sysfs: trip hysteresis
>   * @mode:		current mode of this thermal zone
>   * @devdata:	private pointer for device private data
> - * @trips:	an array of struct thermal_trip
>   * @num_trips:	number of trip points the thermal zone supports
>   * @passive_delay_jiffies: number of jiffies to wait between polls when
>   *			performing passive cooling.
> @@ -160,6 +159,7 @@ struct thermal_cooling_device {
>   * @poll_queue:	delayed work for polling
>   * @notify_event: Last notification event
>   * @suspended: thermal zone suspend indicator
> + * @trips:	array of struct thermal_trip objects
>   */
>  struct thermal_zone_device {
>  	int id;
> @@ -172,7 +172,6 @@ struct thermal_zone_device {
>  	struct thermal_attr *trip_hyst_attrs;
>  	enum thermal_device_mode mode;
>  	void *devdata;
> -	struct thermal_trip *trips;
>  	int num_trips;
>  	unsigned long passive_delay_jiffies;
>  	unsigned long polling_delay_jiffies;
> @@ -193,10 +192,11 @@ struct thermal_zone_device {
>  	struct list_head node;
>  	struct delayed_work poll_queue;
>  	enum thermal_notify_event notify_event;
> +	bool suspended;
>  #ifdef CONFIG_THERMAL_DEBUGFS
>  	struct thermal_debugfs *debugfs;
>  #endif
> -	bool suspended;
> +	struct thermal_trip trips[] __counted_by(num_trips);
>  };
>  
>  /**
> @@ -315,7 +315,7 @@ int thermal_zone_get_crit_temp(struct th
>  #ifdef CONFIG_THERMAL
>  struct thermal_zone_device *thermal_zone_device_register_with_trips(
>  					const char *type,
> -					struct thermal_trip *trips,
> +					const struct thermal_trip *trips,
>  					int num_trips, int mask,
>  					void *devdata,
>  					struct thermal_zone_device_ops *ops,
> @@ -375,7 +375,7 @@ void thermal_zone_device_critical(struct
>  #else
>  static inline struct thermal_zone_device *thermal_zone_device_register_with_trips(
>  					const char *type,
> -					struct thermal_trip *trips,
> +					const struct thermal_trip *trips,
>  					int num_trips, int mask,
>  					void *devdata,
>  					struct thermal_zone_device_ops *ops,
> Index: linux-pm/drivers/thermal/thermal_core.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_core.c
> +++ linux-pm/drivers/thermal/thermal_core.c
> @@ -1272,10 +1272,13 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_crit_
>   * IS_ERR*() helpers.
>   */
>  struct thermal_zone_device *
> -thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask,
> -					void *devdata, struct thermal_zone_device_ops *ops,
> -					const struct thermal_zone_params *tzp, int passive_delay,
> -					int polling_delay)
> +thermal_zone_device_register_with_trips(const char *type,
> +					const struct thermal_trip *trips,
> +					int num_trips, int mask,
> +					void *devdata,
> +					struct thermal_zone_device_ops *ops,
> +					const struct thermal_zone_params *tzp,
> +					int passive_delay, int polling_delay)
>  {
>  	struct thermal_zone_device *tz;
>  	int id;
> @@ -1322,7 +1325,7 @@ thermal_zone_device_register_with_trips(
>  	if (!thermal_class)
>  		return ERR_PTR(-ENODEV);
>  
> -	tz = kzalloc(sizeof(*tz), GFP_KERNEL);
> +	tz = kzalloc(struct_size(tz, trips, num_trips), GFP_KERNEL);
>  	if (!tz)
>  		return ERR_PTR(-ENOMEM);
>  
> @@ -1344,7 +1347,6 @@ thermal_zone_device_register_with_trips(
>  		result = id;
>  		goto free_tzp;
>  	}
> -
>  	tz->id = id;
>  	strscpy(tz->type, type, sizeof(tz->type));
>  
> @@ -1354,7 +1356,7 @@ thermal_zone_device_register_with_trips(
>  	tz->ops = ops;
>  	tz->device.class = thermal_class;
>  	tz->devdata = devdata;
> -	tz->trips = trips;
> +	memcpy(tz->trips, trips, num_trips * sizeof(trips[0]));
>  	tz->num_trips = num_trips;
>  
>  	thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
> 
> 
> 
> 

  reply	other threads:[~2024-02-08  8:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-05 21:12 [PATCH v1 0/6] thermal: Store trips table and ops in thermal_zone_device Rafael J. Wysocki
2024-02-05 21:14 ` [PATCH v1 1/6] thermal: core: Store zone trips table in struct thermal_zone_device Rafael J. Wysocki
2024-02-08  8:22   ` Stanislaw Gruszka [this message]
2024-02-08 19:25     ` Rafael J. Wysocki
2024-02-05 21:15 ` [PATCH v1 2/6] thermal: ACPI: Discard trip table after zone registration Rafael J. Wysocki
2024-02-08  8:22   ` Stanislaw Gruszka
2024-02-05 21:16 ` [PATCH v1 3/6] thermal: intel: Discard trip tables " Rafael J. Wysocki
2024-02-08  8:36   ` Stanislaw Gruszka
2024-02-05 21:18 ` [PATCH v1 4/6] thermal: core: Store zone ops in struct thermal_zone_device Rafael J. Wysocki
2024-02-08  8:48   ` Stanislaw Gruszka
2024-02-05 21:18 ` [PATCH v1 5/6] thermal: ACPI: Constify acpi_thermal_zone_ops Rafael J. Wysocki
2024-02-08  8:49   ` Stanislaw Gruszka
2024-02-05 21:20 ` [PATCH v1 6/6] thermal: intel: Adjust ops handling during thermal zone registration Rafael J. Wysocki
2024-02-08  8:51   ` Stanislaw Gruszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZcSPMRH34M5yG/IU@linux.intel.com \
    --to=stanislaw.gruszka@linux.intel.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=lukasz.luba@arm.com \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox