[PATCH v3 2/2] hwmon:max6697: fixing the type issue where the comparison is always true

From: Chu Lin
Date: Mon Jul 06 2020 - 20:23:00 EST


- Use reverse christmas tree order convension
- fix the type issue where comparision is always true
- Change the line limit to 100 char instead of 80 char

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Signed-off-by: Chu Lin <linchuyuan@xxxxxxxxxx>
---
drivers/hwmon/max6697.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/hwmon/max6697.c b/drivers/hwmon/max6697.c
index 8c814c544116..6b213e146fbe 100644
--- a/drivers/hwmon/max6697.c
+++ b/drivers/hwmon/max6697.c
@@ -329,15 +329,13 @@ static ssize_t offset_store(struct device *dev,
struct device_attribute *devattr, const char *buf,
size_t count)
{
- long temp;
- u8 val, select;
- int ret, index;
+ int val, ret, index, select;
struct max6697_data *data;
+ long temp;

index = to_sensor_dev_attr(devattr)->index;
data = dev_get_drvdata(dev);
- select = i2c_smbus_read_byte_data(data->client,
- MAX6581_REG_OFFSET_SELECT);
+ select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT);
if (select < 0)
return select;
ret = kstrtol(buf, 10, &temp);
@@ -345,22 +343,18 @@ static ssize_t offset_store(struct device *dev,
return ret;
/* disable the offset for channel */
if (temp == 0) {
- ret = i2c_smbus_write_byte_data(data->client,
- MAX6581_REG_OFFSET_SELECT,
+ ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT,
select & ~(1 << (index - 1)));
return ret < 0 ? ret : count;
}
temp = clamp_val(temp, MAX6581_OFFSET_MIN, MAX6581_OFFSET_MAX);
val = DIV_ROUND_CLOSEST(temp, 250);
mutex_lock(&data->update_lock);
- ret = i2c_smbus_write_byte_data(data->client,
- MAX6581_REG_OFFSET_SELECT,
+ ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET_SELECT,
select | (1 << (index - 1)));
if (ret < 0)
return ret;
- ret = i2c_smbus_write_byte_data(data->client,
- MAX6581_REG_OFFSET,
- val);
+ ret = i2c_smbus_write_byte_data(data->client, MAX6581_REG_OFFSET, val);
mutex_unlock(&data->update_lock);
return ret < 0 ? ret : count;
}
@@ -368,18 +362,16 @@ static ssize_t offset_store(struct device *dev,
static ssize_t offset_show(struct device *dev, struct device_attribute *devattr,
char *buf)
{
- int select, ret, index;
struct max6697_data *data;
+ int select, ret, index;

index = to_sensor_dev_attr(devattr)->index;
data = dev_get_drvdata(dev);
- select = i2c_smbus_read_byte_data(data->client,
- MAX6581_REG_OFFSET_SELECT);
+ select = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET_SELECT);
if (select < 0)
return select;
if (select & (1 << (index - 1))) {
- ret = i2c_smbus_read_byte_data(data->client,
- MAX6581_REG_OFFSET);
+ ret = i2c_smbus_read_byte_data(data->client, MAX6581_REG_OFFSET);
if (ret < 0)
return ret;
} else {
--
2.27.0.383.g050319c2ae-goog