summaryrefslogtreecommitdiff
path: root/drivers/misc/ds1682.c
diff options
context:
space:
mode:
authorAaron Sierra <asierra@xes-inc.com>2017-12-22 10:51:09 -0600
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-01-09 17:03:57 +0100
commit2fa065fde217a39987f8931cb800e511fa5178e4 (patch)
tree071795770e41450cbe21ad8ff5f54b3d1bea7d1a /drivers/misc/ds1682.c
parent1a3771d5fa9417d5a79dd25b1c3c387f7dac7179 (diff)
downloadlinux-next-2fa065fde217a39987f8931cb800e511fa5178e4.tar.gz
misc: ds1682: Show device registers as unsigned
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 <asierra@xes-inc.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/ds1682.c')
-rw-r--r--drivers/misc/ds1682.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c
index 7231260ac287..0fc5366457b9 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,