From patchwork Tue Aug 7 08:57:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72A6413BB for ; Tue, 7 Aug 2018 08:58:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61E8329B73 for ; Tue, 7 Aug 2018 08:58:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 563FF29B7C; Tue, 7 Aug 2018 08:58:38 +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.3 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,URIBL_SBL 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 ABDB029B73 for ; Tue, 7 Aug 2018 08:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727011AbeHGLL4 (ORCPT ); Tue, 7 Aug 2018 07:11:56 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.215]:42222 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727669AbeHGLL4 (ORCPT ); Tue, 7 Aug 2018 07:11:56 -0400 Received: from [67.219.246.196] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-3.bemta.az-c.us-east-1.aws.symcld.net id 49/4C-01625-B3F596B5; Tue, 07 Aug 2018 08:58:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsUyLfyHiK51fGa 0wZy/khbtr7cyOjB6fN4kF8AYxZqZl5RfkcCa8Wz2WbaCd7YVe56eZmlg7DTuYuTkEBKYwyhx sF8Pwv7JKHF+gg2IzSZgKjH91UJGEFtEQEViy7o1zF2MXBzMAqsYJb4vO8AEkhAWiJBY19zEA mKzCKhK3J6zCsjm4OAVcJS4OCURJCwhIC9x+E0TK4jNKeAkcel5GyPELkeJjitLWCBsTYnnPd 8ZIeqDJW5fv8I8gZF3ASPDKkbTpKLM9IyS3MTMHF1DAwNdQ0MjXVNdI3O9xCrdZL3SYt3UxOI SXUO9xPJiveLK3OScFL281JJNjMAgYQCCHYwfZqUeYpTkYFIS5S1SzowW4kvKT6nMSCzOiC8q zUktPsQow8GhJMH7LhYoJ1iUmp5akZaZAwxXmLQEB4+SCO9WkDRvcUFibnFmOkTqFKMlx6nmn knMHH/eTwWS+7qnTWIWYsnLz0uVEucViANqEABpyCjNgxsHi6lLjLJSwryMQAcK8RSkFuVmlq DKv2IU52BUEub9DrKWJzOvBG7rK6CDmIAOeqMNdlBJIkJKqoGRdcHpshkX44RP+uYfVdMS+Ll e39vsoLTrGpGze5lkVP7EM5ZrLKo/fWnCVYvF9R5bGSU27Ni34vJJ5tNCfKcvLNr37ICxLdNn 5ZenvmT2m79QnDlPZXmE5IvlS83akpqzZeSELXeVSVWZPL9rsMfM4qW/y9lgZxZnwanfXN9wL NtgdYl7i4SaEktxRqKhFnNRcSIA3iWqv6QCAAA= X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-19.tower-404.messagelabs.com!1533632314!2238425!1 X-Originating-IP: [150.87.248.20] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.9.15; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26720 invoked from network); 7 Aug 2018 08:58:35 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-19.tower-404.messagelabs.com with SMTP; 7 Aug 2018 08:58:35 -0000 Received: from swim-manx.rd.allied-telesis.co.jp ([150.87.21.50]) by TKY-DS01.at.lc with Microsoft SMTPSVC(8.0.9200.16384); Tue, 7 Aug 2018 17:58:33 +0900 Received: from ikegami-pc.rd.allied-telesis.co.jp by swim-manx.rd.allied-telesis.co.jp (AlliedTelesis SMTPRS 1.3 pl 1 ++E6B86F8C687C6288D9B5559052954DC9) with ESMTP id ; Tue, 7 Aug 2018 17:58:33 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH 1/4] hwmon: (adt7475) Split device update function to measure and limits Date: Tue, 7 Aug 2018 17:57:30 +0900 Message-Id: <20180807085733.28756-2-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> References: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 08:58:33.0927 (UTC) FILETIME=[D21EF570:01D42E2C] 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 function has the measure update part and limits and settings part. And those parts can be split so split them for a maintainability. Signed-off-by: Tokunori Ikegami Cc: Guenter Roeck Cc: Chris Packham Cc: linux-hwmon@vger.kernel.org --- drivers/hwmon/adt7475.c | 200 ++++++++++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 93 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 9ef84998c7f3..270cabb49677 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1658,123 +1658,137 @@ static void adt7475_read_pwm(struct i2c_client *client, int index) } } -static struct adt7475_data *adt7475_update_device(struct device *dev) +static void adt7475_update_measure(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct adt7475_data *data = i2c_get_clientdata(client); u16 ext; int i; - mutex_lock(&data->lock); + data->alarms = adt7475_read(REG_STATUS2) << 8; + data->alarms |= adt7475_read(REG_STATUS1); + + ext = (adt7475_read(REG_EXTEND2) << 8) | + adt7475_read(REG_EXTEND1); + for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { + if (!(data->has_voltage & (1 << i))) + continue; + data->voltage[INPUT][i] = + (adt7475_read(VOLTAGE_REG(i)) << 2) | + ((ext >> (i * 2)) & 3); + } - /* Measurement values update every 2 seconds */ - if (time_after(jiffies, data->measure_updated + HZ * 2) || - !data->valid) { - data->alarms = adt7475_read(REG_STATUS2) << 8; - data->alarms |= adt7475_read(REG_STATUS1); - - ext = (adt7475_read(REG_EXTEND2) << 8) | - adt7475_read(REG_EXTEND1); - for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { - if (!(data->has_voltage & (1 << i))) - continue; - data->voltage[INPUT][i] = - (adt7475_read(VOLTAGE_REG(i)) << 2) | - ((ext >> (i * 2)) & 3); - } + for (i = 0; i < ADT7475_TEMP_COUNT; i++) + data->temp[INPUT][i] = + (adt7475_read(TEMP_REG(i)) << 2) | + ((ext >> ((i + 5) * 2)) & 3); - for (i = 0; i < ADT7475_TEMP_COUNT; i++) - data->temp[INPUT][i] = - (adt7475_read(TEMP_REG(i)) << 2) | - ((ext >> ((i + 5) * 2)) & 3); + if (data->has_voltage & (1 << 5)) { + data->alarms |= adt7475_read(REG_STATUS4) << 24; + ext = adt7475_read(REG_EXTEND3); + data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 | + ((ext >> 4) & 3); + } - if (data->has_voltage & (1 << 5)) { - data->alarms |= adt7475_read(REG_STATUS4) << 24; - ext = adt7475_read(REG_EXTEND3); - data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 | - ((ext >> 4) & 3); - } + for (i = 0; i < ADT7475_TACH_COUNT; i++) { + if (i == 3 && !data->has_fan4) + continue; + data->tach[INPUT][i] = + adt7475_read_word(client, TACH_REG(i)); + } - for (i = 0; i < ADT7475_TACH_COUNT; i++) { - if (i == 3 && !data->has_fan4) - continue; - data->tach[INPUT][i] = - adt7475_read_word(client, TACH_REG(i)); - } + /* Updated by hw when in auto mode */ + for (i = 0; i < ADT7475_PWM_COUNT; i++) { + if (i == 1 && !data->has_pwm2) + continue; + data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); + } - /* Updated by hw when in auto mode */ - for (i = 0; i < ADT7475_PWM_COUNT; i++) { - if (i == 1 && !data->has_pwm2) - continue; - data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); - } + if (data->has_vid) + data->vid = adt7475_read(REG_VID) & 0x3f; +} - if (data->has_vid) - data->vid = adt7475_read(REG_VID) & 0x3f; +static void adt7475_update_limits(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct adt7475_data *data = i2c_get_clientdata(client); + int i; - data->measure_updated = jiffies; + data->config4 = adt7475_read(REG_CONFIG4); + data->config5 = adt7475_read(REG_CONFIG5); + + for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { + if (!(data->has_voltage & (1 << i))) + continue; + /* Adjust values so they match the input precision */ + data->voltage[MIN][i] = + adt7475_read(VOLTAGE_MIN_REG(i)) << 2; + data->voltage[MAX][i] = + adt7475_read(VOLTAGE_MAX_REG(i)) << 2; } - /* Limits and settings, should never change update every 60 seconds */ - if (time_after(jiffies, data->limits_updated + HZ * 60) || - !data->valid) { - data->config4 = adt7475_read(REG_CONFIG4); - data->config5 = adt7475_read(REG_CONFIG5); - - for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { - if (!(data->has_voltage & (1 << i))) - continue; - /* Adjust values so they match the input precision */ - data->voltage[MIN][i] = - adt7475_read(VOLTAGE_MIN_REG(i)) << 2; - data->voltage[MAX][i] = - adt7475_read(VOLTAGE_MAX_REG(i)) << 2; - } + if (data->has_voltage & (1 << 5)) { + data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2; + data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2; + } - if (data->has_voltage & (1 << 5)) { - data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2; - data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2; - } + for (i = 0; i < ADT7475_TEMP_COUNT; i++) { + /* Adjust values so they match the input precision */ + data->temp[MIN][i] = + adt7475_read(TEMP_MIN_REG(i)) << 2; + data->temp[MAX][i] = + adt7475_read(TEMP_MAX_REG(i)) << 2; + data->temp[AUTOMIN][i] = + adt7475_read(TEMP_TMIN_REG(i)) << 2; + data->temp[THERM][i] = + adt7475_read(TEMP_THERM_REG(i)) << 2; + data->temp[OFFSET][i] = + adt7475_read(TEMP_OFFSET_REG(i)); + } + adt7475_read_hystersis(client); - for (i = 0; i < ADT7475_TEMP_COUNT; i++) { - /* Adjust values so they match the input precision */ - data->temp[MIN][i] = - adt7475_read(TEMP_MIN_REG(i)) << 2; - data->temp[MAX][i] = - adt7475_read(TEMP_MAX_REG(i)) << 2; - data->temp[AUTOMIN][i] = - adt7475_read(TEMP_TMIN_REG(i)) << 2; - data->temp[THERM][i] = - adt7475_read(TEMP_THERM_REG(i)) << 2; - data->temp[OFFSET][i] = - adt7475_read(TEMP_OFFSET_REG(i)); - } - adt7475_read_hystersis(client); + for (i = 0; i < ADT7475_TACH_COUNT; i++) { + if (i == 3 && !data->has_fan4) + continue; + data->tach[MIN][i] = + adt7475_read_word(client, TACH_MIN_REG(i)); + } - for (i = 0; i < ADT7475_TACH_COUNT; i++) { - if (i == 3 && !data->has_fan4) - continue; - data->tach[MIN][i] = - adt7475_read_word(client, TACH_MIN_REG(i)); - } + for (i = 0; i < ADT7475_PWM_COUNT; i++) { + if (i == 1 && !data->has_pwm2) + continue; + data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); + data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); + /* Set the channel and control information */ + adt7475_read_pwm(client, i); + } - for (i = 0; i < ADT7475_PWM_COUNT; i++) { - if (i == 1 && !data->has_pwm2) - continue; - data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); - data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); - /* Set the channel and control information */ - adt7475_read_pwm(client, i); - } + data->range[0] = adt7475_read(TEMP_TRANGE_REG(0)); + data->range[1] = adt7475_read(TEMP_TRANGE_REG(1)); + data->range[2] = adt7475_read(TEMP_TRANGE_REG(2)); +} + +static struct adt7475_data *adt7475_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct adt7475_data *data = i2c_get_clientdata(client); - data->range[0] = adt7475_read(TEMP_TRANGE_REG(0)); - data->range[1] = adt7475_read(TEMP_TRANGE_REG(1)); - data->range[2] = adt7475_read(TEMP_TRANGE_REG(2)); + mutex_lock(&data->lock); + + /* Measurement values update every 2 seconds */ + if (time_after(jiffies, data->measure_updated + HZ * 2) || + !data->valid) { + adt7475_update_measure(dev); + data->measure_updated = jiffies; + } + /* Limits and settings, should never change update every 60 seconds */ + if (time_after(jiffies, data->limits_updated + HZ * 60) || + !data->valid) { + adt7475_update_limits(dev); data->limits_updated = jiffies; data->valid = 1; } - mutex_unlock(&data->lock); return data; From patchwork Tue Aug 7 08:57:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 913C413BB for ; Tue, 7 Aug 2018 08:58:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F28829B73 for ; Tue, 7 Aug 2018 08:58:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 730BB29B7C; Tue, 7 Aug 2018 08:58:45 +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.3 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,URIBL_SBL 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 11DE629B73 for ; Tue, 7 Aug 2018 08:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726414AbeHGLMD (ORCPT ); Tue, 7 Aug 2018 07:12:03 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.112]:17971 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727669AbeHGLMD (ORCPT ); Tue, 7 Aug 2018 07:12:03 -0400 Received: from [67.219.250.196] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-b.us-west-2.aws.symcld.net id E1/61-15908-34F596B5; Tue, 07 Aug 2018 08:58:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42KZFv5DRNc5PjP aYMpJdov211sZHRg9Pm+SC2CMYs3MS8qvSGDN2DrhIUtBE1fFlnMnWRsYd3N0MXJxCAnMYZRY Onk3E4Tzk1Hi2fPJbF2MnBxsAqYS018tZASxRQRUJLasW8MMUsQssIpR4vuyA0wgCWEBT4k3b UfZQWwWAVWJvyd7WbsYOTh4BRwlenfVgYQlBOQlDr9pYgWxOQWcJC49bwObKQRU0nFlCQuErS nxvOc7I0irhECwxJdvdhMYeRcwMqxitEgqykzPKMlNzMzRNTQw0DU0NNI1NDbRNTKw0Eus0k3 SKy3WLU8tLtE10kssL9YrrsxNzknRy0st2cQIDBYGINjBePVQyiFGSQ4mJVHeIuXMaCG+pPyU yozE4oz4otKc1OJDjDIcHEoSvHpxQDnBotT01Iq0zBxg2MKkJTh4lER4t8YCpXmLCxJzizPTI VKnGI05/ryfOomZY1/3tEnMQix5+XmpUuK8tSCTBEBKM0rz4AbB4ukSo6yUMC8j0GlCPAWpRb mZJajyrxjFORiVhHmNQabwZOaVwO17BXQKE9Apb7TBTilJREhJNTCuZdW8dC3s5IVNk/IurtI otZXWK/ecf1Wt9UDq8xtnXkiu1v6z6I7v9jw7szcTn8oxLQtbpuD6k+H0NXPVSfqvX6/K2JrX E57w/V7EnxLuScYzzki3zFsnmyXQks9utGOdiKldQquszMOXpZNELXmCXsl9/Tgn+PuMNT6vU 9cmp1f931ah+HCdEktxRqKhFnNRcSIAHmChQaICAAA= X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-23.tower-344.messagelabs.com!1533632322!2726792!1 X-Originating-IP: [150.87.248.20] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.9.15; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22247 invoked from network); 7 Aug 2018 08:58:42 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-23.tower-344.messagelabs.com with SMTP; 7 Aug 2018 08:58:42 -0000 Received: from swim-manx.rd.allied-telesis.co.jp ([150.87.21.50]) by TKY-DS01.at.lc with Microsoft SMTPSVC(8.0.9200.16384); Tue, 7 Aug 2018 17:58:41 +0900 Received: from ikegami-pc.rd.allied-telesis.co.jp by swim-manx.rd.allied-telesis.co.jp (AlliedTelesis SMTPRS 1.3 pl 1 ++E6B86F8C687C6288D9B5559052954DC9) with ESMTP id ; Tue, 7 Aug 2018 17:58:41 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH 2/4] hwmon: (adt7475) Change valid parameter to bool type Date: Tue, 7 Aug 2018 17:57:31 +0900 Message-Id: <20180807085733.28756-3-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> References: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 08:58:41.0919 (UTC) FILETIME=[D6E270F0:01D42E2C] 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 Currently the valid paramter is char type but the type is not required. So change the parameter to boot type correctly. Signed-off-by: Tokunori Ikegami Cc: Guenter Roeck Cc: Chris Packham Cc: linux-hwmon@vger.kernel.org --- drivers/hwmon/adt7475.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 270cabb49677..5f03a93632c3 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -195,7 +195,7 @@ struct adt7475_data { unsigned long measure_updated; unsigned long limits_updated; - char valid; + bool valid; u8 config4; u8 config5; @@ -1780,6 +1780,7 @@ static struct adt7475_data *adt7475_update_device(struct device *dev) !data->valid) { adt7475_update_measure(dev); data->measure_updated = jiffies; + data->valid = true; } /* Limits and settings, should never change update every 60 seconds */ @@ -1787,7 +1788,7 @@ static struct adt7475_data *adt7475_update_device(struct device *dev) !data->valid) { adt7475_update_limits(dev); data->limits_updated = jiffies; - data->valid = 1; + data->valid = true; } mutex_unlock(&data->lock); From patchwork Tue Aug 7 08:57:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69C331390 for ; Tue, 7 Aug 2018 08:58:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5960329B73 for ; Tue, 7 Aug 2018 08:58:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DE9729B76; Tue, 7 Aug 2018 08:58:51 +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.3 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,URIBL_SBL 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 082C329B83 for ; Tue, 7 Aug 2018 08:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732703AbeHGLMI (ORCPT ); Tue, 7 Aug 2018 07:12:08 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.210]:61577 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727669AbeHGLMI (ORCPT ); Tue, 7 Aug 2018 07:12:08 -0400 Received: from [67.219.247.52] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-3.bemta.az-d.us-east-1.aws.symcld.net id 83/5D-01612-74F596B5; Tue, 07 Aug 2018 08:58:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42KZFv5DRNc9PjP a4N03NYv211sZHRg9Pm+SC2CMYs3MS8qvSGDNuHbqJXvBUoeKW4vnMzcwNpt0MXJxCAnMYZTo ndLKDOH8ZJT4c/0KkMPJwSZgKjH91UJGEFtEQEViy7o1YEXMAqsYJb4vO8AEkhAWCJbYtmAem M0ioCrRd+geSxcjBwevgKPE+nmVIGEJAXmJw2+aWEFsTgEniUvP28BmCgGVdFxZwgJha0o87/ nOCFEfLPFw6ySWCYy8CxgZVjGaJRVlpmeU5CZm5ugaGhjoGhoa6VroGpoa6SVW6abolRbrpiY Wl+ga6iWWF+sVV+Ym56To5aWWbGIEhgoDEOxg7JmdeohRkoNJSZS3SDkzWogvKT+lMiOxOCO+ qDQntfgQowwHh5IEr14cUE6wKDU9tSItMwcYtDBpCQ4eJRHeHJA0b3FBYm5xZjpE6hSjMcef9 1MnMXPs6542iVmIJS8/L1VKnLcWpFQApDSjNA9uECyaLjHKSgnzMgKdJsRTkFqUm1mCKv+KUZ yDUUmY93ss0BSezLwSuH2vgE5hAjrljTbYKSWJCCmpBkbPOVybZjddu2D+p+nSVZUt/+dnhl0 93PBjS8L6W5tn/A2qyd/ynTd5v+AB3oe6U9jeXP5iccHvs3Vt5SWPH9Kzg1mYEuIYNl2bUbFF /0BOT+mEn0ueKs7cs2hDsM0LtqePrZ7Ga/6rSC6vDt3M11j7093n3Z2VC1e5yfJ3/o/gMWj4f eKwZb+LEktxRqKhFnNRcSIAjKoe86ECAAA= X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-17.tower-424.messagelabs.com!1533632326!1613165!1 X-Originating-IP: [150.87.248.20] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.9.15; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7750 invoked from network); 7 Aug 2018 08:58:47 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-17.tower-424.messagelabs.com with SMTP; 7 Aug 2018 08:58:47 -0000 Received: from swim-manx.rd.allied-telesis.co.jp ([150.87.21.50]) by TKY-DS01.at.lc with Microsoft SMTPSVC(8.0.9200.16384); Tue, 7 Aug 2018 17:58:46 +0900 Received: from ikegami-pc.rd.allied-telesis.co.jp by swim-manx.rd.allied-telesis.co.jp (AlliedTelesis SMTPRS 1.3 pl 1 ++E6B86F8C687C6288D9B5559052954DC9) with ESMTP id ; Tue, 7 Aug 2018 17:58:45 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH 3/4] hwmon: (adt7475) Change update functions to add error handling Date: Tue, 7 Aug 2018 17:57:32 +0900 Message-Id: <20180807085733.28756-4-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> References: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 08:58:46.0155 (UTC) FILETIME=[D968CDB0:01D42E2C] 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 I2C SMBus is sometimes possible to return error codes. And at the error case the measurement values are updated incorrectly. The sensor application sends warning log message and SNMP trap. To prevent this add error handling into the update functions. Signed-off-by: Tokunori Ikegami Cc: Guenter Roeck Cc: Chris Packham Cc: linux-hwmon@vger.kernel.org --- drivers/hwmon/adt7475.c | 202 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 158 insertions(+), 44 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 5f03a93632c3..fb89b88f1998 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1658,127 +1658,236 @@ static void adt7475_read_pwm(struct i2c_client *client, int index) } } -static void adt7475_update_measure(struct device *dev) +static int adt7475_update_measure(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct adt7475_data *data = i2c_get_clientdata(client); u16 ext; int i; + int ret; - data->alarms = adt7475_read(REG_STATUS2) << 8; - data->alarms |= adt7475_read(REG_STATUS1); + ret = adt7475_read(REG_STATUS2); + if (ret < 0) + return ret; + data->alarms = ret << 8; + + ret = adt7475_read(REG_STATUS1); + if (ret < 0) + return ret; + data->alarms |= ret; + + ret = adt7475_read(REG_EXTEND2); + if (ret < 0) + return ret; + + ext = (ret << 8); + + ret = adt7475_read(REG_EXTEND1); + if (ret < 0) + return ret; + + ext |= ret; - ext = (adt7475_read(REG_EXTEND2) << 8) | - adt7475_read(REG_EXTEND1); for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { if (!(data->has_voltage & (1 << i))) continue; + ret = adt7475_read(VOLTAGE_REG(i)); + if (ret < 0) + return ret; data->voltage[INPUT][i] = - (adt7475_read(VOLTAGE_REG(i)) << 2) | + (ret << 2) | ((ext >> (i * 2)) & 3); } - for (i = 0; i < ADT7475_TEMP_COUNT; i++) + for (i = 0; i < ADT7475_TEMP_COUNT; i++) { + ret = adt7475_read(TEMP_REG(i)); + if (ret < 0) + return ret; data->temp[INPUT][i] = - (adt7475_read(TEMP_REG(i)) << 2) | + (ret << 2) | ((ext >> ((i + 5) * 2)) & 3); + } if (data->has_voltage & (1 << 5)) { - data->alarms |= adt7475_read(REG_STATUS4) << 24; - ext = adt7475_read(REG_EXTEND3); - data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 | + ret = adt7475_read(REG_STATUS4); + if (ret < 0) + return ret; + data->alarms |= ret << 24; + + ret = adt7475_read(REG_EXTEND3); + if (ret < 0) + return ret; + ext = ret; + + ret = adt7475_read(REG_VTT); + if (ret < 0) + return ret; + data->voltage[INPUT][5] = ret << 2 | ((ext >> 4) & 3); } for (i = 0; i < ADT7475_TACH_COUNT; i++) { if (i == 3 && !data->has_fan4) continue; - data->tach[INPUT][i] = - adt7475_read_word(client, TACH_REG(i)); + ret = adt7475_read_word(client, TACH_REG(i)); + if (ret < 0) + return ret; + data->tach[INPUT][i] = ret; } /* Updated by hw when in auto mode */ for (i = 0; i < ADT7475_PWM_COUNT; i++) { if (i == 1 && !data->has_pwm2) continue; - data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); + ret = adt7475_read(PWM_REG(i)); + if (ret < 0) + return ret; + data->pwm[INPUT][i] = ret; } - if (data->has_vid) - data->vid = adt7475_read(REG_VID) & 0x3f; + if (data->has_vid) { + ret = adt7475_read(REG_VID); + if (ret < 0) + return ret; + data->vid = ret & 0x3f; + } + + return 0; } -static void adt7475_update_limits(struct device *dev) +static int adt7475_update_limits(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct adt7475_data *data = i2c_get_clientdata(client); int i; + int ret; - data->config4 = adt7475_read(REG_CONFIG4); - data->config5 = adt7475_read(REG_CONFIG5); + ret = adt7475_read(REG_CONFIG4); + if (ret < 0) + return ret; + data->config4 = ret; + + ret = adt7475_read(REG_CONFIG5); + if (ret < 0) + return ret; + data->config5 = ret; for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { if (!(data->has_voltage & (1 << i))) continue; /* Adjust values so they match the input precision */ - data->voltage[MIN][i] = - adt7475_read(VOLTAGE_MIN_REG(i)) << 2; - data->voltage[MAX][i] = - adt7475_read(VOLTAGE_MAX_REG(i)) << 2; + ret = adt7475_read(VOLTAGE_MIN_REG(i)); + if (ret < 0) + return ret; + data->voltage[MIN][i] = ret << 2; + + ret = adt7475_read(VOLTAGE_MAX_REG(i)); + if (ret < 0) + return ret; + data->voltage[MAX][i] = ret << 2; } if (data->has_voltage & (1 << 5)) { - data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2; - data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2; + ret = adt7475_read(REG_VTT_MIN); + if (ret < 0) + return ret; + data->voltage[MIN][5] = ret << 2; + + ret = adt7475_read(REG_VTT_MAX); + if (ret < 0) + return ret; + data->voltage[MAX][5] = ret << 2; } for (i = 0; i < ADT7475_TEMP_COUNT; i++) { /* Adjust values so they match the input precision */ - data->temp[MIN][i] = - adt7475_read(TEMP_MIN_REG(i)) << 2; - data->temp[MAX][i] = - adt7475_read(TEMP_MAX_REG(i)) << 2; - data->temp[AUTOMIN][i] = - adt7475_read(TEMP_TMIN_REG(i)) << 2; - data->temp[THERM][i] = - adt7475_read(TEMP_THERM_REG(i)) << 2; - data->temp[OFFSET][i] = - adt7475_read(TEMP_OFFSET_REG(i)); + ret = adt7475_read(TEMP_MIN_REG(i)); + if (ret < 0) + return ret; + data->temp[MIN][i] = ret << 2; + + ret = adt7475_read(TEMP_MAX_REG(i)); + if (ret < 0) + return ret; + data->temp[MAX][i] = ret << 2; + + ret = adt7475_read(TEMP_TMIN_REG(i)); + if (ret < 0) + return ret; + data->temp[AUTOMIN][i] = ret << 2; + + ret = adt7475_read(TEMP_THERM_REG(i)); + if (ret < 0) + return ret; + data->temp[THERM][i] = ret << 2; + + ret = adt7475_read(TEMP_OFFSET_REG(i)); + if (ret < 0) + return ret; + data->temp[OFFSET][i] = ret; } adt7475_read_hystersis(client); for (i = 0; i < ADT7475_TACH_COUNT; i++) { if (i == 3 && !data->has_fan4) continue; - data->tach[MIN][i] = - adt7475_read_word(client, TACH_MIN_REG(i)); + ret = adt7475_read_word(client, TACH_MIN_REG(i)); + if (ret < 0) + return ret; + data->tach[MIN][i] = ret; } for (i = 0; i < ADT7475_PWM_COUNT; i++) { if (i == 1 && !data->has_pwm2) continue; - data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); - data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); + ret = adt7475_read(PWM_MAX_REG(i)); + if (ret < 0) + return ret; + data->pwm[MAX][i] = ret; + + ret = adt7475_read(PWM_MIN_REG(i)); + if (ret < 0) + return ret; + data->pwm[MIN][i] = ret; /* Set the channel and control information */ adt7475_read_pwm(client, i); } - data->range[0] = adt7475_read(TEMP_TRANGE_REG(0)); - data->range[1] = adt7475_read(TEMP_TRANGE_REG(1)); - data->range[2] = adt7475_read(TEMP_TRANGE_REG(2)); + ret = adt7475_read(TEMP_TRANGE_REG(0)); + if (ret < 0) + return ret; + data->range[0] = ret; + + ret = adt7475_read(TEMP_TRANGE_REG(1)); + if (ret < 0) + return ret; + data->range[1] = ret; + + ret = adt7475_read(TEMP_TRANGE_REG(2)); + if (ret < 0) + return ret; + data->range[2] = ret; + + return 0; } static struct adt7475_data *adt7475_update_device(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct adt7475_data *data = i2c_get_clientdata(client); + int ret; mutex_lock(&data->lock); /* Measurement values update every 2 seconds */ if (time_after(jiffies, data->measure_updated + HZ * 2) || !data->valid) { - adt7475_update_measure(dev); + ret = adt7475_update_measure(dev); + if (ret < 0) { + data->valid = false; + mutex_unlock(&data->lock); + return ERR_PTR(ret); + } data->measure_updated = jiffies; data->valid = true; } @@ -1786,7 +1895,12 @@ static struct adt7475_data *adt7475_update_device(struct device *dev) /* Limits and settings, should never change update every 60 seconds */ if (time_after(jiffies, data->limits_updated + HZ * 60) || !data->valid) { - adt7475_update_limits(dev); + ret = adt7475_update_limits(dev); + if (ret < 0) { + data->valid = false; + mutex_unlock(&data->lock); + return ERR_PTR(ret); + } data->limits_updated = jiffies; data->valid = true; } From patchwork Tue Aug 7 08:57:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60DB713BB for ; Tue, 7 Aug 2018 08:58:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5017C29B73 for ; Tue, 7 Aug 2018 08:58:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4460129B86; Tue, 7 Aug 2018 08:58:53 +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.3 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,URIBL_SBL 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 CFE3229B76 for ; Tue, 7 Aug 2018 08:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727669AbeHGLML (ORCPT ); Tue, 7 Aug 2018 07:12:11 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.5]:7146 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbeHGLML (ORCPT ); Tue, 7 Aug 2018 07:12:11 -0400 Received: from [67.219.250.100] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-5.bemta.az-a.us-west-2.aws.symcld.net id 85/F9-25586-A4F596B5; Tue, 07 Aug 2018 08:58:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsUyLfyHiK5XfGa 0waVpuhbtr7cyOjB6fN4kF8AYxZqZl5RfkcCasWv/GdaCk9IVczZ9ZG5gPCfexcjFISQwh1Hi XfteVgjnJ6NEz+VTzF2MnBxsAqYS018tZASxRQRUJLasW8MMUsQssIpR4vuyA0wgCWGBKIkX8 x6xgdgsAqoSvw9tBmvmFXCUeHG6nwXElhCQlzj8pokVxOYUcJK49LwNbKgQUE3HlSUsELamxP Oe74wQ9cESLatWMk9g5F3AyLCK0SKpKDM9oyQ3MTNH19DAQNfQ0EjX0NhQ19DIVC+xSjdRr7R Ytzy1uETXSC+xvFivuDI3OSdFLy+1ZBMjMGAYgGAH45cXKYcYJTmYlER5i5Qzo4X4kvJTKjMS izPii0pzUosPMcpwcChJ8ObHAeUEi1LTUyvSMnOAoQuTluDgURLhzQFJ8xYXJOYWZ6ZDpE4xG nOcau6ZxMzx5/3UScxCLHn5ealS4rwCIKUCIKUZpXlwg2AxdYlRVkqYlxHoNCGegtSi3MwSVP lXjOIcjErCvIUgU3gy80rg9r0COoUJ6JQ32mCnlCQipKQaGMO/lKeKaKf/sr/49/L047rHKgv OPZv8I+1zs8llLr7vBuxeVttmGXE9MT6ptdxhYsIc13eTvpvPEfL8aN5UHz09cHbkq5dPNIzk pulZWIRu23/Y0YXbcKX37Ak3l8in/7fZoxT0Rv2pyg6uc5I7mK8F6x789iDiw/5NAULSpxdZy cY5Hm077q7EUpyRaKjFXFScCAAc5F/1pAIAAA== X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-8.tower-324.messagelabs.com!1533632329!3076686!1 X-Originating-IP: [150.87.248.20] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.9.15; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5397 invoked from network); 7 Aug 2018 08:58:50 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-8.tower-324.messagelabs.com with SMTP; 7 Aug 2018 08:58:50 -0000 Received: from swim-manx.rd.allied-telesis.co.jp ([150.87.21.50]) by TKY-DS01.at.lc with Microsoft SMTPSVC(8.0.9200.16384); Tue, 7 Aug 2018 17:58:49 +0900 Received: from ikegami-pc.rd.allied-telesis.co.jp by swim-manx.rd.allied-telesis.co.jp (AlliedTelesis SMTPRS 1.3 pl 1 ++E6B86F8C687C6288D9B5559052954DC9) with ESMTP id ; Tue, 7 Aug 2018 17:58:48 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH 4/4] hwmon: (adt7475) Change show functions to return error data correctly Date: Tue, 7 Aug 2018 17:57:33 +0900 Message-Id: <20180807085733.28756-5-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> References: <20180807085733.28756-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 08:58:49.0406 (UTC) FILETIME=[DB58DDE0:01D42E2C] 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 update device function was changed to return error pointer value. So change the show functions using the update function to return error. Signed-off-by: Tokunori Ikegami Cc: Guenter Roeck Cc: Chris Packham Cc: linux-hwmon@vger.kernel.org --- drivers/hwmon/adt7475.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index fb89b88f1998..21a40fbb3a49 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -326,6 +326,9 @@ static ssize_t show_voltage(struct device *dev, struct device_attribute *attr, struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); unsigned short val; + if (IS_ERR(data)) + return PTR_ERR(data); + switch (sattr->nr) { case ALARM: return sprintf(buf, "%d\n", @@ -381,6 +384,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); int out; + if (IS_ERR(data)) + return PTR_ERR(data); + switch (sattr->nr) { case HYSTERSIS: mutex_lock(&data->lock); @@ -625,6 +631,9 @@ static ssize_t show_point2(struct device *dev, struct device_attribute *attr, struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); int out, val; + if (IS_ERR(data)) + return PTR_ERR(data); + mutex_lock(&data->lock); out = (data->range[sattr->index] >> 4) & 0x0F; val = reg2temp(data, data->temp[AUTOMIN][sattr->index]); @@ -683,6 +692,9 @@ static ssize_t show_tach(struct device *dev, struct device_attribute *attr, struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); int out; + if (IS_ERR(data)) + return PTR_ERR(data); + if (sattr->nr == ALARM) out = (data->alarms >> (sattr->index + 10)) & 1; else @@ -720,6 +732,9 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, struct adt7475_data *data = adt7475_update_device(dev); struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + if (IS_ERR(data)) + return PTR_ERR(data); + return sprintf(buf, "%d\n", data->pwm[sattr->nr][sattr->index]); } @@ -729,6 +744,9 @@ static ssize_t show_pwmchan(struct device *dev, struct device_attribute *attr, struct adt7475_data *data = adt7475_update_device(dev); struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + if (IS_ERR(data)) + return PTR_ERR(data); + return sprintf(buf, "%d\n", data->pwmchan[sattr->index]); } @@ -738,6 +756,9 @@ static ssize_t show_pwmctrl(struct device *dev, struct device_attribute *attr, struct adt7475_data *data = adt7475_update_device(dev); struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + if (IS_ERR(data)) + return PTR_ERR(data); + return sprintf(buf, "%d\n", data->pwmctl[sattr->index]); } @@ -945,6 +966,9 @@ static ssize_t show_pwmfreq(struct device *dev, struct device_attribute *attr, int i = clamp_val(data->range[sattr->index] & 0xf, 0, ARRAY_SIZE(pwmfreq_table) - 1); + if (IS_ERR(data)) + return PTR_ERR(data); + return sprintf(buf, "%d\n", pwmfreq_table[i]); } @@ -1035,6 +1059,10 @@ static ssize_t cpu0_vid_show(struct device *dev, struct device_attribute *devattr, char *buf) { struct adt7475_data *data = adt7475_update_device(dev); + + if (IS_ERR(data)) + return PTR_ERR(data); + return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); }