[11/11] thermal: Move thermal governor structure to internal header

Message ID 20191012065255.23249-11-daniel.lezcano@linaro.org
State New
Headers show
Series
  • [01/11] thermal: Move default governor config option to the internal header
Related show

Commit Message

Daniel Lezcano Oct. 12, 2019, 6:52 a.m.
The thermal governor structure is a big structure where no
user should change value inside except via helper functions.

Move the structure to the internal header thus preventing external
code to be tempted by hacking the structure's variables.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

---
 drivers/thermal/thermal_core.h | 20 ++++++++++++++++++++
 include/linux/thermal.h        | 21 +--------------------
 2 files changed, 21 insertions(+), 20 deletions(-)

-- 
2.17.1

Comments

Amit Kucheria Oct. 14, 2019, 2:32 p.m. | #1
On Sat, Oct 12, 2019 at 12:23 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>

> The thermal governor structure is a big structure where no

> user should change value inside except via helper functions.

>

> Move the structure to the internal header thus preventing external

> code to be tempted by hacking the structure's variables.

>

> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

> ---

>  drivers/thermal/thermal_core.h | 20 ++++++++++++++++++++

>  include/linux/thermal.h        | 21 +--------------------

>  2 files changed, 21 insertions(+), 20 deletions(-)

>

> diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h

> index c75309d858ce..e54150fa4c5b 100644

> --- a/drivers/thermal/thermal_core.h

> +++ b/drivers/thermal/thermal_core.h

> @@ -46,6 +46,26 @@ struct thermal_attr {

>         char name[THERMAL_NAME_LENGTH];

>  };

>

> +/**

> + * struct thermal_governor - structure that holds thermal governor information

> + * @name:      name of the governor

> + * @bind_to_tz: callback called when binding to a thermal zone.  If it

> + *             returns 0, the governor is bound to the thermal zone,

> + *             otherwise it fails.

> + * @unbind_from_tz:    callback called when a governor is unbound from a

> + *                     thermal zone.

> + * @throttle:  callback called for every trip point even if temperature is

> + *             below the trip point temperature

> + * @governor_list:     node in thermal_governor_list (in thermal_core.c)

> + */

> +struct thermal_governor {

> +       char name[THERMAL_NAME_LENGTH];

> +       int (*bind_to_tz)(struct thermal_zone_device *tz);

> +       void (*unbind_from_tz)(struct thermal_zone_device *tz);

> +       int (*throttle)(struct thermal_zone_device *tz, int trip);

> +       struct list_head        governor_list;

> +};

> +

>  static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)

>  {

>         return cdev->ops->get_requested_power && cdev->ops->state2power &&

> diff --git a/include/linux/thermal.h b/include/linux/thermal.h

> index 8daa179918a1..04264e8a2bce 100644

> --- a/include/linux/thermal.h

> +++ b/include/linux/thermal.h

> @@ -45,6 +45,7 @@

>

>  struct thermal_zone_device;

>  struct thermal_cooling_device;

> +struct thermal_governor;

>  struct thermal_instance;

>  struct thermal_attr;

>

> @@ -206,26 +207,6 @@ struct thermal_zone_device {

>         enum thermal_notify_event notify_event;

>  };

>

> -/**

> - * struct thermal_governor - structure that holds thermal governor information

> - * @name:      name of the governor


AFAICT, some drivers actually like to specify what governor to use
when calling thermal_zone_device_register(), by passing the
thermal_zone_params parameter. You will probably need to provide for
helper functions to return the value of governor name, I think.

> - * @bind_to_tz: callback called when binding to a thermal zone.  If it

> - *             returns 0, the governor is bound to the thermal zone,

> - *             otherwise it fails.

> - * @unbind_from_tz:    callback called when a governor is unbound from a

> - *                     thermal zone.

> - * @throttle:  callback called for every trip point even if temperature is

> - *             below the trip point temperature

> - * @governor_list:     node in thermal_governor_list (in thermal_core.c)

> - */

> -struct thermal_governor {

> -       char name[THERMAL_NAME_LENGTH];

> -       int (*bind_to_tz)(struct thermal_zone_device *tz);

> -       void (*unbind_from_tz)(struct thermal_zone_device *tz);

> -       int (*throttle)(struct thermal_zone_device *tz, int trip);

> -       struct list_head        governor_list;

> -};

> -

>  /* Structure that holds binding parameters for a zone */

>  struct thermal_bind_params {

>         struct thermal_cooling_device *cdev;

> --

> 2.17.1

>

Patch

diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index c75309d858ce..e54150fa4c5b 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -46,6 +46,26 @@  struct thermal_attr {
 	char name[THERMAL_NAME_LENGTH];
 };
 
+/**
+ * struct thermal_governor - structure that holds thermal governor information
+ * @name:	name of the governor
+ * @bind_to_tz: callback called when binding to a thermal zone.  If it
+ *		returns 0, the governor is bound to the thermal zone,
+ *		otherwise it fails.
+ * @unbind_from_tz:	callback called when a governor is unbound from a
+ *			thermal zone.
+ * @throttle:	callback called for every trip point even if temperature is
+ *		below the trip point temperature
+ * @governor_list:	node in thermal_governor_list (in thermal_core.c)
+ */
+struct thermal_governor {
+	char name[THERMAL_NAME_LENGTH];
+	int (*bind_to_tz)(struct thermal_zone_device *tz);
+	void (*unbind_from_tz)(struct thermal_zone_device *tz);
+	int (*throttle)(struct thermal_zone_device *tz, int trip);
+	struct list_head	governor_list;
+};
+
 static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
 {
 	return cdev->ops->get_requested_power && cdev->ops->state2power &&
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 8daa179918a1..04264e8a2bce 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -45,6 +45,7 @@ 
 
 struct thermal_zone_device;
 struct thermal_cooling_device;
+struct thermal_governor;
 struct thermal_instance;
 struct thermal_attr;
 
@@ -206,26 +207,6 @@  struct thermal_zone_device {
 	enum thermal_notify_event notify_event;
 };
 
-/**
- * struct thermal_governor - structure that holds thermal governor information
- * @name:	name of the governor
- * @bind_to_tz: callback called when binding to a thermal zone.  If it
- *		returns 0, the governor is bound to the thermal zone,
- *		otherwise it fails.
- * @unbind_from_tz:	callback called when a governor is unbound from a
- *			thermal zone.
- * @throttle:	callback called for every trip point even if temperature is
- *		below the trip point temperature
- * @governor_list:	node in thermal_governor_list (in thermal_core.c)
- */
-struct thermal_governor {
-	char name[THERMAL_NAME_LENGTH];
-	int (*bind_to_tz)(struct thermal_zone_device *tz);
-	void (*unbind_from_tz)(struct thermal_zone_device *tz);
-	int (*throttle)(struct thermal_zone_device *tz, int trip);
-	struct list_head	governor_list;
-};
-
 /* Structure that holds binding parameters for a zone */
 struct thermal_bind_params {
 	struct thermal_cooling_device *cdev;