Skip to contentSkip to conversation

hwmon: (ucd9000/ucd9200) Optimize array walk

lm-sensors Jean Delvare 2 participants 2 messages Aug 31, 2011 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

Rewrite the loop walking the id array during probe. The new code is better adapted to a null-terminated array, and is also clearer and more efficient than the original.

Cc Axel Lin <[email protected]>
Cc Guenter Roeck <[email protected]>

---
Inspired by a previous patch from Axel.

 drivers/hwmon/pmbus/ucd9000.c |    6 ++----
 drivers/hwmon/pmbus/ucd9200.c |    6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)
drivers/hwmon/pmbus/ucd9000.c +2 -4
@@ -141,13 +141,11 @@ static int ucd9000_probe(struct i2c_clie
 	block_buffer[ret] = '\0';
 	dev_info(&client->dev, "Device ID %s\n", block_buffer);
 
-	mid = NULL;
-	for (i = 0; i < ARRAY_SIZE(ucd9000_id); i++) {
-		mid = &ucd9000_id[i];
+	for (mid = ucd9000_id; mid->name[0]; mid++) {
 		if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
 			break;
 	}
-	if (!mid || !strlen(mid->name)) {
+	if (!mid->name[0]) {
 		dev_err(&client->dev, "Unsupported device\n");
 		return -ENODEV;
 	}
drivers/hwmon/pmbus/ucd9200.c +2 -4
@@ -68,13 +68,11 @@ static int ucd9200_probe(struct i2c_clie
 	block_buffer[ret] = '\0';
 	dev_info(&client->dev, "Device ID %s\n", block_buffer);
 
-	mid = NULL;
-	for (i = 0; i < ARRAY_SIZE(ucd9200_id); i++) {
-		mid = &ucd9200_id[i];
+	for (mid = ucd9200_id; mid->name[0]; mid++) {
 		if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
 			break;
 	}
-	if (!mid || !strlen(mid->name)) {
+	if (!mid->name[0]) {
 		dev_err(&client->dev, "Unsupported device\n");
 		return -ENODEV;
 	}
Signature · 6 lines
Jean Delvare

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

Rewrite the loop walking the id array during probe. The new code is better adapted to a null-terminated array, and is also clearer and more efficient than the original.

Cc Axel Lin <[email protected]>
Cc Guenter Roeck <[email protected]>

---
Inspired by a previous patch from Axel.

Looks good. I'll (hopefully) test it tonight to be sure, but I don't see any problems with it, so consider it applied.

I'll make the same changes in the zl6100 driver.

Thanks,
Guenter

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