Use a local variable to ensure correct endian types for intermediate results. Identified by sparse when building the IIO driver.
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -181,14 +181,18 @@ static inline int twl_i2c_read_u8(u8 mod_no, u8 *val, u8 reg) { · 180 unmodified lines | ||
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | 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); | |
| 186 | 188 | } |
| 187 | 189 | |
| 188 | 190 | static inline int twl_i2c_read_u16(u8 mod_no, u16 *val, u8 reg) { |
| 189 | 191 | 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); | |
| 192 | 196 | return ret; |
| 193 | 197 | } |
| 194 | 198 | |