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 17/20] hwmon: (nct7904) Rely on subsystem locking
Date: Tue, 14 Oct 2025 08:25:12 -0700	[thread overview]
Message-ID: <20251014152515.785203-18-linux@roeck-us.net> (raw)
In-Reply-To: <20251014152515.785203-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/nct7904.c | 63 ++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 39 deletions(-)

diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index f1e6eda949ba..2fa091720c79 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -21,7 +21,6 @@
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/i2c.h>
-#include <linux/mutex.h>
 #include <linux/hwmon.h>
 #include <linux/watchdog.h>
 
@@ -128,7 +127,6 @@ static const unsigned short normal_i2c[] = {
 struct nct7904_data {
 	struct i2c_client *client;
 	struct watchdog_device wdt;
-	struct mutex bank_lock;
 	int bank_sel;
 	u32 fanin_mask;
 	u32 vsen_mask;
@@ -142,24 +140,19 @@ struct nct7904_data {
 };
 
 /* Access functions */
-static int nct7904_bank_lock(struct nct7904_data *data, unsigned int bank)
+static int nct7904_bank_select(struct nct7904_data *data, unsigned int bank)
 {
 	int ret;
 
-	mutex_lock(&data->bank_lock);
 	if (data->bank_sel == bank)
 		return 0;
 	ret = i2c_smbus_write_byte_data(data->client, BANK_SEL_REG, bank);
-	if (ret == 0)
-		data->bank_sel = bank;
-	else
+	if (ret < 0) {
 		data->bank_sel = -1;
-	return ret;
-}
-
-static inline void nct7904_bank_release(struct nct7904_data *data)
-{
-	mutex_unlock(&data->bank_lock);
+		return ret;
+	}
+	data->bank_sel = bank;
+	return 0;
 }
 
 /* Read 1-byte register. Returns unsigned reg or -ERRNO on error. */
@@ -169,12 +162,10 @@ static int nct7904_read_reg(struct nct7904_data *data,
 	struct i2c_client *client = data->client;
 	int ret;
 
-	ret = nct7904_bank_lock(data, bank);
-	if (ret == 0)
-		ret = i2c_smbus_read_byte_data(client, reg);
-
-	nct7904_bank_release(data);
-	return ret;
+	ret = nct7904_bank_select(data, bank);
+	if (ret < 0)
+		return ret;
+	return i2c_smbus_read_byte_data(client, reg);
 }
 
 /*
@@ -187,19 +178,16 @@ static int nct7904_read_reg16(struct nct7904_data *data,
 	struct i2c_client *client = data->client;
 	int ret, hi;
 
-	ret = nct7904_bank_lock(data, bank);
-	if (ret == 0) {
-		ret = i2c_smbus_read_byte_data(client, reg);
-		if (ret >= 0) {
-			hi = ret;
-			ret = i2c_smbus_read_byte_data(client, reg + 1);
-			if (ret >= 0)
-				ret |= hi << 8;
-		}
-	}
-
-	nct7904_bank_release(data);
-	return ret;
+	ret = nct7904_bank_select(data, bank);
+	if (ret < 0)
+		return ret;
+	hi = i2c_smbus_read_byte_data(client, reg);
+	if (hi < 0)
+		return hi;
+	ret = i2c_smbus_read_byte_data(client, reg + 1);
+	if (ret < 0)
+		return ret;
+	return ret | (hi << 8);
 }
 
 /* Write 1-byte register. Returns 0 or -ERRNO on error. */
@@ -209,12 +197,10 @@ static int nct7904_write_reg(struct nct7904_data *data,
 	struct i2c_client *client = data->client;
 	int ret;
 
-	ret = nct7904_bank_lock(data, bank);
-	if (ret == 0)
-		ret = i2c_smbus_write_byte_data(client, reg, val);
-
-	nct7904_bank_release(data);
-	return ret;
+	ret = nct7904_bank_select(data, bank);
+	if (ret < 0)
+		return ret;
+	return i2c_smbus_write_byte_data(client, reg, val);
 }
 
 static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
@@ -1023,7 +1009,6 @@ static int nct7904_probe(struct i2c_client *client)
 		return -ENOMEM;
 
 	data->client = client;
-	mutex_init(&data->bank_lock);
 	data->bank_sel = -1;
 
 	/* Setup sensor groups. */
-- 
2.45.2


  parent reply	other threads:[~2025-10-14 15:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 15:24 [PATCH 00/20] hwmon: Rely on subsystem locking [set 1] Guenter Roeck
2025-10-14 15:24 ` [PATCH 01/20] hwmon: (jc42) Rely on subsystem locking Guenter Roeck
2025-10-14 15:24 ` [PATCH 02/20] hwmon: (lm90) " Guenter Roeck
2025-10-14 15:24 ` [PATCH 03/20] hwmon: (adm9240) " Guenter Roeck
2025-10-14 15:24 ` [PATCH 04/20] hwmon: (emc1403) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 05/20] hwmon: (tmp464) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 06/20] hwmon: (tmp421) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 07/20] hwmon: (tmp401) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 08/20] hwmon: (tmp108) Drop mutex.h include Guenter Roeck
2025-10-14 15:25 ` [PATCH 09/20] hwmon: (drivetemp) Rely on subsystem locking Guenter Roeck
2025-10-14 15:25 ` [PATCH 10/20] hwmon: (max6697) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 11/20] hwmon: (ltc4245) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 12/20] hwmon: (lm95245) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 13/20] hwmon: (tmp103) Drop unnecessary include files Guenter Roeck
2025-10-14 15:25 ` [PATCH 14/20] hwmon: (tmp102) " Guenter Roeck
2025-10-14 15:25 ` [PATCH 15/20] hwmon: (max6639) Rely on subsystem locking Guenter Roeck
2025-10-14 15:25 ` [PATCH 16/20] hwmon: (max31827) " Guenter Roeck
2025-10-14 15:25 ` Guenter Roeck [this message]
2025-10-14 15:25 ` [PATCH 18/20] hwmon: (nct7363) Drop unnecessary include files Guenter Roeck
2025-10-14 15:25 ` [PATCH 19/20] hwmon: (max6620) Rely on subsystem locking Guenter Roeck
2025-10-14 15:25 ` [PATCH 20/20] hwmon: (max31790) " 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=20251014152515.785203-18-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