Skip to contentSkip to conversation

hwmon/lm70: Add a name attribute

PATCH In review Jean Delvare 4 participants 5 messages Aug 17, 2007 – Aug 26, 2007 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon/lm70: Add a name attribute

Add a name attribute to the lm70 devices. This is required for libsensors to recognize them.

Also drop the "+" before the temperature value, even though it did not cause problems to libsensors, other hardware monitoring drivers don't print it, so it's more consistent that way.

---
 drivers/hwmon/lm70.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/hwmon/lm70.c +13 -2
@@ -81,7 +81,7 @@ static ssize_t lm70_sense_temp(struct de
 	 * So it's equivalent to multiplying by 0.25 * 1000 = 250.
 	 */
 	val = ((int)raw/32) * 250;
-	status = sprintf(buf, "%+d\n", val); /* millidegrees Celsius */
+	status = sprintf(buf, "%d\n", val); /* millidegrees Celsius */
 out:
 	up(&p_lm70->sem);
 	return status;
@@ -89,6 +89,14 @@ out:
 
 static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL);
 
+static ssize_t lm70_show_name(struct device *dev, struct device_attribute
+			      *devattr, char *buf)
+{
+	return sprintf(buf, "lm70\n");
+}
+
+static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
+
 /*----------------------------------------------------------------------*/
 
 static int __devinit lm70_probe(struct spi_device *spi)
@@ -115,7 +123,8 @@ static int __devinit lm70_probe(struct s
 	}
 	dev_set_drvdata(&spi->dev, p_lm70);
 
-	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))) {
+	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
+	 || (status = device_create_file(&spi->dev, &dev_attr_name))) {
 		dev_dbg(&spi->dev, "device_create_file failure.\n");
 		goto out_dev_create_file_failed;
 	}
@@ -123,6 +132,7 @@ static int __devinit lm70_probe(struct s
 	return 0;
 
 out_dev_create_file_failed:
+	device_remove_file(&spi->dev, &dev_attr_temp1_input);
 	hwmon_device_unregister(p_lm70->cdev);
 out_dev_reg_failed:
 	dev_set_drvdata(&spi->dev, NULL);
@@ -135,6 +145,7 @@ static int __devexit lm70_remove(struct 
 	struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
 
 	device_remove_file(&spi->dev, &dev_attr_temp1_input);
+	device_remove_file(&spi->dev, &dev_attr_name);
 	hwmon_device_unregister(p_lm70->cdev);
 	dev_set_drvdata(&spi->dev, NULL);
 	kfree(p_lm70);
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jean Delvare

Add a name attribute to the lm70 devices. This is required for libsensors to recognize them.

Also drop the "+" before the temperature value, even though it did not cause problems to libsensors, other hardware monitoring drivers don't print it, so it's more consistent that way.

Looks good to me.

Quoted 51 lines
---
 drivers/hwmon/lm70.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/hwmon/lm70.c +12 -2
@@ -81,7 +81,7 @@ static ssize_t lm70_sense_temp(struct de
 	 * So it's equivalent to multiplying by 0.25 * 1000 = 250.
 	 */
 	val = ((int)raw/32) * 250;
-	status = sprintf(buf, "%+d\n", val); /* millidegrees Celsius */
+	status = sprintf(buf, "%d\n", val); /* millidegrees Celsius */
 out:
 	up(&p_lm70->sem);
 	return status;
@@ -89,6 +89,14 @@ out:
 
 static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL);
 
+static ssize_t lm70_show_name(struct device *dev, struct device_attribute
+			      *devattr, char *buf)
+{
+	return sprintf(buf, "lm70\n");
+}
+
+static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
+
 /*----------------------------------------------------------------------*/
 
 static int __devinit lm70_probe(struct spi_device *spi)
@@ -115,7 +123,8 @@ static int __devinit lm70_probe(struct s
 	}
 	dev_set_drvdata(&spi->dev, p_lm70);
 
-	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))) {
+	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
+	 || (status = device_create_file(&spi->dev, &dev_attr_name))) {
 		dev_dbg(&spi->dev, "device_create_file failure.\n");
 		goto out_dev_create_file_failed;
 	}
@@ -123,6 +132,7 @@ static int __devinit lm70_probe(struct s
 	return 0;
 
 out_dev_create_file_failed:
+	device_remove_file(&spi->dev, &dev_attr_temp1_input);
 	hwmon_device_unregister(p_lm70->cdev);
 out_dev_reg_failed:
 	dev_set_drvdata(&spi->dev, NULL);

drivers/hwmon/lm70.c static int __devexit lm70_remove(struct · line 151

Quoted 7 lines
drivers/hwmon/lm70.c +1 -0
@@ -135,6 +145,7 @@ static int __devexit lm70_remove(struct 
 	struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
 
 	device_remove_file(&spi->dev, &dev_attr_temp1_input);
+	device_remove_file(&spi->dev, &dev_attr_name);
 	hwmon_device_unregister(p_lm70->cdev);
 	dev_set_drvdata(&spi->dev, NULL);
 	kfree(p_lm70);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

Acked-by on v1 1/1
#2 lore raw
In reply to Jean Delvare
Quoted 8 lines

Add a name attribute to the lm70 devices. This is required for libsensors to recognize them.

Also drop the "+" before the temperature value, even though it did not cause problems to libsensors, other hardware monitoring drivers don't print it, so it's more consistent that way.

Yup, fine with me.

Quoted 41 lines
---
 drivers/hwmon/lm70.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/hwmon/lm70.c +11 -2
@@ -81,7 +81,7 @@ static ssize_t lm70_sense_temp(struct de
 	 * So it's equivalent to multiplying by 0.25 * 1000 = 250.
 	 */
 	val = ((int)raw/32) * 250;
-	status = sprintf(buf, "%+d\n", val); /* millidegrees Celsius */
+	status = sprintf(buf, "%d\n", val); /* millidegrees Celsius */
 out:
 	up(&p_lm70->sem);
 	return status;
@@ -89,6 +89,14 @@ out:
 
 static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL);
 
+static ssize_t lm70_show_name(struct device *dev, struct device_attribute
+			      *devattr, char *buf)
+{
+	return sprintf(buf, "lm70\n");
+}
+
+static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
+
 /*----------------------------------------------------------------------*/
 
 static int __devinit lm70_probe(struct spi_device *spi)
@@ -115,7 +123,8 @@ static int __devinit lm70_probe(struct s
 	}
 	dev_set_drvdata(&spi->dev, p_lm70);
 
-	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))) {
+	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
+	 || (status = device_create_file(&spi->dev, &dev_attr_name))) {
 		dev_dbg(&spi->dev, "device_create_file failure.\n");
 		goto out_dev_create_file_failed;
 	}

drivers/hwmon/lm70.c static int __devinit lm70_probe(struct s · line 135

Quoted 4 lines
drivers/hwmon/lm70.c +1 -0
@@ -123,6 +132,7 @@ static int __devinit lm70_probe(struct s
 	return 0;
 
 out_dev_create_file_failed:
+	device_remove_file(&spi->dev, &dev_attr_temp1_input);

Ah. Thanks!

drivers/hwmon/lm70.c static int __devexit lm70_remove(struct · line 151

Quoted 13 lines
drivers/hwmon/lm70.c +1 -0
 	hwmon_device_unregister(p_lm70->cdev);
 out_dev_reg_failed:
 	dev_set_drvdata(&spi->dev, NULL);
@@ -135,6 +145,7 @@ static int __devexit lm70_remove(struct 
 	struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
 
 	device_remove_file(&spi->dev, &dev_attr_temp1_input);
+	device_remove_file(&spi->dev, &dev_attr_name);
 	hwmon_device_unregister(p_lm70->cdev);
 	dev_set_drvdata(&spi->dev, NULL);
 	kfree(p_lm70);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
In reply to Jean Delvare

Hi Kaiwan,

Quoted 13 lines · Kaiwan N Billimoria
Quoted 13 lines
drivers/hwmon/lm70.c +2 -1
@@ -115,7 +123,8 @@ static int __devinit lm70_probe(struct s
 	}
 	dev_set_drvdata(&spi->dev, p_lm70);
 
-	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))) {
+	if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
+	 || (status = device_create_file(&spi->dev, &dev_attr_name))) {
 		dev_dbg(&spi->dev, "device_create_file failure.\n");
 		goto out_dev_create_file_failed;
 	}
@@ -123,6 +132,7 @@ static int __devinit lm70_probe(struct s
 	return 0;
 
Quoted 8 lines

drivers/hwmon/lm70.c static int __devinit lm70_probe(struct s · line 135

Quoted 2 lines
drivers/hwmon/lm70.c +1 -0
 out_dev_create_file_failed:
+	device_remove_file(&spi->dev, &dev_attr_temp1_input);

Ah. Thanks!

Quoted 3 lines
drivers/hwmon/lm70.c +0 -0
 	hwmon_device_unregister(p_lm70->cdev);
 out_dev_reg_failed:
 	dev_set_drvdata(&spi->dev, NULL);

Just to make it clear: there was no bug there. This call to device_remove_file() is now needed in the case where the temp1_input file would be successfully created but the name file creation would fail.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#4 lore raw
In reply to Jean Delvare
Quoted 8 lines · Hans de Goede
Quoted 7 lines · Jean Delvare

Add a name attribute to the lm70 devices. This is required for libsensors to recognize them.

Also drop the "+" before the temperature value, even though it did not cause problems to libsensors, other hardware monitoring drivers don't print it, so it's more consistent that way.

Quoted 5 lines
Quoted 1 line

Looks good to me.

Applied to hwmon-2.6.git/testing, thanks.

Signature · 8 lines
Mark M. Hoffman
[email protected]


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors