hwmon: (nct7904) Rely on subsystem locking

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>
pull/1354/merge
Guenter Roeck 2025-09-07 13:50:21 -07:00
parent e1c4d5db9a
commit 9ad270bf4d
1 changed files with 24 additions and 39 deletions

View File

@ -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. */