From patchwork Wed Nov 23 11:34:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Etnestad X-Patchwork-Id: 9443031 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 D1F036075F for ; Wed, 23 Nov 2016 11:42:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC09A205AB for ; Wed, 23 Nov 2016 11:42:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0ACD23E64; Wed, 23 Nov 2016 11:42:34 +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 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 EB7B1205AB for ; Wed, 23 Nov 2016 11:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935453AbcKWLmd (ORCPT ); Wed, 23 Nov 2016 06:42:33 -0500 Received: from mailcluster2.itpays.net ([193.107.29.212]:35665 "EHLO mailcluster2.itpays.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934582AbcKWLmd (ORCPT ); Wed, 23 Nov 2016 06:42:33 -0500 Received: from [10.10.48.149] (unknown [195.159.183.42]) by mailcluster2.itpays.net (Postfix) with ESMTPA id 22FF03199579 for ; Wed, 23 Nov 2016 12:34:58 +0100 (CET) To: linux-hwmon@vger.kernel.org From: Martin Etnestad Subject: hwmon: (adt7470) fix checking of num_temp_sensors Message-ID: Date: Wed, 23 Nov 2016 12:34:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 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 The ADT7470 driver uses num_temp_sensors to check whether or not it actually needs to read the temperature registers. However, the check currently has a broken comparison: "num_temp_sensors >= 0" instead of "num_temp_sensors == 0". This causes the driver to only read the temperature registers _once_ because num_temp_sensors gets set to a non-negative number after the check, in the same function. Additionally, the check is currently done _after_ the measurement sequence has been completed. The check should be done before the measurement sequence is initiated, as it can be skipped altogether if num_temp_sensors is 0. This patch fixes the comparison and moves the check. Signed-off-by: Martin Etnestad --- drivers/hwmon/adt7470.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) pwm_cfg[1] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(2)); @@ -243,10 +247,6 @@ static int adt7470_read_temperatures(struct i2c_client *client, return -EAGAIN; } - /* Only count fans if we have to */ - if (data->num_temp_sensors >= 0) - return 0; - for (i = 0; i < ADT7470_TEMP_COUNT; i++) { data->temp[i] = i2c_smbus_read_byte_data(client, ADT7470_TEMP_REG(i)); diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index f5da39a..d1f9a54 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -201,6 +201,10 @@ static int adt7470_read_temperatures(struct i2c_client *client, int i; u8 cfg, pwm[4], pwm_cfg[2]; + /* only read sensors if we have to */ + if (data->num_temp_sensors == 0) + return 0; + /* save pwm[1-4] config register */ pwm_cfg[0] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(0));