Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 07/29] hwmon: (sht4x) Rely on subsystem locking
Date: Fri, 17 Oct 2025 06:01:59 -0700	[thread overview]
Message-ID: <20251017130221.1823453-8-linux@roeck-us.net> (raw)
In-Reply-To: <20251017130221.1823453-1-linux@roeck-us.net>

Attribute access is now serialized in the hardware monitoring core,
so locking in the driver code is no longer necessary. Drop it.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/sht4x.c | 40 +++++++++++-----------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/drivers/hwmon/sht4x.c b/drivers/hwmon/sht4x.c
index 6c9b776237c2..5abe1227e109 100644
--- a/drivers/hwmon/sht4x.c
+++ b/drivers/hwmon/sht4x.c
@@ -55,7 +55,6 @@ DECLARE_CRC8_TABLE(sht4x_crc8_table);
 /**
  * struct sht4x_data - All the data required to operate an SHT4X chip
  * @client: the i2c client associated with the SHT4X
- * @lock: a mutex that is used to prevent parallel access to the i2c client
  * @heating_complete: the time that the last heating finished
  * @data_pending: true if and only if there are measurements to retrieve after heating
  * @heater_power: the power at which the heater will be started
@@ -68,7 +67,6 @@ DECLARE_CRC8_TABLE(sht4x_crc8_table);
  */
 struct sht4x_data {
 	struct i2c_client	*client;
-	struct mutex		lock;	/* atomic read data updates */
 	unsigned long		heating_complete;	/* in jiffies */
 	bool			data_pending;
 	u32			heater_power;	/* in milli-watts */
@@ -87,7 +85,7 @@ struct sht4x_data {
  */
 static int sht4x_read_values(struct sht4x_data *data)
 {
-	int ret = 0;
+	int ret;
 	u16 t_ticks, rh_ticks;
 	unsigned long next_update;
 	struct i2c_client *client = data->client;
@@ -96,8 +94,6 @@ static int sht4x_read_values(struct sht4x_data *data)
 	u8 raw_data[SHT4X_RESPONSE_LENGTH];
 	unsigned long curr_jiffies;
 
-	mutex_lock(&data->lock);
-
 	curr_jiffies = jiffies;
 	if (time_before(curr_jiffies, data->heating_complete))
 		msleep(jiffies_to_msecs(data->heating_complete - curr_jiffies));
@@ -110,11 +106,11 @@ static int sht4x_read_values(struct sht4x_data *data)
 			msecs_to_jiffies(data->update_interval);
 
 		if (data->valid && time_before_eq(jiffies, next_update))
-			goto unlock;
+			return 0;
 
 		ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN);
 		if (ret < 0)
-			goto unlock;
+			return ret;
 
 		usleep_range(SHT4X_MEAS_DELAY_HPM, SHT4X_MEAS_DELAY_HPM + SHT4X_DELAY_EXTRA);
 	}
@@ -123,7 +119,7 @@ static int sht4x_read_values(struct sht4x_data *data)
 	if (ret != SHT4X_RESPONSE_LENGTH) {
 		if (ret >= 0)
 			ret = -ENODATA;
-		goto unlock;
+		return ret;
 	}
 
 	t_ticks = raw_data[0] << 8 | raw_data[1];
@@ -132,26 +128,20 @@ static int sht4x_read_values(struct sht4x_data *data)
 	crc = crc8(sht4x_crc8_table, &raw_data[0], SHT4X_WORD_LEN, CRC8_INIT_VALUE);
 	if (crc != raw_data[2]) {
 		dev_err(&client->dev, "data integrity check failed\n");
-		ret = -EIO;
-		goto unlock;
+		return -EIO;
 	}
 
 	crc = crc8(sht4x_crc8_table, &raw_data[3], SHT4X_WORD_LEN, CRC8_INIT_VALUE);
 	if (crc != raw_data[5]) {
 		dev_err(&client->dev, "data integrity check failed\n");
-		ret = -EIO;
-		goto unlock;
+		return -EIO;
 	}
 
 	data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000;
 	data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000;
 	data->last_updated = jiffies;
 	data->valid = true;
-	ret = 0;
-
-unlock:
-	mutex_unlock(&data->lock);
-	return ret;
+	return 0;
 }
 
 static ssize_t sht4x_interval_write(struct sht4x_data *data, long val)
@@ -287,22 +277,16 @@ static ssize_t heater_enable_store(struct device *dev,
 		heating_time_bound = 1100;
 	}
 
-	mutex_lock(&data->lock);
-
-	if (time_before(jiffies, data->heating_complete)) {
-		ret = -EBUSY;
-		goto unlock;
-	}
+	if (time_before(jiffies, data->heating_complete))
+		return -EBUSY;
 
 	ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
 	if (ret < 0)
-		goto unlock;
+		return ret;
 
 	data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound);
 	data->data_pending = true;
-unlock:
-	mutex_unlock(&data->lock);
-	return ret;
+	return 0;
 }
 
 static ssize_t heater_power_show(struct device *dev,
@@ -422,8 +406,6 @@ static int sht4x_probe(struct i2c_client *client)
 	data->heater_time = 1000;
 	data->heating_complete = jiffies;
 
-	mutex_init(&data->lock);
-
 	crc8_populate_msb(sht4x_crc8_table, SHT4X_CRC8_POLYNOMIAL);
 
 	ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN);
-- 
2.45.2


  parent reply	other threads:[~2025-10-17 13:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17 13:01 [PATCH 00/29] hwmon: Rely on subsystem locking [set 2] Guenter Roeck
2025-10-17 13:01 ` [PATCH 01/29] hwmon: (max127) Rely on subsystem locking Guenter Roeck
2025-10-17 13:01 ` [PATCH 02/29] hwmon: (lm95234) " Guenter Roeck
2025-10-17 13:01 ` [PATCH 03/29] hwmon: (lm92) " Guenter Roeck
2025-10-17 13:01 ` [PATCH 04/29] hwmon: (hs3001) " Guenter Roeck
2025-10-17 13:01 ` [PATCH 05/29] hwmon: (sbtsi_temp) " Guenter Roeck
2025-10-17 13:01 ` [PATCH 06/29] hwmon: (ina2xx) " Guenter Roeck
2025-10-17 13:01 ` Guenter Roeck [this message]
2025-10-17 13:02 ` [PATCH 08/29] hwmon: (ina3221) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 09/29] hwmon: (k10temp) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 10/29] hwmon: (mr75203) Drop unnecessary include file Guenter Roeck
2025-10-17 13:02 ` [PATCH 11/29] hwmon: (powr1220) Rely on subsystem locking Guenter Roeck
2025-10-17 13:02 ` [PATCH 12/29] hwmon: (ftsteutates) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 13/29] hwmon: (ina238) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 14/29] hwmon: (lm95241) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 15/29] hwmon: (aht10) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 16/29] hwmon: (adt7411) " Guenter Roeck
2025-10-17 14:10   ` Nuno Sá
2025-10-17 13:02 ` [PATCH 17/29] hwmon: (ltc2947-core) " Guenter Roeck
2025-10-17 14:11   ` Nuno Sá
2025-10-17 13:02 ` [PATCH 18/29] hwmon: (peci) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 19/29] hwmon: (adt7x10) " Guenter Roeck
2025-10-17 14:08   ` Nuno Sá
2025-10-17 13:02 ` [PATCH 20/29] hwmon: (sfctemp) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 21/29] hwmon: (lochnagar-hwmon) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 22/29] hwmon: (ltc4282) " Guenter Roeck
2025-10-17 14:07   ` Nuno Sá
2025-10-17 13:02 ` [PATCH 23/29] hwmon: (aquacomputer_d5next) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 24/29] hwmon: (gpd-fan) " Guenter Roeck
2025-10-17 13:02 ` [PATCH 25/29] hwmon: (i5500_temp) Drop unnecessary include files Guenter Roeck
2025-10-17 13:02 ` [PATCH 26/29] hwmon: (asus_rog_ryujin) Rely on subsystem locking Guenter Roeck
2025-10-17 13:02 ` [PATCH 27/29] hwmon: (chipcap2) Drop unnecessary include files Guenter Roeck
2025-10-17 13:02 ` [PATCH 28/29] hwmon: (corsair-psu) Rely on subsystem locking Guenter Roeck
2025-10-17 13:02 ` [PATCH 29/29] " Guenter Roeck

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=20251017130221.1823453-8-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-hwmon@vger.kernel.org \
    /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