Skip to content

Commit 2fa065f

Browse files
Aaron Sierragregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1a3771d commit 2fa065f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/misc/ds1682.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
5959
{
6060
struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
6161
struct i2c_client *client = to_i2c_client(dev);
62-
__le32 val = 0;
62+
unsigned long long val;
63+
__le32 val_le = 0;
6364
int rc;
6465

6566
dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
6667

6768
/* Read the register */
6869
rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
69-
(u8 *) & val);
70+
(u8 *)&val_le);
7071
if (rc < 0)
7172
return -EIO;
7273

73-
/* Special case: the 32 bit regs are time values with 1/4s
74-
* resolution, scale them up to milliseconds */
75-
if (sattr->nr == 4)
76-
return sprintf(buf, "%llu\n",
77-
((unsigned long long)le32_to_cpu(val)) * 250);
74+
val = le32_to_cpu(val_le);
7875

79-
/* Format the output string and return # of bytes */
80-
return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
76+
/* Format the output string and return # of bytes
77+
* Special case: the 32 bit regs are time values with 1/4s
78+
* resolution, scale them up to milliseconds
79+
*/
80+
return sprintf(buf, "%llu\n", (sattr->nr == 4) ? (val * 250) : val);
8181
}
8282

8383
static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,

0 commit comments

Comments
 (0)