thermal: netlink: Fix compilation error when CONFIG_NET=n

Message ID 20200707090159.1018-1-daniel.lezcano@linaro.org
State Accepted
Commit 5b8583d3bd7fc10cea07e4a5bfa59465758a39dc
Headers show
Series
  • thermal: netlink: Fix compilation error when CONFIG_NET=n
Related show

Commit Message

Daniel Lezcano July 7, 2020, 9:01 a.m.
When the network is not configured, the netlink are disabled on all
the system. The thermal framework assumed the netlink are always
opt-in.

Fix this by adding a Kconfig option for the netlink notification,
defaulting to yes and depending on CONFIG_NET.

As the change implies multiple stubs and in order to not pollute the
internal thermal header, the thermal_nelink.h has been added and
included in the thermal_core.h, so this one regain some kind of
clarity.

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

---
 drivers/thermal/Kconfig           | 10 ++++
 drivers/thermal/Makefile          |  5 +-
 drivers/thermal/thermal_core.h    | 20 +------
 drivers/thermal/thermal_netlink.h | 98 +++++++++++++++++++++++++++++++
 4 files changed, 114 insertions(+), 19 deletions(-)
 create mode 100644 drivers/thermal/thermal_netlink.h

-- 
2.17.1

Comments

Randy Dunlap July 7, 2020, 3:47 p.m. | #1
On 7/7/20 2:01 AM, Daniel Lezcano wrote:
> When the network is not configured, the netlink are disabled on all

> the system. The thermal framework assumed the netlink are always

> opt-in.

> 

> Fix this by adding a Kconfig option for the netlink notification,

> defaulting to yes and depending on CONFIG_NET.

> 

> As the change implies multiple stubs and in order to not pollute the

> internal thermal header, the thermal_nelink.h has been added and

> included in the thermal_core.h, so this one regain some kind of

> clarity.

> 

> Reported-by: Randy Dunlap <rdunlap@infradead.org>

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

> ---

>  drivers/thermal/Kconfig           | 10 ++++

>  drivers/thermal/Makefile          |  5 +-

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

>  drivers/thermal/thermal_netlink.h | 98 +++++++++++++++++++++++++++++++

>  4 files changed, 114 insertions(+), 19 deletions(-)

>  create mode 100644 drivers/thermal/thermal_netlink.h

> 



Hm, now I get this:

../drivers/thermal/thermal_helpers.c: In function ‘thermal_cdev_set_cur_state’:
../drivers/thermal/thermal_helpers.c:182:2: error: implicit declaration of function ‘thermal_notify_cdev_update’; did you mean ‘thermal_notify_cdev_delete’? [-Werror=implicit-function-declaration]
  thermal_notify_cdev_update(cdev->id, target);


or should that call be to thermal_notify_cdev_state_update()?


-- 
~Randy
Daniel Lezcano July 7, 2020, 3:49 p.m. | #2
On 07/07/2020 17:47, Randy Dunlap wrote:
> On 7/7/20 2:01 AM, Daniel Lezcano wrote:

>> When the network is not configured, the netlink are disabled on all

>> the system. The thermal framework assumed the netlink are always

>> opt-in.

>>

>> Fix this by adding a Kconfig option for the netlink notification,

>> defaulting to yes and depending on CONFIG_NET.

>>

>> As the change implies multiple stubs and in order to not pollute the

>> internal thermal header, the thermal_nelink.h has been added and

>> included in the thermal_core.h, so this one regain some kind of

>> clarity.

>>

>> Reported-by: Randy Dunlap <rdunlap@infradead.org>

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

>> ---

>>  drivers/thermal/Kconfig           | 10 ++++

>>  drivers/thermal/Makefile          |  5 +-

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

>>  drivers/thermal/thermal_netlink.h | 98 +++++++++++++++++++++++++++++++

>>  4 files changed, 114 insertions(+), 19 deletions(-)

>>  create mode 100644 drivers/thermal/thermal_netlink.h

>>

> 

> 

> Hm, now I get this:

> 

> ../drivers/thermal/thermal_helpers.c: In function ‘thermal_cdev_set_cur_state’:

> ../drivers/thermal/thermal_helpers.c:182:2: error: implicit declaration of function ‘thermal_notify_cdev_update’; did you mean ‘thermal_notify_cdev_delete’? [-Werror=implicit-function-declaration]

>   thermal_notify_cdev_update(cdev->id, target);

> 

> 

> or should that call be to thermal_notify_cdev_state_update()?


Ah right, the patch applies on top of the v4 which is not yet in
linux-next, I'm waiting for the kernelci loop result.


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Randy Dunlap July 7, 2020, 3:50 p.m. | #3
On 7/7/20 8:49 AM, Daniel Lezcano wrote:
> On 07/07/2020 17:47, Randy Dunlap wrote:

>> On 7/7/20 2:01 AM, Daniel Lezcano wrote:

>>> When the network is not configured, the netlink are disabled on all

>>> the system. The thermal framework assumed the netlink are always

>>> opt-in.

>>>

>>> Fix this by adding a Kconfig option for the netlink notification,

>>> defaulting to yes and depending on CONFIG_NET.

>>>

>>> As the change implies multiple stubs and in order to not pollute the

>>> internal thermal header, the thermal_nelink.h has been added and

>>> included in the thermal_core.h, so this one regain some kind of

>>> clarity.

>>>

>>> Reported-by: Randy Dunlap <rdunlap@infradead.org>

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

>>> ---

>>>  drivers/thermal/Kconfig           | 10 ++++

>>>  drivers/thermal/Makefile          |  5 +-

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

>>>  drivers/thermal/thermal_netlink.h | 98 +++++++++++++++++++++++++++++++

>>>  4 files changed, 114 insertions(+), 19 deletions(-)

>>>  create mode 100644 drivers/thermal/thermal_netlink.h

>>>

>>

>>

>> Hm, now I get this:

>>

>> ../drivers/thermal/thermal_helpers.c: In function ‘thermal_cdev_set_cur_state’:

>> ../drivers/thermal/thermal_helpers.c:182:2: error: implicit declaration of function ‘thermal_notify_cdev_update’; did you mean ‘thermal_notify_cdev_delete’? [-Werror=implicit-function-declaration]

>>   thermal_notify_cdev_update(cdev->id, target);

>>

>>

>> or should that call be to thermal_notify_cdev_state_update()?

> 

> Ah right, the patch applies on top of the v4 which is not yet in

> linux-next, I'm waiting for the kernelci loop result.


OK, that explains why I had a little trouble applying the patch.

thanks.
-- 
~Randy
Amit Kucheria July 21, 2020, 7:33 a.m. | #4
On Tue, Jul 7, 2020 at 2:32 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>

> When the network is not configured, the netlink are disabled on all

> the system. The thermal framework assumed the netlink are always


nit: s/are/is/ in both places above

> opt-in.

>

> Fix this by adding a Kconfig option for the netlink notification,

> defaulting to yes and depending on CONFIG_NET.

>

> As the change implies multiple stubs and in order to not pollute the

> internal thermal header, the thermal_nelink.h has been added and

> included in the thermal_core.h, so this one regain some kind of

> clarity.

>

> Reported-by: Randy Dunlap <rdunlap@infradead.org>

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


Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>


> ---

>  drivers/thermal/Kconfig           | 10 ++++

>  drivers/thermal/Makefile          |  5 +-

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

>  drivers/thermal/thermal_netlink.h | 98 +++++++++++++++++++++++++++++++

>  4 files changed, 114 insertions(+), 19 deletions(-)

>  create mode 100644 drivers/thermal/thermal_netlink.h

>

> diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig

> index 3eb2348e5242..07983bef8d6a 100644

> --- a/drivers/thermal/Kconfig

> +++ b/drivers/thermal/Kconfig

> @@ -17,6 +17,16 @@ menuconfig THERMAL

>

>  if THERMAL

>

> +config THERMAL_NETLINK

> +       bool "Thermal netlink management"

> +       depends on NET

> +       default y

> +       help

> +         The thermal framework has a netlink interface to do thermal

> +         zones discovery, temperature readings and events such as

> +         trip point crossed, cooling device update or governor

> +         change. It is recommended to enable the feature.

> +

>  config THERMAL_STATISTICS

>         bool "Thermal state transition statistics"

>         help

> diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile

> index 1bbf0805fb04..589f6fb0d381 100644

> --- a/drivers/thermal/Makefile

> +++ b/drivers/thermal/Makefile

> @@ -5,7 +5,10 @@

>

>  obj-$(CONFIG_THERMAL)          += thermal_sys.o

>  thermal_sys-y                  += thermal_core.o thermal_sysfs.o \

> -                                       thermal_helpers.o thermal_netlink.o

> +                                       thermal_helpers.o

> +

> +# netlink interface to manage the thermal framework

> +thermal_sys-$(CONFIG_THERMAL_NETLINK)          += thermal_netlink.o

>

>  # interface to/from other layers providing sensors

>  thermal_sys-$(CONFIG_THERMAL_HWMON)            += thermal_hwmon.o

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

> index b44969d50ec0..99d065e6ed08 100644

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

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

> @@ -12,6 +12,8 @@

>  #include <linux/device.h>

>  #include <linux/thermal.h>

>

> +#include "thermal_netlink.h"

> +

>  /* Default Thermal Governor */

>  #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)

>  #define DEFAULT_THERMAL_GOVERNOR       "step_wise"

> @@ -52,24 +54,6 @@ int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),

>

>  struct thermal_zone_device *thermal_zone_get_by_id(int id);

>

> -/* Netlink notification function */

> -int thermal_notify_tz_create(int tz_id, const char *name);

> -int thermal_notify_tz_delete(int tz_id);

> -int thermal_notify_tz_enable(int tz_id);

> -int thermal_notify_tz_disable(int tz_id);

> -int thermal_notify_tz_trip_down(int tz_id, int id);

> -int thermal_notify_tz_trip_up(int tz_id, int id);

> -int thermal_notify_tz_trip_delete(int tz_id, int id);

> -int thermal_notify_tz_trip_add(int tz_id, int id, int type,

> -                              int temp, int hyst);

> -int thermal_notify_tz_trip_change(int tz_id, int id, int type,

> -                                 int temp, int hyst);

> -int thermal_notify_cdev_state_update(int cdev_id, int state);

> -int thermal_notify_cdev_add(int cdev_id, const char *name, int max_state);

> -int thermal_notify_cdev_delete(int cdev_id);

> -int thermal_notify_tz_gov_change(int tz_id, const char *name);

> -int thermal_genl_sampling_temp(int id, int temp);

> -

>  struct thermal_attr {

>         struct device_attribute attr;

>         char name[THERMAL_NAME_LENGTH];

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

> new file mode 100644

> index 000000000000..0ec28d105da5

> --- /dev/null

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

> @@ -0,0 +1,98 @@

> +/* SPDX-License-Identifier: GPL-2.0 */

> +/*

> + *  Copyright (C) Linaro Ltd 2020

> + *  Author: Daniel Lezcano <daniel.lezcano@linaro.org>

> + */

> +

> +/* Netlink notification function */

> +#ifdef CONFIG_THERMAL_NETLINK

> +int thermal_notify_tz_create(int tz_id, const char *name);

> +int thermal_notify_tz_delete(int tz_id);

> +int thermal_notify_tz_enable(int tz_id);

> +int thermal_notify_tz_disable(int tz_id);

> +int thermal_notify_tz_trip_down(int tz_id, int id);

> +int thermal_notify_tz_trip_up(int tz_id, int id);

> +int thermal_notify_tz_trip_delete(int tz_id, int id);

> +int thermal_notify_tz_trip_add(int tz_id, int id, int type,

> +                              int temp, int hyst);

> +int thermal_notify_tz_trip_change(int tz_id, int id, int type,

> +                                 int temp, int hyst);

> +int thermal_notify_cdev_state_update(int cdev_id, int state);

> +int thermal_notify_cdev_add(int cdev_id, const char *name, int max_state);

> +int thermal_notify_cdev_delete(int cdev_id);

> +int thermal_notify_tz_gov_change(int tz_id, const char *name);

> +int thermal_genl_sampling_temp(int id, int temp);

> +#else

> +static inline int thermal_notify_tz_create(int tz_id, const char *name)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_delete(int tz_id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_enable(int tz_id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_disable(int tz_id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_trip_down(int tz_id, int id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_trip_up(int tz_id, int id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_trip_delete(int tz_id, int id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_trip_add(int tz_id, int id, int type,

> +                                            int temp, int hyst)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_trip_change(int tz_id, int id, int type,

> +                                               int temp, int hyst)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_cdev_state_update(int cdev_id, int state)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_cdev_add(int cdev_id, const char *name,

> +                                         int max_state)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_cdev_delete(int cdev_id)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_notify_tz_gov_change(int tz_id, const char *name)

> +{

> +       return 0;

> +}

> +

> +static inline int thermal_genl_sampling_temp(int id, int temp)

> +{

> +       return 0;

> +}

> +#endif /* CONFIG_THERMAL_NETLINK */

> --

> 2.17.1

>

Patch

diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 3eb2348e5242..07983bef8d6a 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -17,6 +17,16 @@  menuconfig THERMAL
 
 if THERMAL
 
+config THERMAL_NETLINK
+	bool "Thermal netlink management"
+	depends on NET
+	default y
+	help
+	  The thermal framework has a netlink interface to do thermal
+	  zones discovery, temperature readings and events such as
+	  trip point crossed, cooling device update or governor
+	  change. It is recommended to enable the feature.
+
 config THERMAL_STATISTICS
 	bool "Thermal state transition statistics"
 	help
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 1bbf0805fb04..589f6fb0d381 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -5,7 +5,10 @@ 
 
 obj-$(CONFIG_THERMAL)		+= thermal_sys.o
 thermal_sys-y			+= thermal_core.o thermal_sysfs.o \
-					thermal_helpers.o thermal_netlink.o
+					thermal_helpers.o
+
+# netlink interface to manage the thermal framework
+thermal_sys-$(CONFIG_THERMAL_NETLINK)		+= thermal_netlink.o
 
 # interface to/from other layers providing sensors
 thermal_sys-$(CONFIG_THERMAL_HWMON)		+= thermal_hwmon.o
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index b44969d50ec0..99d065e6ed08 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -12,6 +12,8 @@ 
 #include <linux/device.h>
 #include <linux/thermal.h>
 
+#include "thermal_netlink.h"
+
 /* Default Thermal Governor */
 #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
 #define DEFAULT_THERMAL_GOVERNOR       "step_wise"
@@ -52,24 +54,6 @@  int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
 
 struct thermal_zone_device *thermal_zone_get_by_id(int id);
 
-/* Netlink notification function */
-int thermal_notify_tz_create(int tz_id, const char *name);
-int thermal_notify_tz_delete(int tz_id);
-int thermal_notify_tz_enable(int tz_id);
-int thermal_notify_tz_disable(int tz_id);
-int thermal_notify_tz_trip_down(int tz_id, int id);
-int thermal_notify_tz_trip_up(int tz_id, int id);
-int thermal_notify_tz_trip_delete(int tz_id, int id);
-int thermal_notify_tz_trip_add(int tz_id, int id, int type,
-			       int temp, int hyst);
-int thermal_notify_tz_trip_change(int tz_id, int id, int type,
-				  int temp, int hyst);
-int thermal_notify_cdev_state_update(int cdev_id, int state);
-int thermal_notify_cdev_add(int cdev_id, const char *name, int max_state);
-int thermal_notify_cdev_delete(int cdev_id);
-int thermal_notify_tz_gov_change(int tz_id, const char *name);
-int thermal_genl_sampling_temp(int id, int temp);
-
 struct thermal_attr {
 	struct device_attribute attr;
 	char name[THERMAL_NAME_LENGTH];
diff --git a/drivers/thermal/thermal_netlink.h b/drivers/thermal/thermal_netlink.h
new file mode 100644
index 000000000000..0ec28d105da5
--- /dev/null
+++ b/drivers/thermal/thermal_netlink.h
@@ -0,0 +1,98 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ *  Copyright (C) Linaro Ltd 2020
+ *  Author: Daniel Lezcano <daniel.lezcano@linaro.org>
+ */
+
+/* Netlink notification function */
+#ifdef CONFIG_THERMAL_NETLINK
+int thermal_notify_tz_create(int tz_id, const char *name);
+int thermal_notify_tz_delete(int tz_id);
+int thermal_notify_tz_enable(int tz_id);
+int thermal_notify_tz_disable(int tz_id);
+int thermal_notify_tz_trip_down(int tz_id, int id);
+int thermal_notify_tz_trip_up(int tz_id, int id);
+int thermal_notify_tz_trip_delete(int tz_id, int id);
+int thermal_notify_tz_trip_add(int tz_id, int id, int type,
+			       int temp, int hyst);
+int thermal_notify_tz_trip_change(int tz_id, int id, int type,
+				  int temp, int hyst);
+int thermal_notify_cdev_state_update(int cdev_id, int state);
+int thermal_notify_cdev_add(int cdev_id, const char *name, int max_state);
+int thermal_notify_cdev_delete(int cdev_id);
+int thermal_notify_tz_gov_change(int tz_id, const char *name);
+int thermal_genl_sampling_temp(int id, int temp);
+#else
+static inline int thermal_notify_tz_create(int tz_id, const char *name)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_delete(int tz_id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_enable(int tz_id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_disable(int tz_id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_trip_down(int tz_id, int id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_trip_up(int tz_id, int id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_trip_delete(int tz_id, int id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_trip_add(int tz_id, int id, int type,
+					     int temp, int hyst)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_trip_change(int tz_id, int id, int type,
+						int temp, int hyst)
+{
+	return 0;
+}
+
+static inline int thermal_notify_cdev_state_update(int cdev_id, int state)
+{
+	return 0;
+}
+
+static inline int thermal_notify_cdev_add(int cdev_id, const char *name,
+					  int max_state)
+{
+	return 0;
+}
+
+static inline int thermal_notify_cdev_delete(int cdev_id)
+{
+	return 0;
+}
+
+static inline int thermal_notify_tz_gov_change(int tz_id, const char *name)
+{
+	return 0;
+}
+
+static inline int thermal_genl_sampling_temp(int id, int temp)
+{
+	return 0;
+}
+#endif /* CONFIG_THERMAL_NETLINK */