Skip to contentSkip to conversation

hwmon: (lm70) Simplify show_name function

PATCH In review Guenter Roeck 4 participants 8 messages Sep 11, 2012 – Sep 17, 2012 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/4 hwmon: (lm70) Simplify show_name function

Instead of using a switch statement to determine the device name, use to_spi_device(dev)->modalias to simplify the code and reduce module size.

---
 drivers/hwmon/lm70.c |   21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/hwmon/lm70.c +1 -20
index 789753d..2d1777a 100644
@@ -124,26 +124,7 @@ 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)
 {
-	struct lm70 *p_lm70 = dev_get_drvdata(dev);
-	int ret;
-
-	switch (p_lm70->chip) {
-	case LM70_CHIP_LM70:
-		ret = sprintf(buf, "lm70\n");
-		break;
-	case LM70_CHIP_TMP121:
-		ret = sprintf(buf, "tmp121\n");
-		break;
-	case LM70_CHIP_LM71:
-		ret = sprintf(buf, "lm71\n");
-		break;
-	case LM70_CHIP_LM74:
-		ret = sprintf(buf, "lm74\n");
-		break;
-	default:
-		ret = -EINVAL;
-	}
-	return ret;
+	return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
 }
 
 static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to a message not in the archive

Hi Guenter,

Quoted 28 lines · Guenter Roeck

Instead of using a switch statement to determine the device name, use to_spi_device(dev)->modalias to simplify the code and reduce module size.

---
 drivers/hwmon/lm70.c |   21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/hwmon/lm70.c +0 -12
index 789753d..2d1777a 100644
@@ -124,26 +124,7 @@ 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)
 {
-	struct lm70 *p_lm70 = dev_get_drvdata(dev);
-	int ret;
-
-	switch (p_lm70->chip) {
-	case LM70_CHIP_LM70:
-		ret = sprintf(buf, "lm70\n");
-		break;
-	case LM70_CHIP_TMP121:
-		ret = sprintf(buf, "tmp121\n");
-		break;
-	case LM70_CHIP_LM71:
-		ret = sprintf(buf, "lm71\n");

drivers/hwmon/lm70.c static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); · line 128

Quoted 10 lines
drivers/hwmon/lm70.c +1 -8
-		break;
-	case LM70_CHIP_LM74:
-		ret = sprintf(buf, "lm74\n");
-		break;
-	default:
-		ret = -EINVAL;
-	}
-	return ret;
+	return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
 }

That's a very nice cleanup, but it makes me wonder...

Wouldn't it make sense to create the "name" attribute of spi devices at the spi core level, as we do for i2c devices? All spi-based hwmon drivers create the hwmon attributes as the spi device level, as is done for i2c devices, so that would make no difference from a user-space perspective. And this would avoid code redundancy.

If we don't want to do that, then let's offer drivers a nicer function to retrieve the spi device name, e.g. spi_dev_name(). That way, the internal implementation can change in the future without having to update all drivers.

Grant, what do you think?

Signature · 8 lines
Jean Delvare

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
#4 lore raw
In reply to a message not in the archive
Quoted 50 lines · Jean Delvare

Hi Guenter,

Quoted 28 lines · Guenter Roeck

Instead of using a switch statement to determine the device name, use to_spi_device(dev)->modalias to simplify the code and reduce module size.

---
 drivers/hwmon/lm70.c |   21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/hwmon/lm70.c +0 -12
index 789753d..2d1777a 100644
@@ -124,26 +124,7 @@ 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)
 {
-	struct lm70 *p_lm70 = dev_get_drvdata(dev);
-	int ret;
-
-	switch (p_lm70->chip) {
-	case LM70_CHIP_LM70:
-		ret = sprintf(buf, "lm70\n");
-		break;
-	case LM70_CHIP_TMP121:
-		ret = sprintf(buf, "tmp121\n");
-		break;
-	case LM70_CHIP_LM71:
-		ret = sprintf(buf, "lm71\n");

drivers/hwmon/lm70.c static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); · line 128

Quoted 10 lines
drivers/hwmon/lm70.c +1 -8
-		break;
-	case LM70_CHIP_LM74:
-		ret = sprintf(buf, "lm74\n");
-		break;
-	default:
-		ret = -EINVAL;
-	}
-	return ret;
+	return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
 }

That's a very nice cleanup, but it makes me wonder...

Wouldn't it make sense to create the "name" attribute of spi devices at the spi core level, as we do for i2c devices? All spi-based hwmon drivers create the hwmon attributes as the spi device level, as is done for i2c devices, so that would make no difference from a user-space perspective. And this would avoid code redundancy.

Quoted 5 lines

If we don't want to do that, then let's offer drivers a nicer function to retrieve the spi device name, e.g. spi_dev_name(). That way, the internal implementation can change in the future without having to update all drivers.

Adding a "name" attribute would be great, but it is not used outside hwmon, and I am not sure if we want to impose that on other users. I am obviusly fine with spi_dev_name().

Having said that, modalias is used heavily in SPI drivers, so my patches don't really do anything special.

Guenter

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html

#6 lore raw
In reply to a message not in the archive
Quoted 10 lines · Guenter Roeck
Quoted 9 lines · Jean Delvare

On Tue, 11 Sep 2012 13:52:50 -0700, Guenter Roeck wrote:
That's a very nice cleanup, but it makes me wonder...

Wouldn't it make sense to create the "name" attribute of spi devices at the spi core level, as we do for i2c devices? All spi-based hwmon drivers create the hwmon attributes as the spi device level, as is done for i2c devices, so that would make no difference from a user-space perspective. And this would avoid code redundancy.

Quoted 7 lines
Quoted 4 lines

If we don't want to do that, then let's offer drivers a nicer function to retrieve the spi device name, e.g. spi_dev_name(). That way, the internal implementation can change in the future without having to update all drivers.

Adding a "name" attribute would be great, but it is not used outside hwmon, and I am not sure if we want to impose that on other users.

That's correct, but OTOH we do exactly that for i2c devices and I am not aware of anybody complaining about that so far.

Quoted 4 lines

I am obviously fine with spi_dev_name().

Having said that, modalias is used heavily in SPI drivers, so my patches don't really do anything special.

OK, good to know. This certainly speaks in favor of at least spi_dev_name(), but we can take your patches as is for the time being, pending Grant's decision.

Signature · 8 lines
Jean Delvare

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
#8 lore raw
In reply to a message not in the archive
Quoted 22 lines · Jean Delvare
Quoted 10 lines · Guenter Roeck
Quoted 9 lines · Jean Delvare

On Tue, 11 Sep 2012 13:52:50 -0700, Guenter Roeck wrote:
That's a very nice cleanup, but it makes me wonder...

Wouldn't it make sense to create the "name" attribute of spi devices at the spi core level, as we do for i2c devices? All spi-based hwmon drivers create the hwmon attributes as the spi device level, as is done for i2c devices, so that would make no difference from a user-space perspective. And this would avoid code redundancy.

Quoted 7 lines
Quoted 4 lines

If we don't want to do that, then let's offer drivers a nicer function to retrieve the spi device name, e.g. spi_dev_name(). That way, the internal implementation can change in the future without having to update all drivers.

Adding a "name" attribute would be great, but it is not used outside hwmon, and I am not sure if we want to impose that on other users.

That's correct, but OTOH we do exactly that for i2c devices and I am not aware of anybody complaining about that so far.

Quoted 9 lines
Quoted 4 lines

I am obviously fine with spi_dev_name().

Having said that, modalias is used heavily in SPI drivers, so my patches don't really do anything special.

OK, good to know. This certainly speaks in favor of at least spi_dev_name(), but we can take your patches as is for the time being, pending Grant's decision.

That is what I would suggest we should do.

Also copying Mark Brown; he is handling much of the SPI changes nowadays.

Guenter

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://ad.doubleclick.net/clk;258768047;13503038;j?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html

author maintainer
#9 lore raw
In reply to Guenter Roeck

ping

Quoted 44 lines · Guenter Roeck

Instead of using a switch statement to determine the device name, use to_spi_device(dev)->modalias to simplify the code and reduce module size.

---
 drivers/hwmon/lm70.c |   21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/hwmon/lm70.c +1 -20
index 789753d..2d1777a 100644
@@ -124,26 +124,7 @@ 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)
 {
-	struct lm70 *p_lm70 = dev_get_drvdata(dev);
-	int ret;
-
-	switch (p_lm70->chip) {
-	case LM70_CHIP_LM70:
-		ret = sprintf(buf, "lm70\n");
-		break;
-	case LM70_CHIP_TMP121:
-		ret = sprintf(buf, "tmp121\n");
-		break;
-	case LM70_CHIP_LM71:
-		ret = sprintf(buf, "lm71\n");
-		break;
-	case LM70_CHIP_LM74:
-		ret = sprintf(buf, "lm74\n");
-		break;
-	default:
-		ret = -EINVAL;
-	}
-	return ret;
+	return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
 }
 
 static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
Signature · 1 line
1.7.9.7

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

#10 lore raw
In reply to Guenter Roeck
Quoted 1 line · Guenter Roeck

ping

All 4 patches are on my review list for this evening.

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/4
#11 lore raw
In reply to Guenter Roeck
Quoted 30 lines · Guenter Roeck

Instead of using a switch statement to determine the device name, use to_spi_device(dev)->modalias to simplify the code and reduce module size.

---
 drivers/hwmon/lm70.c |   21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
drivers/hwmon/lm70.c +0 -14
index 789753d..2d1777a 100644
@@ -124,26 +124,7 @@ 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)
 {
-	struct lm70 *p_lm70 = dev_get_drvdata(dev);
-	int ret;
-
-	switch (p_lm70->chip) {
-	case LM70_CHIP_LM70:
-		ret = sprintf(buf, "lm70\n");
-		break;
-	case LM70_CHIP_TMP121:
-		ret = sprintf(buf, "tmp121\n");
-		break;
-	case LM70_CHIP_LM71:
-		ret = sprintf(buf, "lm71\n");
-		break;
-	case LM70_CHIP_LM74:

drivers/hwmon/lm70.c static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL); · line 130

Quoted 10 lines
drivers/hwmon/lm70.c +1 -6
-		ret = sprintf(buf, "lm74\n");
-		break;
-	default:
-		ret = -EINVAL;
-	}
-	return ret;
+	return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
 }
 
 static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);

Nice cleanup.

Signature · 6 lines
Jean Delvare

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