Skip to content

Commit cbfdc83

Browse files
Jonathan CameronLee Jones
authored andcommitted
mfd: twl: Endian fixups in i2c write and read wrappers
Use a local variable to ensure correct endian types for intermediate results. Identified by sparse when building the IIO driver. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 11c4f2b commit cbfdc83

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎include/linux/mfd/twl.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,18 @@ static inline int twl_i2c_read_u8(u8 mod_no, u8 *val, u8 reg) {
181181
}
182182

183183
static inline int twl_i2c_write_u16(u8 mod_no, u16 val, u8 reg) {
184-
val = cpu_to_le16(val);
185-
return twl_i2c_write(mod_no, (u8*) &val, reg, 2);
184+
__le16 value;
185+
186+
value = cpu_to_le16(val);
187+
return twl_i2c_write(mod_no, (u8 *) &value, reg, 2);
186188
}
187189

188190
static inline int twl_i2c_read_u16(u8 mod_no, u16 *val, u8 reg) {
189191
int ret;
190-
ret = twl_i2c_read(mod_no, (u8*) val, reg, 2);
191-
*val = le16_to_cpu(*val);
192+
__le16 value;
193+
194+
ret = twl_i2c_read(mod_no, (u8 *) &value, reg, 2);
195+
*val = le16_to_cpu(value);
192196
return ret;
193197
}
194198

0 commit comments

Comments
 (0)