From: Dan Carpenter <dan.carpenter@oracle.com>
To: Joel Stanley <joel@jms.id.au>,
Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>
Cc: Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
linux-hwmon@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH 1/2] hwmon: (tacho) Fix a condition in aspeed_get_fan_tach_ch_rpm()
Date: Mon, 10 Apr 2017 13:46:21 +0000 [thread overview]
Message-ID: <20170410134621.GA1918@mwanda> (raw)
What we want is for regmap_read() to return zero meaning success and
for RESULT_STATUS_MASK which is BIT(31) to be set set.
The current code is buggy in two ways. It requires both failure
conditions should be met before it fails. And if it times out then it
returns zero instead of -EIO.
Fixes: cc96f6f6d766 ("hwmon: Support for ASPEED PWM/Fan tach")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Static analysis. Not tested.
diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c
index 29010ad94208..2f22add5c73b 100644
--- a/drivers/hwmon/aspeed-pwm-tacho.c
+++ b/drivers/hwmon/aspeed-pwm-tacho.c
@@ -512,11 +512,11 @@ static u32 aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
msleep(sec);
- while (!(regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val))
- & !(val & RESULT_STATUS_MASK)) {
+ while (regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val) ||
+ !(val & RESULT_STATUS_MASK)) {
timeout++;
if (timeout > 1)
- return 0;
+ return -EIO;
msleep(sec);
}
next reply other threads:[~2017-04-10 13:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-10 13:46 Dan Carpenter [this message]
2017-04-10 20:31 ` [PATCH 1/2] hwmon: (tacho) Fix a condition in aspeed_get_fan_tach_ch_rpm() 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=20170410134621.GA1918@mwanda \
--to=dan.carpenter@oracle.com \
--cc=jaghu@google.com \
--cc=jdelvare@suse.com \
--cc=joel@jms.id.au \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
/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