* [PATCH v3 0/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file
@ 2024-11-18 6:15 Thomas Weißschuh
2024-11-18 6:15 ` [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update() Thomas Weißschuh
2024-11-18 6:15 ` [PATCH v3 2/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
0 siblings, 2 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-11-18 6:15 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Lukasz Luba
Cc: linux-hwmon, linux-kernel, linux-pm, Thomas Weißschuh
Replace some confusing ifdeffery with IS_ENABLED() conditionals.
The ifdefs confused me while looking at the implementation of
HWMON_C_REGISTER_TZ.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v3:
- Fix warning "omitting the parameter name in a function definition is a C23 extension [-Werror,-Wc23-extensions]"
- Link to v2: https://lore.kernel.org/r/20241115-hwmon-thermal-v2-0-c96f0c0984b2@weissschuh.net
Changes in v2:
- Add stub for thermal_zone_device_update()
- Link to v1: https://lore.kernel.org/r/20241113-hwmon-thermal-v1-1-71270be7f7a2@weissschuh.net
---
Thomas Weißschuh (2):
thermal: core: Add stub for thermal_zone_device_update()
hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file
drivers/hwmon/hwmon.c | 21 ++++++---------------
include/linux/thermal.h | 4 ++++
2 files changed, 10 insertions(+), 15 deletions(-)
---
base-commit: f66d6acccbc08b4146f4c2cf9445241f70f5517d
change-id: 20241113-hwmon-thermal-2d2da581c276
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update()
2024-11-18 6:15 [PATCH v3 0/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
@ 2024-11-18 6:15 ` Thomas Weißschuh
2024-11-25 14:12 ` Rafael J. Wysocki
2024-11-25 17:09 ` Guenter Roeck
2024-11-18 6:15 ` [PATCH v3 2/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
1 sibling, 2 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-11-18 6:15 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Lukasz Luba
Cc: linux-hwmon, linux-kernel, linux-pm, Thomas Weißschuh
To simplify the !CONFIG_THERMAL case in the hwmon core,
add a !CONFIG_THERMAL stub for thermal_zone_device_update().
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
include/linux/thermal.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 25ea8fe2313e6d0a53192974a80d92f50f0ff03e..455e0814b9165dbb96d698e670f160136a017cc4 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -289,6 +289,10 @@ static inline struct thermal_zone_device *thermal_tripless_zone_device_register(
static inline void thermal_zone_device_unregister(struct thermal_zone_device *tz)
{ }
+static inline void thermal_zone_device_update(struct thermal_zone_device *tz,
+ enum thermal_notify_event event)
+{ }
+
static inline struct thermal_cooling_device *
thermal_cooling_device_register(const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops)
--
2.47.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file
2024-11-18 6:15 [PATCH v3 0/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
2024-11-18 6:15 ` [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update() Thomas Weißschuh
@ 2024-11-18 6:15 ` Thomas Weißschuh
2024-11-25 17:09 ` Guenter Roeck
1 sibling, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2024-11-18 6:15 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Lukasz Luba
Cc: linux-hwmon, linux-kernel, linux-pm, Thomas Weißschuh
Using an #ifdef in a C source files to have different definitions
of the same symbol makes the code harder to read and understand.
Furthermore it makes it harder to test compilation of the different
branches.
Replace the ifdeffery with IS_ENABLED() which is just a normal
conditional.
The resulting binary is still the same as before as the compiler
optimizes away all the unused code and definitions.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/hwmon.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 9c35c4d0369d7aad7ea61ccd25f4f63fc98b9e02..86fb674c85d3f54d475be014c3fd3dd74c815c57 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -147,11 +147,6 @@ static DEFINE_IDA(hwmon_ida);
/* Thermal zone handling */
-/*
- * The complex conditional is necessary to avoid a cyclic dependency
- * between hwmon and thermal_sys modules.
- */
-#ifdef CONFIG_THERMAL_OF
static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
{
struct hwmon_thermal_data *tdata = thermal_zone_device_priv(tz);
@@ -257,6 +252,9 @@ static int hwmon_thermal_register_sensors(struct device *dev)
void *drvdata = dev_get_drvdata(dev);
int i;
+ if (!IS_ENABLED(CONFIG_THERMAL_OF))
+ return 0;
+
for (i = 1; info[i]; i++) {
int j;
@@ -285,6 +283,9 @@ static void hwmon_thermal_notify(struct device *dev, int index)
struct hwmon_device *hwdev = to_hwmon_device(dev);
struct hwmon_thermal_data *tzdata;
+ if (!IS_ENABLED(CONFIG_THERMAL_OF))
+ return;
+
list_for_each_entry(tzdata, &hwdev->tzdata, node) {
if (tzdata->index == index) {
thermal_zone_device_update(tzdata->tzd,
@@ -293,16 +294,6 @@ static void hwmon_thermal_notify(struct device *dev, int index)
}
}
-#else
-static int hwmon_thermal_register_sensors(struct device *dev)
-{
- return 0;
-}
-
-static void hwmon_thermal_notify(struct device *dev, int index) { }
-
-#endif /* IS_REACHABLE(CONFIG_THERMAL) && ... */
-
static int hwmon_attr_base(enum hwmon_sensor_types type)
{
if (type == hwmon_in || type == hwmon_intrusion)
--
2.47.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update()
2024-11-18 6:15 ` [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update() Thomas Weißschuh
@ 2024-11-25 14:12 ` Rafael J. Wysocki
2024-11-25 17:09 ` Guenter Roeck
1 sibling, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2024-11-25 14:12 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Jean Delvare, Guenter Roeck, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Lukasz Luba, linux-hwmon, linux-kernel, linux-pm
On Mon, Nov 18, 2024 at 7:16 AM Thomas Weißschuh <linux@weissschuh.net> wrote:
>
> To simplify the !CONFIG_THERMAL case in the hwmon core,
> add a !CONFIG_THERMAL stub for thermal_zone_device_update().
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
and please route it through hwmon.
> ---
> include/linux/thermal.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 25ea8fe2313e6d0a53192974a80d92f50f0ff03e..455e0814b9165dbb96d698e670f160136a017cc4 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -289,6 +289,10 @@ static inline struct thermal_zone_device *thermal_tripless_zone_device_register(
> static inline void thermal_zone_device_unregister(struct thermal_zone_device *tz)
> { }
>
> +static inline void thermal_zone_device_update(struct thermal_zone_device *tz,
> + enum thermal_notify_event event)
> +{ }
> +
> static inline struct thermal_cooling_device *
> thermal_cooling_device_register(const char *type, void *devdata,
> const struct thermal_cooling_device_ops *ops)
>
> --
> 2.47.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update()
2024-11-18 6:15 ` [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update() Thomas Weißschuh
2024-11-25 14:12 ` Rafael J. Wysocki
@ 2024-11-25 17:09 ` Guenter Roeck
1 sibling, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2024-11-25 17:09 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Jean Delvare, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba, linux-hwmon, linux-kernel, linux-pm
On Mon, Nov 18, 2024 at 07:15:58AM +0100, Thomas Weißschuh wrote:
> To simplify the !CONFIG_THERMAL case in the hwmon core,
> add a !CONFIG_THERMAL stub for thermal_zone_device_update().
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file
2024-11-18 6:15 ` [PATCH v3 2/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
@ 2024-11-25 17:09 ` Guenter Roeck
0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2024-11-25 17:09 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Jean Delvare, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Lukasz Luba, linux-hwmon, linux-kernel, linux-pm
On Mon, Nov 18, 2024 at 07:15:59AM +0100, Thomas Weißschuh wrote:
> Using an #ifdef in a C source files to have different definitions
> of the same symbol makes the code harder to read and understand.
> Furthermore it makes it harder to test compilation of the different
> branches.
>
> Replace the ifdeffery with IS_ENABLED() which is just a normal
> conditional.
> The resulting binary is still the same as before as the compiler
> optimizes away all the unused code and definitions.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-11-25 17:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-18 6:15 [PATCH v3 0/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
2024-11-18 6:15 ` [PATCH v3 1/2] thermal: core: Add stub for thermal_zone_device_update() Thomas Weißschuh
2024-11-25 14:12 ` Rafael J. Wysocki
2024-11-25 17:09 ` Guenter Roeck
2024-11-18 6:15 ` [PATCH v3 2/2] hwmon: (core) Avoid ifdef CONFIG_THERMAL in C source file Thomas Weißschuh
2024-11-25 17:09 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox