Skip to contentSkip to conversation

hwmon: (lm90) split set&show temp as common codes

PATCH RESEND Superseded Wei Ni 2 participants 5 messages Aug 6, 2013 – Sep 17, 2013

Subsystems (3)
lore
Share & tools
lore

Wei Ni

author
#0 lore raw

PATCH RESEND v4 1/1 hwmon: (lm90) split set&show temp as common codes

Split set&show temp codes as common functions, so we can use it directly when implement linux thermal framework.
And handle error return value for the lm90_select_remote_channel and write_tempx, then set_temp8 and set_temp11 could return it to user-space.

---
 drivers/hwmon/lm90.c |  150 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 99 insertions(+), 51 deletions(-)
drivers/hwmon/lm90.c +99 -51
index cdff742..6de8e01 100644
@@ -422,20 +422,29 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
  * various registers have different meanings as a result of selecting a
  * non-default remote channel.
  */
-static inline void lm90_select_remote_channel(struct i2c_client *client,
+static inline int lm90_select_remote_channel(struct i2c_client *client,
 					      struct lm90_data *data,
 					      int channel)
 {
 	u8 config;
+	int err = 0;
 
 	if (data->kind == max6696) {
 		lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 		config &= ~0x08;
 		if (channel)
 			config |= 0x08;
-		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
-					  config);
+		err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
+						config);
+		if (err < 0) {
+			dev_err(&client->dev,
+				"Failed to select remote channel %d, err %d\n",
+				channel, err);
+			return err;
+		}
 	}
+
+	return err;
 }
 
 /*
@@ -702,29 +711,34 @@ static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
  * Sysfs stuff
  */
 
-static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
-			  char *buf)
+static int read_temp8(struct device *dev, int index)
 {
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
+		temp = temp_from_u8_adt7461(data, data->temp8[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u8(data->temp8[attr->index]);
+		temp = temp_from_u8(data->temp8[index]);
 	else
-		temp = temp_from_s8(data->temp8[attr->index]);
+		temp = temp_from_s8(data->temp8[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
-			 const char *buf, size_t count)
+static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%d\n", read_temp8(dev, attr->index));
+}
+
+static int write_temp8(struct device *dev, int index, long val)
 {
 	static const u8 reg[8] = {
 		LM90_REG_W_LOCAL_LOW,
@@ -737,60 +751,79 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
 		MAX6659_REG_W_REMOTE_EMERG,
 	};
 
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		val -= 16000;
 
 	mutex_lock(&data->update_lock);
 	if (data->kind == adt7461)
-		data->temp8[nr] = temp_to_u8_adt7461(data, val);
+		data->temp8[index] = temp_to_u8_adt7461(data, val);
 	else if (data->kind == max6646)
-		data->temp8[nr] = temp_to_u8(val);
+		data->temp8[index] = temp_to_u8(val);
 	else
-		data->temp8[nr] = temp_to_s8(val);
-
-	lm90_select_remote_channel(client, data, nr >= 6);
-	i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
-	lm90_select_remote_channel(client, data, 0);
+		data->temp8[index] = temp_to_s8(val);
 
+	err = lm90_select_remote_channel(client, data, index >= 6);
+	err |= i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp8 failed!\n");
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
+			 const char *buf, size_t count)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp8(dev, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
-static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
-			   char *buf)
+static int read_temp11(struct device *dev, int index)
 {
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
+		temp = temp_from_u16_adt7461(data, data->temp11[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u16(data->temp11[attr->index]);
+		temp = temp_from_u16(data->temp11[index]);
 	else
-		temp = temp_from_s16(data->temp11[attr->index]);
+		temp = temp_from_s16(data->temp11[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 &&  attr->index <= 2)
+	if (data->kind == lm99 && index <= 2)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
-			  const char *buf, size_t count)
+static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
+			   char *buf)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+
+	return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
+}
+
+static int write_temp11(struct device *dev, int nr, int index, long val)
 {
 	struct {
 		u8 high;
@@ -804,18 +837,10 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 		{ LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
 	};
 
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->nr;
-	int index = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
 	if (data->kind == lm99 && index <= 2)
 		val -= 16000;
@@ -830,15 +855,38 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 	else
 		data->temp11[index] = temp_to_s8(val) << 8;
 
-	lm90_select_remote_channel(client, data, reg[nr].channel);
-	i2c_smbus_write_byte_data(client, reg[nr].high,
+	err = lm90_select_remote_channel(client, data, reg[nr].channel);
+	err |= i2c_smbus_write_byte_data(client, reg[nr].high,
 				  data->temp11[index] >> 8);
 	if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
-		i2c_smbus_write_byte_data(client, reg[nr].low,
-					  data->temp11[index] & 0xff);
-	lm90_select_remote_channel(client, data, 0);
+		err |= i2c_smbus_write_byte_data(client, reg[nr].low,
+						data->temp11[index] & 0xff);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp11 failed !\n");
 
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
+			  const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+	int nr = attr->nr;
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp11(dev, nr, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
Signature · 1 line
1.7.9.5
author
#1 lore raw

This patch is separated from my previous v3 series, which is in
http://www.mail-archive.com/[email protected]/msg466772.html

Changes from v3:
1. Add error handler for lm90_select_remote_channel(), set_temp8(), and set_temp11().

Wei.

Quoted 262 lines · Wei Ni

Split set&show temp codes as common functions, so we can use it directly when implement linux thermal framework.
And handle error return value for the lm90_select_remote_channel and write_tempx, then set_temp8 and set_temp11 could return it to user-space.

---
 drivers/hwmon/lm90.c |  150 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 99 insertions(+), 51 deletions(-)
drivers/hwmon/lm90.c +99 -51
index cdff742..6de8e01 100644
@@ -422,20 +422,29 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
  * various registers have different meanings as a result of selecting a
  * non-default remote channel.
  */
-static inline void lm90_select_remote_channel(struct i2c_client *client,
+static inline int lm90_select_remote_channel(struct i2c_client *client,
 					      struct lm90_data *data,
 					      int channel)
 {
 	u8 config;
+	int err = 0;
 
 	if (data->kind == max6696) {
 		lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 		config &= ~0x08;
 		if (channel)
 			config |= 0x08;
-		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
-					  config);
+		err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
+						config);
+		if (err < 0) {
+			dev_err(&client->dev,
+				"Failed to select remote channel %d, err %d\n",
+				channel, err);
+			return err;
+		}
 	}
+
+	return err;
 }
 
 /*
@@ -702,29 +711,34 @@ static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
  * Sysfs stuff
  */
 
-static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
-			  char *buf)
+static int read_temp8(struct device *dev, int index)
 {
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
+		temp = temp_from_u8_adt7461(data, data->temp8[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u8(data->temp8[attr->index]);
+		temp = temp_from_u8(data->temp8[index]);
 	else
-		temp = temp_from_s8(data->temp8[attr->index]);
+		temp = temp_from_s8(data->temp8[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
-			 const char *buf, size_t count)
+static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%d\n", read_temp8(dev, attr->index));
+}
+
+static int write_temp8(struct device *dev, int index, long val)
 {
 	static const u8 reg[8] = {
 		LM90_REG_W_LOCAL_LOW,
@@ -737,60 +751,79 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
 		MAX6659_REG_W_REMOTE_EMERG,
 	};
 
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		val -= 16000;
 
 	mutex_lock(&data->update_lock);
 	if (data->kind == adt7461)
-		data->temp8[nr] = temp_to_u8_adt7461(data, val);
+		data->temp8[index] = temp_to_u8_adt7461(data, val);
 	else if (data->kind == max6646)
-		data->temp8[nr] = temp_to_u8(val);
+		data->temp8[index] = temp_to_u8(val);
 	else
-		data->temp8[nr] = temp_to_s8(val);
-
-	lm90_select_remote_channel(client, data, nr >= 6);
-	i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
-	lm90_select_remote_channel(client, data, 0);
+		data->temp8[index] = temp_to_s8(val);
 
+	err = lm90_select_remote_channel(client, data, index >= 6);
+	err |= i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp8 failed!\n");
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
+			 const char *buf, size_t count)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp8(dev, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
-static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
-			   char *buf)
+static int read_temp11(struct device *dev, int index)
 {
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
+		temp = temp_from_u16_adt7461(data, data->temp11[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u16(data->temp11[attr->index]);
+		temp = temp_from_u16(data->temp11[index]);
 	else
-		temp = temp_from_s16(data->temp11[attr->index]);
+		temp = temp_from_s16(data->temp11[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 &&  attr->index <= 2)
+	if (data->kind == lm99 && index <= 2)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
-			  const char *buf, size_t count)
+static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
+			   char *buf)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+
+	return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
+}
+
+static int write_temp11(struct device *dev, int nr, int index, long val)
 {
 	struct {
 		u8 high;
@@ -804,18 +837,10 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 		{ LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
 	};
 
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->nr;
-	int index = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
 	if (data->kind == lm99 && index <= 2)
 		val -= 16000;
@@ -830,15 +855,38 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 	else
 		data->temp11[index] = temp_to_s8(val) << 8;
 
-	lm90_select_remote_channel(client, data, reg[nr].channel);
-	i2c_smbus_write_byte_data(client, reg[nr].high,
+	err = lm90_select_remote_channel(client, data, reg[nr].channel);
+	err |= i2c_smbus_write_byte_data(client, reg[nr].high,
 				  data->temp11[index] >> 8);
 	if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
-		i2c_smbus_write_byte_data(client, reg[nr].low,
-					  data->temp11[index] & 0xff);
-	lm90_select_remote_channel(client, data, 0);
+		err |= i2c_smbus_write_byte_data(client, reg[nr].low,
+						data->temp11[index] & 0xff);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp11 failed !\n");
 
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
+			  const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+	int nr = attr->nr;
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp11(dev, nr, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
author
#2 lore raw

Hi, Jean
Do you have any more suggestions on this patch ?

Thanks.
Wei.

Quoted 273 lines · Wei Ni

This patch is separated from my previous v3 series, which is in
http://www.mail-archive.com/[email protected]/msg466772.html

Changes from v3:
1. Add error handler for lm90_select_remote_channel(), set_temp8(), and set_temp11().

Wei.

Quoted 262 lines · Wei Ni

Split set&show temp codes as common functions, so we can use it directly when implement linux thermal framework.
And handle error return value for the lm90_select_remote_channel and write_tempx, then set_temp8 and set_temp11 could return it to user-space.

---
 drivers/hwmon/lm90.c |  150 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 99 insertions(+), 51 deletions(-)
drivers/hwmon/lm90.c +99 -51
index cdff742..6de8e01 100644
@@ -422,20 +422,29 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
  * various registers have different meanings as a result of selecting a
  * non-default remote channel.
  */
-static inline void lm90_select_remote_channel(struct i2c_client *client,
+static inline int lm90_select_remote_channel(struct i2c_client *client,
 					      struct lm90_data *data,
 					      int channel)
 {
 	u8 config;
+	int err = 0;
 
 	if (data->kind == max6696) {
 		lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 		config &= ~0x08;
 		if (channel)
 			config |= 0x08;
-		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
-					  config);
+		err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
+						config);
+		if (err < 0) {
+			dev_err(&client->dev,
+				"Failed to select remote channel %d, err %d\n",
+				channel, err);
+			return err;
+		}
 	}
+
+	return err;
 }
 
 /*
@@ -702,29 +711,34 @@ static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
  * Sysfs stuff
  */
 
-static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
-			  char *buf)
+static int read_temp8(struct device *dev, int index)
 {
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
+		temp = temp_from_u8_adt7461(data, data->temp8[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u8(data->temp8[attr->index]);
+		temp = temp_from_u8(data->temp8[index]);
 	else
-		temp = temp_from_s8(data->temp8[attr->index]);
+		temp = temp_from_s8(data->temp8[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
-			 const char *buf, size_t count)
+static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%d\n", read_temp8(dev, attr->index));
+}
+
+static int write_temp8(struct device *dev, int index, long val)
 {
 	static const u8 reg[8] = {
 		LM90_REG_W_LOCAL_LOW,
@@ -737,60 +751,79 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
 		MAX6659_REG_W_REMOTE_EMERG,
 	};
 
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		val -= 16000;
 
 	mutex_lock(&data->update_lock);
 	if (data->kind == adt7461)
-		data->temp8[nr] = temp_to_u8_adt7461(data, val);
+		data->temp8[index] = temp_to_u8_adt7461(data, val);
 	else if (data->kind == max6646)
-		data->temp8[nr] = temp_to_u8(val);
+		data->temp8[index] = temp_to_u8(val);
 	else
-		data->temp8[nr] = temp_to_s8(val);
-
-	lm90_select_remote_channel(client, data, nr >= 6);
-	i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
-	lm90_select_remote_channel(client, data, 0);
+		data->temp8[index] = temp_to_s8(val);
 
+	err = lm90_select_remote_channel(client, data, index >= 6);
+	err |= i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp8 failed!\n");
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
+			 const char *buf, size_t count)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp8(dev, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
-static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
-			   char *buf)
+static int read_temp11(struct device *dev, int index)
 {
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
+		temp = temp_from_u16_adt7461(data, data->temp11[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u16(data->temp11[attr->index]);
+		temp = temp_from_u16(data->temp11[index]);
 	else
-		temp = temp_from_s16(data->temp11[attr->index]);
+		temp = temp_from_s16(data->temp11[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 &&  attr->index <= 2)
+	if (data->kind == lm99 && index <= 2)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
-			  const char *buf, size_t count)
+static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
+			   char *buf)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+
+	return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
+}
+
+static int write_temp11(struct device *dev, int nr, int index, long val)
 {
 	struct {
 		u8 high;
@@ -804,18 +837,10 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 		{ LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
 	};
 
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->nr;
-	int index = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
 	if (data->kind == lm99 && index <= 2)
 		val -= 16000;
@@ -830,15 +855,38 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 	else
 		data->temp11[index] = temp_to_s8(val) << 8;
 
-	lm90_select_remote_channel(client, data, reg[nr].channel);
-	i2c_smbus_write_byte_data(client, reg[nr].high,
+	err = lm90_select_remote_channel(client, data, reg[nr].channel);
+	err |= i2c_smbus_write_byte_data(client, reg[nr].high,
 				  data->temp11[index] >> 8);
 	if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
-		i2c_smbus_write_byte_data(client, reg[nr].low,
-					  data->temp11[index] & 0xff);
-	lm90_select_remote_channel(client, data, 0);
+		err |= i2c_smbus_write_byte_data(client, reg[nr].low,
+						data->temp11[index] & 0xff);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp11 failed !\n");
 
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
+			  const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+	int nr = attr->nr;
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp11(dev, nr, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
#3 lore raw
In reply to Wei Ni

Hi Wei,

Quoted 16 lines · Wei Ni

Split set&show temp codes as common functions, so we can use it directly when implement linux thermal framework.
And handle error return value for the lm90_select_remote_channel and write_tempx, then set_temp8 and set_temp11 could return it to user-space.

---
 drivers/hwmon/lm90.c |  150 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 99 insertions(+), 51 deletions(-)
drivers/hwmon/lm90.c +0 -0
index cdff742..6de8e01 100644

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 430

Quoted 10 lines
drivers/hwmon/lm90.c +2 -1
@@ -422,20 +422,29 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
  * various registers have different meanings as a result of selecting a
  * non-default remote channel.
  */
-static inline void lm90_select_remote_channel(struct i2c_client *client,
+static inline int lm90_select_remote_channel(struct i2c_client *client,
 					      struct lm90_data *data,
 					      int channel)
 {
 	u8 config;
+	int err = 0;

You don't have to initialize err, as you return immediately when an error happens. You can just...

Quoted 9 lines
drivers/hwmon/lm90.c +1 -2
 	if (data->kind == max6696) {
 		lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 		config &= ~0x08;
 		if (channel)
 			config |= 0x08;
-		i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
-					  config);
+		err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 447

Quoted 10 lines
drivers/hwmon/lm90.c +9 -0
+						config);
+		if (err < 0) {
+			dev_err(&client->dev,
+				"Failed to select remote channel %d, err %d\n",
+				channel, err);
+			return err;
+		}
 	}
+
+	return err;

... return 0 here.

Quoted 76 lines
drivers/hwmon/lm90.c +18 -20
 }
 
 /*
@@ -702,29 +711,34 @@ static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
  * Sysfs stuff
  */
 
-static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
-			  char *buf)
+static int read_temp8(struct device *dev, int index)
 {
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
+		temp = temp_from_u8_adt7461(data, data->temp8[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u8(data->temp8[attr->index]);
+		temp = temp_from_u8(data->temp8[index]);
 	else
-		temp = temp_from_s8(data->temp8[attr->index]);
+		temp = temp_from_s8(data->temp8[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
-			 const char *buf, size_t count)
+static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+	return sprintf(buf, "%d\n", read_temp8(dev, attr->index));
+}
+
+static int write_temp8(struct device *dev, int index, long val)
 {
 	static const u8 reg[8] = {
 		LM90_REG_W_LOCAL_LOW,
@@ -737,60 +751,79 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
 		MAX6659_REG_W_REMOTE_EMERG,
 	};
 
-	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 && attr->index == 3)
+	if (data->kind == lm99 && index == 3)
 		val -= 16000;
 
 	mutex_lock(&data->update_lock);
 	if (data->kind == adt7461)
-		data->temp8[nr] = temp_to_u8_adt7461(data, val);
+		data->temp8[index] = temp_to_u8_adt7461(data, val);
 	else if (data->kind == max6646)
-		data->temp8[nr] = temp_to_u8(val);
+		data->temp8[index] = temp_to_u8(val);
 	else

drivers/hwmon/lm90.c static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, · line 772

Quoted 10 lines
drivers/hwmon/lm90.c +4 -5
-		data->temp8[nr] = temp_to_s8(val);
-
-	lm90_select_remote_channel(client, data, nr >= 6);
-	i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
-	lm90_select_remote_channel(client, data, 0);
+		data->temp8[index] = temp_to_s8(val);
 
+	err = lm90_select_remote_channel(client, data, index >= 6);
+	err |= i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
+	err |= lm90_select_remote_channel(client, data, 0);

You can't use |= for error codes. Imagine that lm90_select_remote_channel() returns -EIO (-5) and i2c_smbus_write_byte_data() returns -EAGAIN (-11), err will have value -EPERM (-1) which makes no sense. You have to report errors as soon as they happen so that the error code isn't lost.

What you can do is:

	if ((err = f1(...)) ||
	    (err = f2(...)) ||
	    (err = f3(...))) {
		dev_err(...);
		return err;
	}

I think checkpatch will complain about that construct but me, I'm fine with it.

Quoted 94 lines
drivers/hwmon/lm90.c +39 -20
+	if (err)
+		dev_err(dev, "write_temp8 failed!\n");
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
+			 const char *buf, size_t count)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp8(dev, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
-static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
-			   char *buf)
+static int read_temp11(struct device *dev, int index)
 {
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct lm90_data *data = lm90_update_device(dev);
 	int temp;
 
 	if (data->kind == adt7461)
-		temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
+		temp = temp_from_u16_adt7461(data, data->temp11[index]);
 	else if (data->kind == max6646)
-		temp = temp_from_u16(data->temp11[attr->index]);
+		temp = temp_from_u16(data->temp11[index]);
 	else
-		temp = temp_from_s16(data->temp11[attr->index]);
+		temp = temp_from_s16(data->temp11[index]);
 
 	/* +16 degrees offset for temp2 for the LM99 */
-	if (data->kind == lm99 &&  attr->index <= 2)
+	if (data->kind == lm99 && index <= 2)
 		temp += 16000;
 
-	return sprintf(buf, "%d\n", temp);
+	return temp;
 }
 
-static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
-			  const char *buf, size_t count)
+static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
+			   char *buf)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+
+	return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
+}
+
+static int write_temp11(struct device *dev, int nr, int index, long val)
 {
 	struct {
 		u8 high;
@@ -804,18 +837,10 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 		{ LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
 	};
 
-	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm90_data *data = i2c_get_clientdata(client);
-	int nr = attr->nr;
-	int index = attr->index;
-	long val;
 	int err;
 
-	err = kstrtol(buf, 10, &val);
-	if (err < 0)
-		return err;
-
 	/* +16 degrees offset for temp2 for the LM99 */
 	if (data->kind == lm99 && index <= 2)
 		val -= 16000;
@@ -830,15 +855,38 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
 	else
 		data->temp11[index] = temp_to_s8(val) << 8;
 
-	lm90_select_remote_channel(client, data, reg[nr].channel);
-	i2c_smbus_write_byte_data(client, reg[nr].high,
+	err = lm90_select_remote_channel(client, data, reg[nr].channel);
+	err |= i2c_smbus_write_byte_data(client, reg[nr].high,

drivers/hwmon/lm90.c static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, · line 866

Quoted 10 lines
drivers/hwmon/lm90.c +5 -3
 				  data->temp11[index] >> 8);
 	if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
-		i2c_smbus_write_byte_data(client, reg[nr].low,
-					  data->temp11[index] & 0xff);
-	lm90_select_remote_channel(client, data, 0);
+		err |= i2c_smbus_write_byte_data(client, reg[nr].low,
+						data->temp11[index] & 0xff);
+	err |= lm90_select_remote_channel(client, data, 0);
+	if (err)
+		dev_err(dev, "write_temp11 failed !\n");

Same here, you can't use |=.

Also, no space needed before exclamation marks in English.

Quoted 26 lines
drivers/hwmon/lm90.c +21 -0
 	mutex_unlock(&data->update_lock);
+
+	return err;
+}
+
+static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
+			  const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+	int nr = attr->nr;
+	int index = attr->index;
+	long val;
+	int err;
+
+	err = kstrtol(buf, 10, &val);
+	if (err < 0)
+		return err;
+
+	err = write_temp11(dev, nr, index, val);
+	if (err < 0)
+		return err;
+
 	return count;
 }
 
Signature · 1 line
Jean Delvare
author
#4 lore raw
Quoted 24 lines · Jean Delvare

Hi Wei,

Quoted 21 lines · Wei Ni

Split set&show temp codes as common functions, so we can use it directly when implement linux thermal framework.
And handle error return value for the lm90_select_remote_channel and write_tempx, then set_temp8 and set_temp11 could return it to user-space.

---
 drivers/hwmon/lm90.c |  150 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 99 insertions(+), 51 deletions(-)
drivers/hwmon/lm90.c +1 -1
index cdff742..6de8e01 100644
@@ -422,20 +422,29 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
  * various registers have different meanings as a result of selecting a
  * non-default remote channel.
  */
-static inline void lm90_select_remote_channel(struct i2c_client *client,
+static inline int lm90_select_remote_channel(struct i2c_client *client,
Quoted 8 lines

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 430

Quoted 5 lines
drivers/hwmon/lm90.c +1 -0
                                            struct lm90_data *data,
                                            int channel)
 {
      u8 config;
+     int err = 0;

You don't have to initialize err, as you return immediately when an error happens. You can just...

Got it, I will change it.

Quoted 125 lines
Quoted 10 lines
drivers/hwmon/lm90.c +1 -2
      if (data->kind == max6696) {
              lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
              config &= ~0x08;
              if (channel)
                      config |= 0x08;
-             i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
-                                       config);
+             err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,

drivers/hwmon/lm90.c static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) · line 447

Quoted 10 lines
drivers/hwmon/lm90.c +9 -0
+                                             config);
+             if (err < 0) {
+                     dev_err(&client->dev,
+                             "Failed to select remote channel %d, err %d\n",
+                             channel, err);
+                     return err;
+             }
      }
+
+     return err;

... return 0 here.

Quoted 76 lines
drivers/hwmon/lm90.c +18 -20
 }
 
 /*
@@ -702,29 +711,34 @@ static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
  * Sysfs stuff
  */
 
-static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
-                       char *buf)
+static int read_temp8(struct device *dev, int index)
 {
-     struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
      struct lm90_data *data = lm90_update_device(dev);
      int temp;
 
      if (data->kind == adt7461)
-             temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
+             temp = temp_from_u8_adt7461(data, data->temp8[index]);
      else if (data->kind == max6646)
-             temp = temp_from_u8(data->temp8[attr->index]);
+             temp = temp_from_u8(data->temp8[index]);
      else
-             temp = temp_from_s8(data->temp8[attr->index]);
+             temp = temp_from_s8(data->temp8[index]);
 
      /* +16 degrees offset for temp2 for the LM99 */
-     if (data->kind == lm99 && attr->index == 3)
+     if (data->kind == lm99 && index == 3)
              temp += 16000;
 
-     return sprintf(buf, "%d\n", temp);
+     return temp;
 }
 
-static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
-                      const char *buf, size_t count)
+static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
+                       char *buf)
+{
+     struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+
+     return sprintf(buf, "%d\n", read_temp8(dev, attr->index));
+}
+
+static int write_temp8(struct device *dev, int index, long val)
 {
      static const u8 reg[8] = {
              LM90_REG_W_LOCAL_LOW,
@@ -737,60 +751,79 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
              MAX6659_REG_W_REMOTE_EMERG,
      };
 
-     struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
      struct i2c_client *client = to_i2c_client(dev);
      struct lm90_data *data = i2c_get_clientdata(client);
-     int nr = attr->index;
-     long val;
      int err;
 
-     err = kstrtol(buf, 10, &val);
-     if (err < 0)
-             return err;
-
      /* +16 degrees offset for temp2 for the LM99 */
-     if (data->kind == lm99 && attr->index == 3)
+     if (data->kind == lm99 && index == 3)
              val -= 16000;
 
      mutex_lock(&data->update_lock);
      if (data->kind == adt7461)
-             data->temp8[nr] = temp_to_u8_adt7461(data, val);
+             data->temp8[index] = temp_to_u8_adt7461(data, val);
      else if (data->kind == max6646)
-             data->temp8[nr] = temp_to_u8(val);
+             data->temp8[index] = temp_to_u8(val);
      else

drivers/hwmon/lm90.c static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, · line 772

Quoted 10 lines
drivers/hwmon/lm90.c +4 -5
-             data->temp8[nr] = temp_to_s8(val);
-
-     lm90_select_remote_channel(client, data, nr >= 6);
-     i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
-     lm90_select_remote_channel(client, data, 0);
+             data->temp8[index] = temp_to_s8(val);
 
+     err = lm90_select_remote_channel(client, data, index >= 6);
+     err |= i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]);
+     err |= lm90_select_remote_channel(client, data, 0);

You can't use |= for error codes. Imagine that lm90_select_remote_channel() returns -EIO (-5) and i2c_smbus_write_byte_data() returns -EAGAIN (-11), err will have value -EPERM (-1) which makes no sense. You have to report errors as soon as they happen so that the error code isn't lost.

What you can do is:

        if ((err = f1(...)) ||
            (err = f2(...)) ||
            (err = f3(...))) {
                dev_err(...);
                return err;
        }
Quoted 2 lines

I think checkpatch will complain about that construct but me, I'm fine with it.

Ok, I will do it.

Quoted 108 lines
Quoted 95 lines
drivers/hwmon/lm90.c +39 -20
+     if (err)
+             dev_err(dev, "write_temp8 failed!\n");
      mutex_unlock(&data->update_lock);
+
+     return err;
+}
+
+static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
+                      const char *buf, size_t count)
+{
+     struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+     int index = attr->index;
+     long val;
+     int err;
+
+     err = kstrtol(buf, 10, &val);
+     if (err < 0)
+             return err;
+
+     err = write_temp8(dev, index, val);
+     if (err < 0)
+             return err;
+
      return count;
 }
 
-static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
-                        char *buf)
+static int read_temp11(struct device *dev, int index)
 {
-     struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
      struct lm90_data *data = lm90_update_device(dev);
      int temp;
 
      if (data->kind == adt7461)
-             temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
+             temp = temp_from_u16_adt7461(data, data->temp11[index]);
      else if (data->kind == max6646)
-             temp = temp_from_u16(data->temp11[attr->index]);
+             temp = temp_from_u16(data->temp11[index]);
      else
-             temp = temp_from_s16(data->temp11[attr->index]);
+             temp = temp_from_s16(data->temp11[index]);
 
      /* +16 degrees offset for temp2 for the LM99 */
-     if (data->kind == lm99 &&  attr->index <= 2)
+     if (data->kind == lm99 && index <= 2)
              temp += 16000;
 
-     return sprintf(buf, "%d\n", temp);
+     return temp;
 }
 
-static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
-                       const char *buf, size_t count)
+static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
+                        char *buf)
+{
+     struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+
+     return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
+}
+
+static int write_temp11(struct device *dev, int nr, int index, long val)
 {
      struct {
              u8 high;
@@ -804,18 +837,10 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
              { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL, 1 }
      };
 
-     struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
      struct i2c_client *client = to_i2c_client(dev);
      struct lm90_data *data = i2c_get_clientdata(client);
-     int nr = attr->nr;
-     int index = attr->index;
-     long val;
      int err;
 
-     err = kstrtol(buf, 10, &val);
-     if (err < 0)
-             return err;
-
      /* +16 degrees offset for temp2 for the LM99 */
      if (data->kind == lm99 && index <= 2)
              val -= 16000;
@@ -830,15 +855,38 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
      else
              data->temp11[index] = temp_to_s8(val) << 8;
 
-     lm90_select_remote_channel(client, data, reg[nr].channel);
-     i2c_smbus_write_byte_data(client, reg[nr].high,
+     err = lm90_select_remote_channel(client, data, reg[nr].channel);
+     err |= i2c_smbus_write_byte_data(client, reg[nr].high,

drivers/hwmon/lm90.c static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, · line 866

Quoted 10 lines
drivers/hwmon/lm90.c +5 -3
                                data->temp11[index] >> 8);
      if (data->flags & LM90_HAVE_REM_LIMIT_EXT)
-             i2c_smbus_write_byte_data(client, reg[nr].low,
-                                       data->temp11[index] & 0xff);
-     lm90_select_remote_channel(client, data, 0);
+             err |= i2c_smbus_write_byte_data(client, reg[nr].low,
+                                             data->temp11[index] & 0xff);
+     err |= lm90_select_remote_channel(client, data, 0);
+     if (err)
+             dev_err(dev, "write_temp11 failed !\n");

Same here, you can't use |=.

Quoted 1 line

Also, no space needed before exclamation marks in English.

Oh, you reviewed so carefully, thanks.

Quoted 35 lines
Quoted 17 lines
drivers/hwmon/lm90.c +14 -0
      mutex_unlock(&data->update_lock);
+
+     return err;
+}
+
+static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
+                       const char *buf, size_t count)
+{
+     struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+     int nr = attr->nr;
+     int index = attr->index;
+     long val;
+     int err;
+
+     err = kstrtol(buf, 10, &val);

drivers/hwmon/lm90.c static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, · line 892

Quoted 10 lines
drivers/hwmon/lm90.c +7 -0
+     if (err < 0)
+             return err;
+
+     err = write_temp11(dev, nr, index, val);
+     if (err < 0)
+             return err;
+
      return count;
 }
 

--
Jean Delvare
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html