From patchwork Wed Aug 8 01:32:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10559383 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 3BA6F157D for ; Wed, 8 Aug 2018 01:36:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 288A32040D for ; Wed, 8 Aug 2018 01:36:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A42726256; Wed, 8 Aug 2018 01:36: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.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 597AC2040D for ; Wed, 8 Aug 2018 01:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbeHHDxm (ORCPT ); Tue, 7 Aug 2018 23:53:42 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.208]:46712 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeHHDxm (ORCPT ); Tue, 7 Aug 2018 23:53:42 -0400 Received: from [67.219.247.52] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-d.us-east-1.aws.symcld.net id D7/0C-01617-E194A6B5; Wed, 08 Aug 2018 01:36:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKIsWRWlGSWpSXmKPExsUyLfyHiK6cZ1a 0welHUhbtr7cyOjB6fN4kF8AYxZqZl5RfkcCa8enQR+aCY04VG5sOsTUwfjLrYuTiEBKYwyjx YtEaJgjnJ6PEkX0TgRxODjYBU4nprxYygtgiAioSW9atYQYpYhZYxSjxfdkBsCJhgWiJ8w8eg tksAqoSX2/MYgOxeQUcJU5NXcwKYksIyEscftMEZHNwcAo4SRx6mAASFgIqWdTXwQZha0o87/ nOCFEeLDHr3l32CYy8CxgZVjGaJxVlpmeU5CZm5ugaGhjoGhoaAWldQxNzvcQq3RS90mLd1MT iEl1DvcTyYr3iytzknBS9vNSSTYzAYGEAgh2MTbNTDzFKcjApifJ+/pYZLcSXlJ9SmZFYnBFf VJqTWnyIUYaDQ0mCN8wjK1pIsCg1PbUiLTMHGLYwaQkOHiURXjWQNG9xQWJucWY6ROoUoyXHq eaeScwcf95PBZL7uqdNYhZiycvPS5US533uDtQgANKQUZoHNw4WW5cYZaWEeRmBDhTiKUgtys 0sQZV/xSjOwagkzKsLspYnM68EbusroIOYgA56o50JclBJIkJKqoExl2XpTZa5mivvrIzn/h/ ibXh5tW1d+QZX1RtPuv/u/cAas7mo99Srl7nlaQdjVE4/VK3pVdTbVJy9rXmWe3jxtolXGB/f WG665qEsU77Hv483rNZU8R3ba7s390jQw1ov1tdb3JY+/34ntKzJqjpU7/qv723cvycrBDxtX K/9M/HutI3ZFmIKSizFGYmGWsxFxYkAm49czKgCAAA= X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-28.tower-424.messagelabs.com!1533692189!1668344!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 31085 invoked from network); 8 Aug 2018 01:36:30 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-28.tower-424.messagelabs.com with SMTP; 8 Aug 2018 01:36:30 -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 10:36:28 +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 10:36:28 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v3 1/4] hwmon: (adt7475) Split device update function to measure and limits Date: Wed, 8 Aug 2018 10:32:16 +0900 Message-Id: <20180808013219.26118-2-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> References: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 08 Aug 2018 01:36:28.0892 (UTC) FILETIME=[3A6191C0:01D42EB8] 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 --- Changes since v2: - Move to update the limits from the probe function. Changes since v1: - Change to update the limits only once. drivers/hwmon/adt7475.c | 210 +++++++++++++++++++++++++----------------------- 1 file changed, 109 insertions(+), 101 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 9ef84998c7f3..d6fe4ddd9927 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -194,7 +194,6 @@ struct adt7475_data { struct mutex lock; unsigned long measure_updated; - unsigned long limits_updated; char valid; u8 config4; @@ -1385,6 +1384,65 @@ static void adt7475_remove_files(struct i2c_client *client, sysfs_remove_group(&client->dev.kobj, &vid_attr_group); } +static void adt7475_update_limits(struct i2c_client *client) +{ + struct adt7475_data *data = i2c_get_clientdata(client); + int i; + + 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; + } + + 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_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 int adt7475_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1562,6 +1620,9 @@ static int adt7475_probe(struct i2c_client *client, (data->bypass_attn & (1 << 3)) ? " in3" : "", (data->bypass_attn & (1 << 4)) ? " in4" : ""); + /* Limits and settings, should never change update more than once */ + adt7475_update_limits(client); + return 0; eremove: @@ -1658,121 +1719,68 @@ 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); - - /* 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); - - 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)); - } - - /* 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)); - } + 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); + } - if (data->has_vid) - data->vid = adt7475_read(REG_VID) & 0x3f; + for (i = 0; i < ADT7475_TEMP_COUNT; i++) + data->temp[INPUT][i] = + (adt7475_read(TEMP_REG(i)) << 2) | + ((ext >> ((i + 5) * 2)) & 3); - data->measure_updated = jiffies; + 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); } - /* 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; - } + 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_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); + /* 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)); + } - 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)); - } + if (data->has_vid) + data->vid = adt7475_read(REG_VID) & 0x3f; +} - 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); - } +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; } mutex_unlock(&data->lock); From patchwork Wed Aug 8 01:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10559385 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 A406E157D for ; Wed, 8 Aug 2018 01:36:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9402B2040D for ; Wed, 8 Aug 2018 01:36:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87DCF26256; Wed, 8 Aug 2018 01:36:35 +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 378AC2040D for ; Wed, 8 Aug 2018 01:36:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbeHHDxo (ORCPT ); Tue, 7 Aug 2018 23:53:44 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.1]:16443 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeHHDxo (ORCPT ); Tue, 7 Aug 2018 23:53:44 -0400 Received: from [67.219.250.100] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-a.us-west-2.aws.symcld.net id 13/46-28970-1294A6B5; Wed, 08 Aug 2018 01:36:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeJIrShJLcpLzFFi42KZFv5DRFfRMyv a4NpfNYv211sZHRg9Pm+SC2CMYs3MS8qvSGDNaG58wlywg6Pi/smbTA2ME9i7GLk4hATmMEqs nPaEFcL5ySixuGU2YxcjJwebgKnE9FcLwWwRARWJLevWMIMUMQusYpT4vuwAE0hCWMBHYv3PI 6wgNouAqsTLCdvBGngFHCU+fL3KDGJLCMhLHH7TBFTDwcEp4CRx6GECSFgIqGRRXwcbhK0p8b znOyNEebDElM4+5gmMvAsYGVYxWiQVZaZnlOQmZuboGhoY6BoaGukaGlkAsZFeYpVuol5psW5 5anGJLpBbXqxXXJmbnJOil5dasokRGC4MQLCD8fKhlEOMkhxMSqK8n79lRgvxJeWnVGYkFmfE F5XmpBYfYpTh4FCS4J3unhUtJFiUmp5akZaZAwxcmLQEB4+SCO8ukDRvcUFibnFmOkTqFKMux 5/3UycxC7Hk5eelSonzPgcpEgApyijNgxsBi6JLjLJSwryMQEcJ8RSkFuVmlqDKv2IU52BUEu b9ADKFJzOvBG7TK6AjmICOeKOdCXJESSJCSqqBMZ+F9/Sa7q6GxyfD7nw/vetJ1fyzGQcvObQ 9mXykNO7uz+fGeU4ndzPP/7ddhDFZMqA8sv2cgKJh/DTWFT/6tdYEO546zTlNnPPzSUb9X/Ga ktPlJ7N4rXj7/pxpjllU4XWjiCKBHyLert7W7PrB1rkb5P5dKA7m+7/ty4s1F3x0p5sw73HmU 2Ipzkg01GIuKk4EAEtcx6adAgAA X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-19.tower-324.messagelabs.com!1533692192!3131492!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 26115 invoked from network); 8 Aug 2018 01:36:33 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-19.tower-324.messagelabs.com with SMTP; 8 Aug 2018 01:36:33 -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 10:36:32 +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 10:36:31 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v3 2/4] hwmon: (adt7475) Change valid parameter to bool type Date: Wed, 8 Aug 2018 10:32:17 +0900 Message-Id: <20180808013219.26118-3-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> References: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 08 Aug 2018 01:36:32.0394 (UTC) FILETIME=[3C77EEA0:01D42EB8] 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 v2: - Change to rebase on the v3 patch 1. 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 d6fe4ddd9927..d90b31eb3472 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; - char valid; + bool valid; u8 config4; u8 config5; @@ -1781,6 +1781,7 @@ static struct adt7475_data *adt7475_update_device(struct device *dev) !data->valid) { adt7475_update_measure(dev); data->measure_updated = jiffies; + data->valid = true; } mutex_unlock(&data->lock); From patchwork Wed Aug 8 01:32:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10559387 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 EC11013B4 for ; Wed, 8 Aug 2018 01:36:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB03D2040D for ; Wed, 8 Aug 2018 01:36:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CED3726256; Wed, 8 Aug 2018 01:36: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 2FD512040D for ; Wed, 8 Aug 2018 01:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726503AbeHHDxr (ORCPT ); Tue, 7 Aug 2018 23:53:47 -0400 Received: from mail1.bemta24.messagelabs.com ([67.219.250.112]:27867 "EHLO mail1.bemta24.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeHHDxr (ORCPT ); Tue, 7 Aug 2018 23:53:47 -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 88/2E-15908-4294A6B5; Wed, 08 Aug 2018 01:36:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42KZFv5DRFfZMyv aYEWDkUX7662MDowenzfJBTBGsWbmJeVXJLBm9B4xK3hkVXGgrZmtgfGqfhcjF4eQwBxGiY0f 9zBCOD8ZJeaf2A3kcHKwCZhKTH+1EMwWEVCR2LJuDTNIEbPAKkaJ78sOMIEkhAXCJC5sncECY rMIqEq837SAGcTmFXCUuPT0KxuILSEgL3H4TRNrFyMHB6eAk8ShhwkgYSGgkkV9HWwQtqbE85 7vjCAlEgLBEmdXSk9g5F3AyLCK0SKpKDM9oyQ3MTNH19DAQNfQ0EjX0NhY19DEUi+xSjdJr7R Ytzy1uETXSC+xvFivuDI3OSdFLy+1ZBMjMFQYgGAH448XKYcYJTmYlER5P3/LjBbiS8pPqcxI LM6ILyrNSS0+xCjDwaEkwcvnkRUtJFiUmp5akZaZAwxamLQEB4+SCK8aSJq3uCAxtzgzHSJ1i lGX48/7qZOYhVjy8vNSpcR5k0CKBECKMkrz4EbAIugSo6yUMC8j0FFCPAWpRbmZJajyrxjFOR iVhHkzQabwZOaVwG16BXQEE9ARb7QzQY4oSURISTUw2pYpHarVST0hsXH5nzUSIjve+VV/uX3 0Zdzmqts/QkWDjDa1Lryw8xC7pfWh8pkGc1cFmAskbCg6Ul16utrqw0H5X2o34x7/7zBXK/aW O/grqONt9XyJjGq7H2usL1btaF+Z4vxYcsLHrBNvO7l0tIzLtEPFVwZXeZqLM1fklNXu2B76Q 7ZfiaU4I9FQi7moOBEAk9BlmJsCAAA= X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-34.tower-344.messagelabs.com!1533692194!2782359!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 4767 invoked from network); 8 Aug 2018 01:36:35 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-34.tower-344.messagelabs.com with SMTP; 8 Aug 2018 01:36: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); Wed, 8 Aug 2018 10:36:34 +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 10:36:33 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v3 3/4] hwmon: (adt7475) Change update functions to add error handling Date: Wed, 8 Aug 2018 10:32:18 +0900 Message-Id: <20180808013219.26118-4-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> References: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 08 Aug 2018 01:36:34.0467 (UTC) FILETIME=[3DB43F30:01D42EB8] 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 v2: - Change to rebase on the v3 patch 1. 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 d90b31eb3472..9f7e1a5b08a5 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -1384,63 +1384,119 @@ static void adt7475_remove_files(struct i2c_client *client, sysfs_remove_group(&client->dev.kobj, &vid_attr_group); } -static void adt7475_update_limits(struct i2c_client *client) +static int adt7475_update_limits(struct i2c_client *client) { 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 int adt7475_probe(struct i2c_client *client, @@ -1719,54 +1775,101 @@ 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; + + ret = adt7475_read(REG_STATUS2); + if (ret < 0) + return ret; + data->alarms = ret << 8; - data->alarms = adt7475_read(REG_STATUS2) << 8; - data->alarms |= adt7475_read(REG_STATUS1); + 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 struct adt7475_data *adt7475_update_device(struct device *dev) From patchwork Wed Aug 8 01:32:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: IKEGAMI Tokunori X-Patchwork-Id: 10559389 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 ED97013B4 for ; Wed, 8 Aug 2018 01:36:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD3692040D for ; Wed, 8 Aug 2018 01:36:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1C7826256; Wed, 8 Aug 2018 01:36: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 C0E192040D for ; Wed, 8 Aug 2018 01:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726625AbeHHDxs (ORCPT ); Tue, 7 Aug 2018 23:53:48 -0400 Received: from mail1.bemta23.messagelabs.com ([67.219.246.1]:47667 "EHLO mail1.bemta23.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeHHDxs (ORCPT ); Tue, 7 Aug 2018 23:53:48 -0400 Received: from [67.219.246.100] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-1.bemta.az-b.us-east-1.aws.symcld.net id 2F/46-01620-6294A6B5; Wed, 08 Aug 2018 01:36:38 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42KZFv5DRFfVMyv a4Ot1M4v211sZHRg9Pm+SC2CMYs3MS8qvSGDNWPv/MXvBZpWK75u4GxhfyHUxcnEICcxhlPjU +I0ZwvnJKPHl8CamLkZODjYBU4nprxYygtgiAioSW9atAStiFljFKPF92QGwImGBWImLZ06zg dgsAqoSBzfNAmvgFXCU+H3pDDOILSEgL3H4TRNrFyMHB6eAk8ShhwkgYSGgkkV9HWwQtqbE85 7vjBDlwRJPtlxhnsDIu4CRYRWjWVJRZnpGSW5iZo6uoYGBrqGhka6xrpGpiV5ilW6SXmmxbmp icYmuoV5iebFecWVuck6KXl5qySZGYKAwAMEOxpW70g4xSnIwKYnyfv6WGS3El5SfUpmRWJwR X1Sak1p8iFGGg0NJgjfMIytaSLAoNT21Ii0zBxiyMGkJDh4lEV41kDRvcUFibnFmOkTqFKMxx 6nmnknMHH/eT53ELMSSl5+XKiXOmwRSKgBSmlGaBzcIFkuXGGWlhHkZgU4T4ilILcrNLEGVf8 UozsGoJMybCTKFJzOvBG7fK6BTmIBOeaOdCXJKSSJCSqqBkf1hadW+nM9szncEzE9MsUn+wV5 5QS0+Q3ySXty1+5qtysqxrvH8lRfuV9S6q/tzhK+bffKQztTTJsznexe0Ldj7RIz7185IZs/O J/fmVO/rf7Tn+P1u+YO8Mold8gnXA3h/+7NfUJra2akWVvVLNM/2QW3KLjnltXUrJvBc2n381 IP+/+efKLEUZyQaajEXFScCALlS1ISgAgAA X-Env-Sender: ikegami@allied-telesis.co.jp X-Msg-Ref: server-13.tower-384.messagelabs.com!1533692196!2075759!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 2783 invoked from network); 8 Aug 2018 01:36:37 -0000 Received: from abricot-inet.allied-telesis.co.jp (HELO TKY-DS01.at.lc) (150.87.248.20) by server-13.tower-384.messagelabs.com with SMTP; 8 Aug 2018 01:36: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 10:36: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 10:36:35 +0900 From: Tokunori Ikegami To: Jean Delvare Cc: Tokunori Ikegami , Guenter Roeck , Chris Packham , linux-hwmon@vger.kernel.org Subject: [PATCH v3 4/4] hwmon: (adt7475) Change show functions to return error data correctly Date: Wed, 8 Aug 2018 10:32:19 +0900 Message-Id: <20180808013219.26118-5-ikegami@allied-telesis.co.jp> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> References: <20180808013219.26118-1-ikegami@allied-telesis.co.jp> X-OriginalArrivalTime: 08 Aug 2018 01:36:36.0054 (UTC) FILETIME=[3EA66760:01D42EB8] 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 v2: - Change to rebase on the v3 patch 1. 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 | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 9f7e1a5b08a5..90837f7c7d0f 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -325,6 +325,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", @@ -380,6 +383,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); @@ -624,6 +630,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]); @@ -682,6 +691,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 @@ -719,6 +731,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]); } @@ -728,6 +743,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]); } @@ -737,6 +755,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]); } @@ -944,6 +965,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]); } @@ -1034,6 +1058,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)); } @@ -1677,7 +1705,9 @@ static int adt7475_probe(struct i2c_client *client, (data->bypass_attn & (1 << 4)) ? " in4" : ""); /* Limits and settings, should never change update more than once */ - adt7475_update_limits(client); + ret = adt7475_update_limits(client); + if (ret) + goto eremove; return 0; @@ -1876,13 +1906,19 @@ 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) { + data->valid = false; + mutex_unlock(&data->lock); + return ERR_PTR(ret); + } data->measure_updated = jiffies; data->valid = true; }