From patchwork Tue Aug 7 15:19:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558777 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 1915F1057 for ; Tue, 7 Aug 2018 15:19:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 070332A335 for ; Tue, 7 Aug 2018 15:19:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF0A22A338; Tue, 7 Aug 2018 15:19:40 +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 CCBF02A337 for ; Tue, 7 Aug 2018 15:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389625AbeHGRe1 (ORCPT ); Tue, 7 Aug 2018 13:34:27 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.4]:26666 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbeHGRe1 (ORCPT ); Tue, 7 Aug 2018 13:34:27 -0400 Received: from [67.219.250.100] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-a.us-west-2.aws.symcld.net id 6D/8B-02308-988B96B5; Tue, 07 Aug 2018 15:19:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKIsWRWlGSWpSXmKPExsUyLfyHiG7njsx ogyWzZCzaX29ldGD0+LxJLoAxijUzLym/IoE1Y+P/A2wFMxwqbrazNDD+Neli5OIQEpjDKNHx 4gszhPOTUWLf10VMXYycHGwCphLTXy1kBLFFBFQktqxbA1bELLCKUeL7sgNgRcIC0RLTZ9xlA 7FZBFQlbr9bBVTEwcEr4Cix4ZczSFhCQF7i8JsmVhCbU8BJ4uWqw2AzhYBKFv2byARha0o87/ nOCFEfLLHl9FnmCYy8CxgZVjFaJBVlpmeU5CZm5ugaGhjoGhoa6RoaA2kzE73EKt1EvdJi3fL U4hJdI73E8mK94src5JwUvbzUkk2MwGBhAIIdjBcPpRxilORgUhLlPbcxM1qILyk/pTIjsTgj vqg0J7X4EKMMB4eSBO/B7UA5waLU9NSKtMwcYNjCpCU4eJREeJ+DpHmLCxJzizPTIVKnGC05T jX3TGLm+PN+KpDc1z1tErMQS15+XqqUOG8tSIMASENGaR7cOFhsXWKUlRLmZQQ6UIinILUoN7 MEVf4VozgHo5Iw7wSQKTyZeSVwW18BHcQEdNAbbbCDShIRUlINjPPniJ4T9bD6nhQXM0lVcJH kvdYIIT3FM9+jtM9+m9mRy62ZplRcvVfUj0HQ+47F4luFq08WfO44kRCw///eGJYdig9nbdOr XpcwQdM0YX2sZu8WvYM54SZTFt2foZn9p+feMkF/WweVdbZnGCKck2deWPFu+Ypt4myPJyjcm jfHLNXVcu78EiWW4oxEQy3mouJEAFspOdSoAgAA X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-12.tower-324.messagelabs.com!1533655176!3094672!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 23403 invoked from network); 7 Aug 2018 15:19:37 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-12.tower-324.messagelabs.com with SMTP; 7 Aug 2018 15:19:37 -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); Wed, 8 Aug 2018 00:19:36 +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 ; Wed, 8 Aug 2018 00:19:35 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v2 1/4] hwmon: (adt7475) Split device update function to measure and limits Date: Wed, 8 Aug 2018 00:19:06 +0900 Message-Id: <20180807151909.24433-2-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> References: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 15:19:36.0105 (UTC) FILETIME=[0D0A7990:01D42E62] 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. Also not necessary to read the limits more than once so change to update once. Signed-off-by: Tokunori Ikegami Cc: Guenter Roeck Cc: Chris Packham Cc: linux-hwmon@vger.kernel.org --- Changes since v1: - Change to update the limits only once. drivers/hwmon/adt7475.c | 202 +++++++++++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 95 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 9ef84998c7f3..42f48c6843c5 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -194,7 +194,7 @@ struct adt7475_data { struct mutex lock; unsigned long measure_updated; - unsigned long limits_updated; + bool limits_updated; char valid; u8 config4; @@ -1658,123 +1658,135 @@ 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; +} + +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; - if (data->has_vid) - data->vid = adt7475_read(REG_VID) & 0x3f; + data->config4 = adt7475_read(REG_CONFIG4); + data->config5 = adt7475_read(REG_CONFIG5); - data->measure_updated = jiffies; + 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); - data->limits_updated = jiffies; - data->valid = 1; + /* 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 more than once */ + if (!data->limits_updated) { + adt7475_update_limits(dev); + data->limits_updated = true; + } mutex_unlock(&data->lock); return data; From patchwork Tue Aug 7 15:19:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558779 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 97B2B15E9 for ; Tue, 7 Aug 2018 15:19:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 851902A335 for ; Tue, 7 Aug 2018 15:19:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78E3A2A338; Tue, 7 Aug 2018 15:19:41 +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 2503C2A335 for ; Tue, 7 Aug 2018 15:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389790AbeHGRe2 (ORCPT ); Tue, 7 Aug 2018 13:34:28 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.112]:1615 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbeHGRe2 (ORCPT ); Tue, 7 Aug 2018 13:34:28 -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 1E/1A-15908-B88B96B5; Tue, 07 Aug 2018 15:19:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkkeJIrShJLcpLzFFi42KZFv5DRLd7R2a 0weELkhbtr7cyOjB6fN4kF8AYxZqZl5RfkcCa8WizUMFqjorbN9azNzC2sXcxcnEICcxhlJiw rIUVwvnJKPHn0S2mLkZODjYBU4nprxYygtgiAioSW9atYQYpYhZYxSjxfdkBsCJhAR+Jdbfng NksAqoS99btZAexeQUcJW4f/ccCYksIyEscftPECmJzCjhJvFx1GGyoEFDNon8TmSBsTYnnPd +B4hxA9cESj395TWDkXcDIsIrRIqkoMz2jJDcxM0fX0MBA19DQSNfQ2FTX0MRcL7FKN0mvtFi 3PLW4RNdIL7G8WK+4Mjc5J0UvL7VkEyMwWBiAYAfj60MphxglOZiURHnPbcyMFuJLyk+pzEgs zogvKs1JLT7EKMPBoSTBe3A7UE6wKDU9tSItMwcYtjBpCQ4eJRFeZWDoCvEWFyTmFmemQ6ROM epy/Hk/dRKzEEtefl6qlDjvQ5AZAiBFGaV5cCNgMXSJUVZKmJcR6CghnoLUotzMElT5V4ziHI xKwrwTQKbwZOaVwG16BXQEE9ARb7TBjihJREhJNTAePu9gYSfSFuuxN/WrmZhgcaCb3Zrvsb0 7GRoE5LZ7MRwOvx9xmVVowtuuVd/a893XnDR09M4R1FFhej9jcsRmsY9hSYlnEqUlduiLOd45 aX2D8a3Ua3GWcm62+/c47ZJNj7qrpriobnq/ddkikXLv6lZx30gBr3CV6B2WvSVNyjK807P/K 7EUZyQaajEXFScCANNqUrmcAgAA X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-19.tower-344.messagelabs.com!1533655178!2757224!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 21736 invoked from network); 7 Aug 2018 15:19:39 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-19.tower-344.messagelabs.com with SMTP; 7 Aug 2018 15:19:39 -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); Wed, 8 Aug 2018 00:19:38 +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 ; Wed, 8 Aug 2018 00:19:37 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v2 2/4] hwmon: (adt7475) Change valid parameter to bool type Date: Wed, 8 Aug 2018 00:19:07 +0900 Message-Id: <20180807151909.24433-3-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> References: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 15:19:38.0300 (UTC) FILETIME=[0E5967C0:01D42E62] 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 --- Changes since v1: - Change to rebase on the v2 patch 1. drivers/hwmon/adt7475.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 42f48c6843c5..680fc9cecb7b 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -195,7 +195,7 @@ struct adt7475_data { unsigned long measure_updated; bool 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 more than once */ From patchwork Tue Aug 7 15:19:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558781 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 343E215E9 for ; Tue, 7 Aug 2018 15:19:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2409A2A335 for ; Tue, 7 Aug 2018 15:19:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18F1F2A33D; Tue, 7 Aug 2018 15:19:49 +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 757FC2A335 for ; Tue, 7 Aug 2018 15:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389890AbeHGReb (ORCPT ); Tue, 7 Aug 2018 13:34:31 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.212]:13244 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727429AbeHGRea (ORCPT ); Tue, 7 Aug 2018 13:34:30 -0400 Received: from [67.219.251.52] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-5.bemta.az-c.us-west-2.aws.symcld.net id 95/2D-01612-D88B96B5; Tue, 07 Aug 2018 15:19:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeJIrShJLcpLzFFi42KZFv5DRLd3R2a 0wct2MYv211sZHRg9Pm+SC2CMYs3MS8qvSGDNWLn/JGNBi2XFth8f2RoYp+p1MXJxCAnMYZSY v+8kG4Tzk1Hi8vz5LF2MnBxsAqYS018tZASxRQRUJLasW8MMUsQssIpR4vuyA0xdjBwcwgJhE heX84LUsAioSkx9sgqsl1fAUaL/6SFWEFtCQF7i8JsmMJtTwEni5arDYDOFgGoW/ZvIBGFrSj zv+c4IUR8s8fvUHNYJjLwLGBlWMVokFWWmZ5TkJmbm6BoaGOgaGhrpGhpb6BoZGuklVukm65U W65anFpfoArnlxXrFlbnJOSl6eaklmxiB4cIABDsY/x5KOcQoycGkJMp7bmNmtBBfUn5KZUZi cUZ8UWlOavEhRhkODiUJ3knbgXKCRanpqRVpmTnAwIVJS3DwKInwPgdJ8xYXJOYWZ6ZDpE4x6 nL8eT91ErMQS15+XqqUOG8tSJEASFFGaR7cCFgUXWKUlRLmZQQ6SoinILUoN7MEVf4VozgHo5 Iw71mQKTyZeSVwm14BHcEEdMQbbbAjShIRUlINjG7H1oYfiZ7V+Tv0bKVi3NTsjOCfEx5FpMX 7X7B78//9xKVnJjw8FLZtxlVlDaGsDWZvF34wsxRMFU06+pX59wULPYttejpCDT+TFv7KLHMW uWi880dK+p+XHG/emfzk2Phk88G4tkthn4PuP33e9kfvyHTfCWcsOuMOlumsf7THgd9a1G7XJ G4lluKMREMt5qLiRAAIZJE/nQIAAA== X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-7.tower-364.messagelabs.com!1533655180!2817649!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 27484 invoked from network); 7 Aug 2018 15:19:41 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-7.tower-364.messagelabs.com with SMTP; 7 Aug 2018 15:19:41 -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); Wed, 8 Aug 2018 00:19:40 +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 ; Wed, 8 Aug 2018 00:19:39 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v2 3/4] hwmon: (adt7475) Change update functions to add error handling Date: Wed, 8 Aug 2018 00:19:08 +0900 Message-Id: <20180807151909.24433-4-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> References: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 15:19:40.0062 (UTC) FILETIME=[0F6643E0:01D42E62] 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 --- Changes since v1: - Move the changes in adt7475_update_device() to patch 4. drivers/hwmon/adt7475.c | 187 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 145 insertions(+), 42 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 680fc9cecb7b..74fe5424c394 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1658,114 +1658,217 @@ 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) From patchwork Tue Aug 7 15:19:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10558783 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 7750F96FA for ; Tue, 7 Aug 2018 15:19:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 659102A335 for ; Tue, 7 Aug 2018 15:19:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59AB92A337; Tue, 7 Aug 2018 15:19:49 +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 B7A8E2A338 for ; Tue, 7 Aug 2018 15:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727429AbeHGRee (ORCPT ); Tue, 7 Aug 2018 13:34:34 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.211]:44649 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389891AbeHGRed (ORCPT ); Tue, 7 Aug 2018 13:34:33 -0400 Received: from [67.219.247.52] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta.az-d.us-east-1.aws.symcld.net id 6D/59-01620-098B96B5; Tue, 07 Aug 2018 15:19:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeJIrShJLcpLzFFi42KZFv5DRHfCjsx ogxe/2S3aX29ldGD0+LxJLoAxijUzLym/IoE1Y+6WlIJGlYoPE44wNzAekuti5OIQEpjDKHH6 +lYWCOcno8Suc+1sXYycHGwCphLTXy1kBLFFBFQktqxbwwxSxCywilHi+7IDTCAJYYFYiZ5HG 1m7GDk4WARUJd7fEgQxeQUcJRa89wapkBCQlzj8pokVxOYUcJJ4ueow2EghoJJF/yYyQdiaEs 97vjNC1AdL3L7VzziBkXcBI8MqRrOkosz0jJLcxMwcXUMDA11DQyMgrWtiqpdYpZuiV1qsm5p YXKJrqJdYXqxXXJmbnJOil5dasokRGCYMQLCDce2PlEOMkhxMSqK85zZmRgvxJeWnVGYkFmfE F5XmpBYfYpTh4FCS4J20HSgnWJSanlqRlpkDDFiYtAQHj5IIrzFImre4IDG3ODMdInWK0ZjjV HPPJGaOP++nTmIWYsnLz0uVEuetBSkVACnNKM2DGwSLpEuMslLCvIxApwnxFKQW5WaWoMq/Yh TnYFQS5p0AMoUnM68Ebt8roFOYgE55ow12SkkiQkqqgbE7Ycnt4NQdxsuYfP+UWRk829gpxDM tc+l375kq25jZ2tcoLU9Wc9Dd/tlU6+6GSIb3ASKT11m8cDT/KuB8282F811CuO5Kh7DXq1+c Nq9a7RK35Zizybq1hkkOnI4G4pqfGMXL/wokbcl4KNR3s0tB9tDK2FM7Vs93K1l9XViO7cINK XtrYyWW4oxEQy3mouJEAFdPzIOfAgAA X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-6.tower-424.messagelabs.com!1533655183!1634922!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 12192 invoked from network); 7 Aug 2018 15:19:43 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-6.tower-424.messagelabs.com with SMTP; 7 Aug 2018 15:19:43 -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); Wed, 8 Aug 2018 00:19:42 +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 ; Wed, 8 Aug 2018 00:19:41 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v2 4/4] hwmon: (adt7475) Change show functions to return error data correctly Date: Wed, 8 Aug 2018 00:19:09 +0900 Message-Id: <20180807151909.24433-5-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> References: <20180807151909.24433-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 07 Aug 2018 15:19:42.0676 (UTC) FILETIME=[10F52140:01D42E62] 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 --- Changes since v1: - Move the changes in adt7475_update_device() from patch 3. - Change to rebase on the v2 patch 1. drivers/hwmon/adt7475.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 74fe5424c394..bdafc213fdd5 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)); } @@ -1875,20 +1903,30 @@ 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; } /* Limits and settings, should never change update more than once */ if (!data->limits_updated) { - adt7475_update_limits(dev); + ret = adt7475_update_limits(dev); + if (ret < 0) { + mutex_unlock(&data->lock); + return ERR_PTR(ret); + } data->limits_updated = true; } mutex_unlock(&data->lock);