From patchwork Mon Apr 10 13:46:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 9672687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EEE21600CB for ; Mon, 10 Apr 2017 13:47:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E284927D4D for ; Mon, 10 Apr 2017 13:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5E0C28449; Mon, 10 Apr 2017 13:47:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FE8B27D4D for ; Mon, 10 Apr 2017 13:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752941AbdDJNrU (ORCPT ); Mon, 10 Apr 2017 09:47:20 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:45875 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752760AbdDJNrT (ORCPT ); Mon, 10 Apr 2017 09:47:19 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3ADkVvm012933 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Apr 2017 13:46:31 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v3ADkUJM025026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Apr 2017 13:46:31 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3ADkT7e016307; Mon, 10 Apr 2017 13:46:30 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 10 Apr 2017 06:46:29 -0700 Date: Mon, 10 Apr 2017 16:46:21 +0300 From: Dan Carpenter To: Joel Stanley , Jaghathiswari Rankappagounder Natarajan Cc: Jean Delvare , Guenter Roeck , 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() Message-ID: <20170410134621.GA1918@mwanda> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Static analysis. Not tested. -- To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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); }