mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks
@ 2026-07-11  9:59 Thomas Weißschuh
  2026-07-11  9:59 ` [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones Thomas Weißschuh
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-07-11  9:59 UTC (permalink / raw)
  To: Guenter Roeck, Benson Leung
  Cc: Sung-Chi Li, Guenter Roeck, chrome-platform, linux-hwmon,
	linux-kernel, Thomas Weißschuh

To guarantee consistency for the read-modify-write access in
cros_ec_hwmon_cooling_set_cur_state(), locking is necessary.

Use the existing hwmon device lock to do so.

Sung-Chi: Could you test this? I do not have access to hardware which
triggers this code path.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (3):
      hwmon: (cros_ec) Register the thermal devices after the hwmon ones
      hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv
      hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks

 drivers/hwmon/cros_ec_hwmon.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
---
base-commit: ca078d004cf58137bcf8cb24a8b271397431ba58
change-id: 20260630-cros_ec-hwmon-locking-d32263db1c94

Best regards,
--  
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones
  2026-07-11  9:59 [PATCH 0/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
@ 2026-07-11  9:59 ` Thomas Weißschuh
  2026-07-19 14:34   ` Guenter Roeck
  2026-07-11  9:59 ` [PATCH 2/3] hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv Thomas Weißschuh
  2026-07-11  9:59 ` [PATCH 3/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
  2 siblings, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2026-07-11  9:59 UTC (permalink / raw)
  To: Guenter Roeck, Benson Leung
  Cc: Sung-Chi Li, Guenter Roeck, chrome-platform, linux-hwmon,
	linux-kernel, Thomas Weißschuh

To guarantee consistency for the read-modify-write access in
cros_ec_hwmon_cooling_set_cur_state(), locking is necessary.
The locking will use standard hwmon device locks, which requires
the hwmon device to be ready before the fan devices are set up.

Reorder the initialization so this works.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/hwmon/cros_ec_hwmon.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
index 44291799dd8e..f9b19da50472 100644
--- a/drivers/hwmon/cros_ec_hwmon.c
+++ b/drivers/hwmon/cros_ec_hwmon.c
@@ -579,13 +579,17 @@ static int cros_ec_hwmon_probe(struct platform_device *pdev)
 	priv->fan_control_supported = cros_ec_hwmon_probe_fan_control_supported(priv->cros_ec);
 	priv->temp_threshold_supported = is_cros_ec_cmd_available(priv->cros_ec,
 								  EC_CMD_THERMAL_GET_THRESHOLD, 1);
-	cros_ec_hwmon_register_fan_cooling_devices(dev, priv);
 
 	hwmon_dev = devm_hwmon_device_register_with_info(dev, "cros_ec", priv,
 							 &cros_ec_hwmon_chip_info, NULL);
+	if (IS_ERR(hwmon_dev))
+		return PTR_ERR(hwmon_dev);
+
+	cros_ec_hwmon_register_fan_cooling_devices(dev, priv);
+
 	platform_set_drvdata(pdev, priv);
 
-	return PTR_ERR_OR_ZERO(hwmon_dev);
+	return 0;
 }
 
 static int cros_ec_hwmon_suspend(struct platform_device *pdev, pm_message_t state)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/3] hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv
  2026-07-11  9:59 [PATCH 0/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
  2026-07-11  9:59 ` [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones Thomas Weißschuh
@ 2026-07-11  9:59 ` Thomas Weißschuh
  2026-07-19 14:35   ` Guenter Roeck
  2026-07-11  9:59 ` [PATCH 3/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
  2 siblings, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2026-07-11  9:59 UTC (permalink / raw)
  To: Guenter Roeck, Benson Leung
  Cc: Sung-Chi Li, Guenter Roeck, chrome-platform, linux-hwmon,
	linux-kernel, Thomas Weißschuh

The upcoming locking scheme for thermal devices will require access
to the hwmon device.

Add it do the priv struct.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/hwmon/cros_ec_hwmon.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
index f9b19da50472..fb5daa9f80d1 100644
--- a/drivers/hwmon/cros_ec_hwmon.c
+++ b/drivers/hwmon/cros_ec_hwmon.c
@@ -25,6 +25,7 @@
 
 struct cros_ec_hwmon_priv {
 	struct cros_ec_device *cros_ec;
+	struct device *hwmon_dev;
 	const char *temp_sensor_names[EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES];
 	u8 usable_fans;
 	bool fan_control_supported;
@@ -556,7 +557,6 @@ static int cros_ec_hwmon_probe(struct platform_device *pdev)
 	struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
 	struct cros_ec_device *cros_ec = ec_dev->ec_dev;
 	struct cros_ec_hwmon_priv *priv;
-	struct device *hwmon_dev;
 	u8 thermal_version;
 	int ret;
 
@@ -580,10 +580,10 @@ static int cros_ec_hwmon_probe(struct platform_device *pdev)
 	priv->temp_threshold_supported = is_cros_ec_cmd_available(priv->cros_ec,
 								  EC_CMD_THERMAL_GET_THRESHOLD, 1);
 
-	hwmon_dev = devm_hwmon_device_register_with_info(dev, "cros_ec", priv,
-							 &cros_ec_hwmon_chip_info, NULL);
-	if (IS_ERR(hwmon_dev))
-		return PTR_ERR(hwmon_dev);
+	priv->hwmon_dev = devm_hwmon_device_register_with_info(dev, "cros_ec", priv,
+							       &cros_ec_hwmon_chip_info, NULL);
+	if (IS_ERR(priv->hwmon_dev))
+		return PTR_ERR(priv->hwmon_dev);
 
 	cros_ec_hwmon_register_fan_cooling_devices(dev, priv);
 

-- 
2.55.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks
  2026-07-11  9:59 [PATCH 0/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
  2026-07-11  9:59 ` [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones Thomas Weißschuh
  2026-07-11  9:59 ` [PATCH 2/3] hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv Thomas Weißschuh
@ 2026-07-11  9:59 ` Thomas Weißschuh
  2026-07-19 14:35   ` Guenter Roeck
  2 siblings, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2026-07-11  9:59 UTC (permalink / raw)
  To: Guenter Roeck, Benson Leung
  Cc: Sung-Chi Li, Guenter Roeck, chrome-platform, linux-hwmon,
	linux-kernel, Thomas Weißschuh

To guarantee consistency for the read-modify-write access in
cros_ec_hwmon_cooling_set_cur_state(), locking is necessary.

Use the existing hwmon device lock to do so.

Fixes: 5798b62867b4 ("hwmon: (cros_ec) register fans into thermal framework cooling devices")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/hwmon/cros_ec_hwmon.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
index fb5daa9f80d1..76d83e1c68cf 100644
--- a/drivers/hwmon/cros_ec_hwmon.c
+++ b/drivers/hwmon/cros_ec_hwmon.c
@@ -5,6 +5,7 @@
  *  Copyright (C) 2024 Thomas Weißschuh <linux@weissschuh.net>
  */
 
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/hwmon.h>
 #include <linux/math.h>
@@ -411,6 +412,8 @@ static int cros_ec_hwmon_cooling_get_cur_state(struct thermal_cooling_device *cd
 	u8 read_val;
 	int ret;
 
+	guard(hwmon_lock)(priv->hwmon_priv->hwmon_dev);
+
 	ret = cros_ec_hwmon_read_pwm_value(priv->hwmon_priv->cros_ec, priv->index, &read_val);
 	if (ret)
 		return ret;
@@ -424,6 +427,8 @@ static int cros_ec_hwmon_cooling_set_cur_state(struct thermal_cooling_device *cd
 {
 	const struct cros_ec_hwmon_cooling_priv *priv = cdev->devdata;
 
+	guard(hwmon_lock)(priv->hwmon_priv->hwmon_dev);
+
 	return cros_ec_hwmon_write_pwm_input(priv->hwmon_priv->cros_ec, priv->index, val);
 }
 

-- 
2.55.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones
  2026-07-11  9:59 ` [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones Thomas Weißschuh
@ 2026-07-19 14:34   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-07-19 14:34 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Benson Leung, Sung-Chi Li, Guenter Roeck, chrome-platform,
	linux-hwmon, linux-kernel

On Sat, Jul 11, 2026 at 11:59:05AM +0200, Thomas Weißschuh wrote:
> To guarantee consistency for the read-modify-write access in
> cros_ec_hwmon_cooling_set_cur_state(), locking is necessary.
> The locking will use standard hwmon device locks, which requires
> the hwmon device to be ready before the fan devices are set up.
> 
> Reorder the initialization so this works.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Applied.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv
  2026-07-11  9:59 ` [PATCH 2/3] hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv Thomas Weißschuh
@ 2026-07-19 14:35   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-07-19 14:35 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Benson Leung, Sung-Chi Li, Guenter Roeck, chrome-platform,
	linux-hwmon, linux-kernel

On Sat, Jul 11, 2026 at 11:59:06AM +0200, Thomas Weißschuh wrote:
> The upcoming locking scheme for thermal devices will require access
> to the hwmon device.
> 
> Add it do the priv struct.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/cros_ec_hwmon.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
> index f9b19da50472..fb5daa9f80d1 100644
> --- a/drivers/hwmon/cros_ec_hwmon.c
> +++ b/drivers/hwmon/cros_ec_hwmon.c
> @@ -25,6 +25,7 @@
>  
>  struct cros_ec_hwmon_priv {
>  	struct cros_ec_device *cros_ec;
> +	struct device *hwmon_dev;
>  	const char *temp_sensor_names[EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES];
>  	u8 usable_fans;
>  	bool fan_control_supported;
> @@ -556,7 +557,6 @@ static int cros_ec_hwmon_probe(struct platform_device *pdev)
>  	struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
>  	struct cros_ec_device *cros_ec = ec_dev->ec_dev;
>  	struct cros_ec_hwmon_priv *priv;
> -	struct device *hwmon_dev;
>  	u8 thermal_version;
>  	int ret;
>  
> @@ -580,10 +580,10 @@ static int cros_ec_hwmon_probe(struct platform_device *pdev)
>  	priv->temp_threshold_supported = is_cros_ec_cmd_available(priv->cros_ec,
>  								  EC_CMD_THERMAL_GET_THRESHOLD, 1);
>  
> -	hwmon_dev = devm_hwmon_device_register_with_info(dev, "cros_ec", priv,
> -							 &cros_ec_hwmon_chip_info, NULL);
> -	if (IS_ERR(hwmon_dev))
> -		return PTR_ERR(hwmon_dev);
> +	priv->hwmon_dev = devm_hwmon_device_register_with_info(dev, "cros_ec", priv,
> +							       &cros_ec_hwmon_chip_info, NULL);
> +	if (IS_ERR(priv->hwmon_dev))
> +		return PTR_ERR(priv->hwmon_dev);
>  
>  	cros_ec_hwmon_register_fan_cooling_devices(dev, priv);
>  

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks
  2026-07-11  9:59 ` [PATCH 3/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
@ 2026-07-19 14:35   ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2026-07-19 14:35 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Benson Leung, Sung-Chi Li, Guenter Roeck, chrome-platform,
	linux-hwmon, linux-kernel

On Sat, Jul 11, 2026 at 11:59:07AM +0200, Thomas Weißschuh wrote:
> To guarantee consistency for the read-modify-write access in
> cros_ec_hwmon_cooling_set_cur_state(), locking is necessary.
> 
> Use the existing hwmon device lock to do so.
> 
> Fixes: 5798b62867b4 ("hwmon: (cros_ec) register fans into thermal framework cooling devices")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Applied.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-19 14:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-11  9:59 [PATCH 0/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
2026-07-11  9:59 ` [PATCH 1/3] hwmon: (cros_ec) Register the thermal devices after the hwmon ones Thomas Weißschuh
2026-07-19 14:34   ` Guenter Roeck
2026-07-11  9:59 ` [PATCH 2/3] hwmon: (cros_ec) Store the hwmon device in cros_ec_hwmon_priv Thomas Weißschuh
2026-07-19 14:35   ` Guenter Roeck
2026-07-11  9:59 ` [PATCH 3/3] hwmon: (cros_ec) Synchronize EC access from the thermal device callbacks Thomas Weißschuh
2026-07-19 14:35   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®