Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756575AbdLVQ6M (ORCPT ); Fri, 22 Dec 2017 11:58:12 -0500 Received: from xes-mad.com ([216.165.139.220]:4743 "EHLO mail.xes-mad.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754212AbdLVQ6H (ORCPT ); Fri, 22 Dec 2017 11:58:07 -0500 Date: Fri, 22 Dec 2017 10:51:09 -0600 (CST) From: Aaron Sierra To: Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel Message-ID: <1344833593.97073.1513961469501.JavaMail.zimbra@xes-inc.com> Subject: [PATCH 1/2] misc: ds1682: Show device registers as unsigned MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.52.0.127] X-Mailer: Zimbra 8.7.5_GA_1764 (ZimbraWebClient - FF57 (Linux)/8.7.5_GA_1764) Thread-Index: kvZGMVEaa3ttz0rjGds4EDbATeM5sA== Thread-Topic: misc: ds1682: Show device registers as unsigned Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1735 Lines: 50 This patch leverages the fact that all DS1682 registers are unsigned to merge two return paths into one. It also introduces val_le as used in ds1682_store() to merge two endianness conversions into one. Signed-off-by: Aaron Sierra --- drivers/misc/ds1682.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c index 7231260..0fc5366 100644 --- a/drivers/misc/ds1682.c +++ b/drivers/misc/ds1682.c @@ -59,25 +59,25 @@ static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr, { struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); struct i2c_client *client = to_i2c_client(dev); - __le32 val = 0; + unsigned long long val; + __le32 val_le = 0; int rc; dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name); /* Read the register */ rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr, - (u8 *) & val); + (u8 *)&val_le); if (rc < 0) return -EIO; - /* Special case: the 32 bit regs are time values with 1/4s - * resolution, scale them up to milliseconds */ - if (sattr->nr == 4) - return sprintf(buf, "%llu\n", - ((unsigned long long)le32_to_cpu(val)) * 250); + val = le32_to_cpu(val_le); - /* Format the output string and return # of bytes */ - return sprintf(buf, "%li\n", (long)le32_to_cpu(val)); + /* Format the output string and return # of bytes + * Special case: the 32 bit regs are time values with 1/4s + * resolution, scale them up to milliseconds + */ + return sprintf(buf, "%llu\n", (sattr->nr == 4) ? (val * 250) : val); } static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr, -- 2.7.4