hwmon: (ucd9000/ucd9200) Optimize array walk
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.
Signed-off-by Jean Delvare <[email protected]>
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
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.
Signed-off-by Jean Delvare <[email protected]>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