From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Guenter Roeck <guenter.roeck@ericsson.com>,
Jean Delvare <khali@linux-fr.org>,
lm-sensors@lm-sensors.org
Subject: [PATCH v2] hwmon: (pmbus) Fix the logic of checking if no id is matched
Date: Wed, 31 Aug 2011 12:58:19 +0800 [thread overview]
Message-ID: <1314766699.3960.1.camel@phoenix> (raw)
If no id is matched, the mid pointer is not NULL in current implementation.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
v2:
It seems we don't need to check strlen(mid->name) here.
If there is a match, strlen(mid->name) is always not 0.
If ther is no match, comparing variable i with ARRAY_SIZE(ucd9000_id)
or ARRAY_SIZE(ucd9200_id) is enough.
drivers/hwmon/pmbus/ucd9000.c | 3 +--
drivers/hwmon/pmbus/ucd9200.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c
index 285bb15..a2d4a72 100644
--- a/drivers/hwmon/pmbus/ucd9000.c
+++ b/drivers/hwmon/pmbus/ucd9000.c
@@ -141,13 +141,12 @@ static int ucd9000_probe(struct i2c_client *client,
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];
if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
break;
}
- if (!mid || !strlen(mid->name)) {
+ if (i == ARRAY_SIZE(ucd9000_id)) {
dev_err(&client->dev, "Unsupported device\n");
return -ENODEV;
}
diff --git a/drivers/hwmon/pmbus/ucd9200.c b/drivers/hwmon/pmbus/ucd9200.c
index 786f6cd..a72e55e 100644
--- a/drivers/hwmon/pmbus/ucd9200.c
+++ b/drivers/hwmon/pmbus/ucd9200.c
@@ -68,13 +68,12 @@ static int ucd9200_probe(struct i2c_client *client,
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];
if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
break;
}
- if (!mid || !strlen(mid->name)) {
+ if (i == ARRAY_SIZE(ucd9200_id)) {
dev_err(&client->dev, "Unsupported device\n");
return -ENODEV;
}
--
1.7.4.1
next reply other threads:[~2011-08-31 4:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-31 4:58 Axel Lin [this message]
2011-08-31 10:05 ` [PATCH v2] hwmon: (pmbus) Fix the logic of checking if no id is matched Jean Delvare
2011-08-31 14:30 ` Axel Lin
2011-08-31 15:27 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1314766699.3960.1.camel@phoenix \
--to=axel.lin@gmail.com \
--cc=guenter.roeck@ericsson.com \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lm-sensors@lm-sensors.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox