Skip to content

Commit a85d67b

Browse files
ao2Jiri Kosina
authored andcommitted
HID: sony: Don't use magic numbers in sixaxis_set_operational_usb()
Remove the magic numbers used in sixaxis_set_operational_usb(): - use the already defined SIXAXIS_REPORT_0xF2_SIZE; - define and use SIXAXIS_REPORT_0xF5_SIZE; - set the dummy buffer size to accommodate any report that is going to be requested. Signed-off-by: Antonio Ospite <[email protected]> Acked-by: Frank Praznik <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 29b691a commit a85d67b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/hid/hid-sony.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ union sixaxis_output_report_01 {
803803
#define DS4_REPORT_0x11_SIZE 78
804804
#define DS4_REPORT_0x81_SIZE 7
805805
#define SIXAXIS_REPORT_0xF2_SIZE 17
806+
#define SIXAXIS_REPORT_0xF5_SIZE 8
806807

807808
static spinlock_t sony_dev_list_lock;
808809
static LIST_HEAD(sony_device_list);
@@ -1131,13 +1132,15 @@ static void sony_input_configured(struct hid_device *hdev,
11311132
static int sixaxis_set_operational_usb(struct hid_device *hdev)
11321133
{
11331134
int ret;
1134-
char *buf = kmalloc(18, GFP_KERNEL);
1135+
const int buf_size =
1136+
max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE);
1137+
char *buf = kmalloc(buf_size, GFP_KERNEL);
11351138

11361139
if (!buf)
11371140
return -ENOMEM;
11381141

1139-
ret = hid_hw_raw_request(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT,
1140-
HID_REQ_GET_REPORT);
1142+
ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE,
1143+
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
11411144

11421145
if (ret < 0) {
11431146
hid_err(hdev, "can't set operational mode: step 1\n");
@@ -1148,8 +1151,8 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
11481151
* Some compatible controllers like the Speedlink Strike FX and
11491152
* Gasia need another query plus an USB interrupt to get operational.
11501153
*/
1151-
ret = hid_hw_raw_request(hdev, 0xf5, buf, 8, HID_FEATURE_REPORT,
1152-
HID_REQ_GET_REPORT);
1154+
ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE,
1155+
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
11531156

11541157
if (ret < 0) {
11551158
hid_err(hdev, "can't set operational mode: step 2\n");

0 commit comments

Comments
 (0)