Skip to content

Commit 21ae38f

Browse files
committed
Input: iforce - use unaligned accessors, where appropriate
Instead of open-coding conversion from/to little-endian, let's use proper accessors. Tested-by: Tim Schumacher <timschumi@gmx.de> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 8624dfd commit 21ae38f

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎drivers/input/joystick/iforce/iforce-main.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2222
*/
2323

24+
#include <asm/unaligned.h>
2425
#include "iforce.h"
2526

2627
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>, Johann Deneux <johann.deneux@gmail.com>");
@@ -286,17 +287,17 @@ int iforce_init_device(struct device *parent, u16 bustype,
286287
*/
287288

288289
if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3)
289-
input_dev->id.vendor = (buf[2] << 8) | buf[1];
290+
input_dev->id.vendor = get_unaligned_le16(buf + 1);
290291
else
291292
dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n");
292293

293294
if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3)
294-
input_dev->id.product = (buf[2] << 8) | buf[1];
295+
input_dev->id.product = get_unaligned_le16(buf + 1);
295296
else
296297
dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n");
297298

298299
if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3)
299-
iforce->device_memory.end = (buf[2] << 8) | buf[1];
300+
iforce->device_memory.end = get_unaligned_le16(buf + 1);
300301
else
301302
dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n");
302303

‎drivers/input/joystick/iforce/iforce-packets.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2222
*/
2323

24+
#include <asm/unaligned.h>
2425
#include "iforce.h"
2526

2627
static struct {
@@ -175,8 +176,10 @@ void iforce_process_packet(struct iforce *iforce,
175176
switch (packet_id) {
176177

177178
case 0x01: /* joystick position data */
178-
input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0]));
179-
input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2]));
179+
input_report_abs(dev, ABS_X,
180+
(__s16) get_unaligned_le16(data));
181+
input_report_abs(dev, ABS_Y,
182+
(__s16) get_unaligned_le16(data + 2));
180183
input_report_abs(dev, ABS_THROTTLE, 255 - data[4]);
181184

182185
if (len >= 8 && test_bit(ABS_RUDDER ,dev->absbit))
@@ -188,7 +191,8 @@ void iforce_process_packet(struct iforce *iforce,
188191
break;
189192

190193
case 0x03: /* wheel position data */
191-
input_report_abs(dev, ABS_WHEEL, (__s16) (((__s16)data[1] << 8) | data[0]));
194+
input_report_abs(dev, ABS_WHEEL,
195+
(__s16) get_unaligned_le16(data));
192196
input_report_abs(dev, ABS_GAS, 255 - data[2]);
193197
input_report_abs(dev, ABS_BRAKE, 255 - data[3]);
194198

@@ -214,7 +218,7 @@ void iforce_process_packet(struct iforce *iforce,
214218
}
215219

216220
for (j = 3; j < len; j += 2)
217-
mark_core_as_ready(iforce, data[j] | (data[j + 1] << 8));
221+
mark_core_as_ready(iforce, get_unaligned_le16(data + j));
218222

219223
break;
220224
}

0 commit comments

Comments
 (0)