summaryrefslogtreecommitdiff
path: root/drivers/hid/hid-playstation.c
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2021-02-15 16:39:21 +0000
committerBenjamin Tissoires <benjamin.tissoires@redhat.com>2021-02-17 19:00:06 +0100
commit50ab1ffd7c41c5c7759b62fb42d3006b751bb12b (patch)
tree4f22d1a69591a58271620dfe96f82c3437ba5c92 /drivers/hid/hid-playstation.c
parent5fb52551248f54ddc8f72bc252661468b603cfcc (diff)
HID: playstation: fix array size comparison (off-by-one)
The comparison of value with the array size ps_gamepad_hat_mapping appears to be off-by-one. Fix this by using >= rather than > for the size comparison. Addresses-Coverity: ("Out-of-bounds read") Fixes: bc2e15a9a022 ("HID: playstation: initial DualSense USB support.") Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Diffstat (limited to 'drivers/hid/hid-playstation.c')
-rw-r--r--drivers/hid/hid-playstation.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index f279064e74a5..3b6f42155e21 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -845,7 +845,7 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz);
value = ds_report->buttons[0] & DS_BUTTONS0_HAT_SWITCH;
- if (value > ARRAY_SIZE(ps_gamepad_hat_mapping))
+ if (value >= ARRAY_SIZE(ps_gamepad_hat_mapping))
value = 8; /* center */
input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x);
input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y);