mirror of https://gitee.com/openkylin/linux.git
hwmon: (max6650) Improve error handling in max6650_init_client
Do not overwrite errors reported from i2c functions, and don't ignore any errors. Cc: Jean-Francois Dagenais <jeff.dagenais@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
b2905bb8e1
commit
b9d8de4a17
|
@ -604,8 +604,8 @@ static int max6650_init_client(struct max6650_data *data,
|
||||||
struct i2c_client *client)
|
struct i2c_client *client)
|
||||||
{
|
{
|
||||||
struct device *dev = &client->dev;
|
struct device *dev = &client->dev;
|
||||||
int config;
|
int reg;
|
||||||
int err = -EIO;
|
int err;
|
||||||
u32 voltage;
|
u32 voltage;
|
||||||
u32 prescale;
|
u32 prescale;
|
||||||
u32 target_rpm;
|
u32 target_rpm;
|
||||||
|
@ -619,21 +619,20 @@ static int max6650_init_client(struct max6650_data *data,
|
||||||
&prescale))
|
&prescale))
|
||||||
prescale = prescaler;
|
prescale = prescaler;
|
||||||
|
|
||||||
config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);
|
reg = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);
|
||||||
|
if (reg < 0) {
|
||||||
if (config < 0) {
|
dev_err(dev, "Error reading config register, aborting.\n");
|
||||||
dev_err(dev, "Error reading config, aborting.\n");
|
return reg;
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (voltage) {
|
switch (voltage) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
config &= ~MAX6650_CFG_V12;
|
reg &= ~MAX6650_CFG_V12;
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
config |= MAX6650_CFG_V12;
|
reg |= MAX6650_CFG_V12;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(dev, "illegal value for fan_voltage (%d)\n", voltage);
|
dev_err(dev, "illegal value for fan_voltage (%d)\n", voltage);
|
||||||
|
@ -643,22 +642,22 @@ static int max6650_init_client(struct max6650_data *data,
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
config &= ~MAX6650_CFG_PRESCALER_MASK;
|
reg &= ~MAX6650_CFG_PRESCALER_MASK;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
config = (config & ~MAX6650_CFG_PRESCALER_MASK)
|
reg = (reg & ~MAX6650_CFG_PRESCALER_MASK)
|
||||||
| MAX6650_CFG_PRESCALER_2;
|
| MAX6650_CFG_PRESCALER_2;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
config = (config & ~MAX6650_CFG_PRESCALER_MASK)
|
reg = (reg & ~MAX6650_CFG_PRESCALER_MASK)
|
||||||
| MAX6650_CFG_PRESCALER_4;
|
| MAX6650_CFG_PRESCALER_4;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
config = (config & ~MAX6650_CFG_PRESCALER_MASK)
|
reg = (reg & ~MAX6650_CFG_PRESCALER_MASK)
|
||||||
| MAX6650_CFG_PRESCALER_8;
|
| MAX6650_CFG_PRESCALER_8;
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
config = (config & ~MAX6650_CFG_PRESCALER_MASK)
|
reg = (reg & ~MAX6650_CFG_PRESCALER_MASK)
|
||||||
| MAX6650_CFG_PRESCALER_16;
|
| MAX6650_CFG_PRESCALER_16;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -666,16 +665,22 @@ static int max6650_init_client(struct max6650_data *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n",
|
dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n",
|
||||||
(config & MAX6650_CFG_V12) ? 12 : 5,
|
(reg & MAX6650_CFG_V12) ? 12 : 5,
|
||||||
1 << (config & MAX6650_CFG_PRESCALER_MASK));
|
1 << (reg & MAX6650_CFG_PRESCALER_MASK));
|
||||||
|
|
||||||
if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) {
|
err = i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, reg);
|
||||||
|
if (err) {
|
||||||
dev_err(dev, "Config write error, aborting.\n");
|
dev_err(dev, "Config write error, aborting.\n");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->config = config;
|
data->config = reg;
|
||||||
data->count = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT);
|
reg = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT);
|
||||||
|
if (reg < 0) {
|
||||||
|
dev_err(dev, "Failed to read count register, aborting.\n");
|
||||||
|
return reg;
|
||||||
|
}
|
||||||
|
data->count = reg;
|
||||||
|
|
||||||
if (!of_property_read_u32(client->dev.of_node, "maxim,fan-target-rpm",
|
if (!of_property_read_u32(client->dev.of_node, "maxim,fan-target-rpm",
|
||||||
&target_rpm)) {
|
&target_rpm)) {
|
||||||
|
|
Loading…
Reference in New Issue