Commit c424d67c authored by Jean Delvare's avatar Jean Delvare Committed by Greg Kroah-Hartman

[PATCH] I2C: Fix macro calls in chip drivers

I noticed that some I2C chip drivers (all written or reviewed by me, I
feel ashamed to say) misuse macros. Passing function calls
(simple_strtol in this case) to macros evaluating their argument up to 4
times is certainly not wise and obviously performs poorly. It is not
critical in that it happens only when writing to the chips (setting
limits), which doesn't happen that often. However I'd say it's worth
fixing.

Thus, the patch below fixes that, by moving the function calls outside
of the macro calls.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 8cc8f43b
......@@ -212,8 +212,8 @@ static ssize_t set_in##offset##_min(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1025_data *data = i2c_get_clientdata(client); \
data->in_min[offset] = IN_TO_REG(simple_strtol(buf, NULL, 10), \
in_scale[offset]); \
long val = simple_strtol(buf, NULL, 10); \
data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
data->in_min[offset]); \
return count; \
......@@ -223,8 +223,8 @@ static ssize_t set_in##offset##_max(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1025_data *data = i2c_get_clientdata(client); \
data->in_max[offset] = IN_TO_REG(simple_strtol(buf, NULL, 10), \
in_scale[offset]); \
long val = simple_strtol(buf, NULL, 10); \
data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
data->in_max[offset]); \
return count; \
......@@ -246,7 +246,8 @@ static ssize_t set_temp##offset##_min(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1025_data *data = i2c_get_clientdata(client); \
data->temp_min[offset-1] = TEMP_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->temp_min[offset-1] = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
data->temp_min[offset-1]); \
return count; \
......@@ -256,7 +257,8 @@ static ssize_t set_temp##offset##_max(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1025_data *data = i2c_get_clientdata(client); \
data->temp_max[offset-1] = TEMP_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->temp_max[offset-1] = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
data->temp_max[offset-1]); \
return count; \
......
......@@ -217,7 +217,8 @@ static ssize_t set_##suffix(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct gl518_data *data = i2c_get_clientdata(client); \
data->value = type##_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->value = type##_TO_REG(val); \
gl518_write_value(client, reg, data->value); \
return count; \
}
......@@ -229,7 +230,8 @@ static ssize_t set_##suffix(struct device *dev, const char *buf, \
struct i2c_client *client = to_i2c_client(dev); \
struct gl518_data *data = i2c_get_clientdata(client); \
int regvalue = gl518_read_value(client, reg); \
data->value = type##_TO_REG(simple_strtoul(buf, NULL, 10)); \
unsigned long val = simple_strtoul(buf, NULL, 10); \
data->value = type##_TO_REG(val); \
regvalue = (regvalue & ~mask) | (data->value << shift); \
gl518_write_value(client, reg, regvalue); \
return count; \
......
......@@ -262,14 +262,15 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
{
struct i2c_client *client = to_i2c_client(dev);
struct lm80_data *data = i2c_get_clientdata(client);
unsigned long min;
unsigned long min, val;
u8 reg;
/* Save fan_min */
min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr]));
data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
val = simple_strtoul(buf, NULL, 10);
data->fan_div[nr] = DIV_TO_REG(val);
reg = (lm80_read_value(client, LM80_REG_FANDIV) & ~(3 << (2 * (nr + 1))))
| (data->fan_div[nr] << (2 * (nr + 1)));
......
......@@ -180,7 +180,8 @@ static ssize_t set_temp_##suffix(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct lm83_data *data = i2c_get_clientdata(client); \
data->value = TEMP_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->value = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, reg, data->value); \
return count; \
}
......
......@@ -214,7 +214,8 @@ static ssize_t set_##value(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct lm90_data *data = i2c_get_clientdata(client); \
data->value = TEMP1_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->value = TEMP1_TO_REG(val); \
i2c_smbus_write_byte_data(client, reg, data->value); \
return count; \
}
......@@ -224,7 +225,8 @@ static ssize_t set_##value(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct lm90_data *data = i2c_get_clientdata(client); \
data->value = TEMP2_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->value = TEMP2_TO_REG(val); \
i2c_smbus_write_byte_data(client, regh, data->value >> 8); \
i2c_smbus_write_byte_data(client, regl, data->value & 0xff); \
return count; \
......
......@@ -145,7 +145,8 @@ static ssize_t set_##value(struct device *dev, const char *buf, \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct max1619_data *data = i2c_get_clientdata(client); \
data->value = TEMP_TO_REG(simple_strtol(buf, NULL, 10)); \
long val = simple_strtol(buf, NULL, 10); \
data->value = TEMP_TO_REG(val); \
i2c_smbus_write_byte_data(client, reg, data->value); \
return count; \
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment