[v2 1/9] hwmon: (nct7904) Add error handling in probe function.

From: Amy.Shih
Date: Mon Jun 17 2019 - 04:14:10 EST


From: "amy.shih" <amy.shih@xxxxxxxxxxxxxxxx>

When register read and write operations return errors, needs to add
error handling.

Signed-off-by: amy.shih <amy.shih@xxxxxxxxxxxxxxxx>
---
Changes in v2:
- Check for errors on register read and write operations.

drivers/hwmon/nct7904.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index 5708171197e7..401ed4a4a576 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -506,6 +506,8 @@ static int nct7904_probe(struct i2c_client *client,

/* CPU_TEMP attributes */
ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL0_REG);
+ if (ret < 0)
+ return ret;

if ((ret & 0x6) == 0x6)
data->tcpu_mask |= 1; /* TR1 */
@@ -518,11 +520,15 @@ static int nct7904_probe(struct i2c_client *client,

/* LTD */
ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG);
+ if (ret < 0)
+ return ret;
if ((ret & 0x02) == 0x02)
data->tcpu_mask |= 0x10;

/* Multi-Function detecting for Volt and TR/TD */
ret = nct7904_read_reg(data, BANK_0, VT_ADC_MD_REG);
+ if (ret < 0)
+ return ret;

for (i = 0; i < 4; i++) {
val = (ret & (0x03 << i)) >> (i * 2);
@@ -533,22 +539,29 @@ static int nct7904_probe(struct i2c_client *client,

/* PECI */
ret = nct7904_read_reg(data, BANK_2, PFE_REG);
+ if (ret < 0)
+ return ret;
if (ret & 0x80) {
data->enable_dts = 1; //Enable DTS & PECI
} else {
ret = nct7904_read_reg(data, BANK_2, TSI_CTRL_REG);
+ if (ret < 0)
+ return ret;
if (ret & 0x80)
data->enable_dts = 0x3; //Enable DTS & TSI
}

/* Check DTS enable status */
if (data->enable_dts) {
- data->has_dts =
- nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG) & 0xF;
+ ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG);
+ if (ret < 0)
+ return ret;
+ data->has_dts = ret & 0xF;
if (data->enable_dts & 0x2) {
- data->has_dts |=
- (nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG) & 0xF)
- << 4;
+ ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG);
+ if (ret < 0)
+ return ret;
+ data->has_dts |= (ret & 0xF) << 4;
}
}

--
2.17.1