Skip to content

Commit 749ab30

Browse files
jwrdegoedeJiri Kosina
authored andcommitted
HID: intel_ish-hid: Stop using a static local buffer in get_report()
hid_ishtp_get_report() may be called by multiple callers at the same time, causing trouble with the static local buffer used. Also there is no reason to use a non stack buffer, the buffer is tiny and ishtp_cl_send() copies its contents so the lifetime is not an issue either. Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 37ba3c3 commit 749ab30

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

drivers/hid/intel-ish-hid/ishtp-hid-client.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ void hid_ishtp_get_report(struct hid_device *hid, int report_id,
412412
{
413413
struct ishtp_hid_data *hid_data = hid->driver_data;
414414
struct ishtp_cl_data *client_data = hid_data->client_data;
415-
static unsigned char buf[10];
416-
unsigned int len;
417-
struct hostif_msg_to_sensor *msg = (struct hostif_msg_to_sensor *)buf;
415+
struct hostif_msg_to_sensor msg = {};
418416
int rv;
419417
int i;
420418

@@ -426,14 +424,11 @@ void hid_ishtp_get_report(struct hid_device *hid, int report_id,
426424
return;
427425
}
428426

429-
len = sizeof(struct hostif_msg_to_sensor);
430-
431-
memset(msg, 0, sizeof(struct hostif_msg_to_sensor));
432-
msg->hdr.command = (report_type == HID_FEATURE_REPORT) ?
427+
msg.hdr.command = (report_type == HID_FEATURE_REPORT) ?
433428
HOSTIF_GET_FEATURE_REPORT : HOSTIF_GET_INPUT_REPORT;
434429
for (i = 0; i < client_data->num_hid_devices; ++i) {
435430
if (hid == client_data->hid_sensor_hubs[i]) {
436-
msg->hdr.device_id =
431+
msg.hdr.device_id =
437432
client_data->hid_devices[i].dev_id;
438433
break;
439434
}
@@ -442,8 +437,9 @@ void hid_ishtp_get_report(struct hid_device *hid, int report_id,
442437
if (i == client_data->num_hid_devices)
443438
return;
444439

445-
msg->report_id = report_id;
446-
rv = ishtp_cl_send(client_data->hid_ishtp_cl, buf, len);
440+
msg.report_id = report_id;
441+
rv = ishtp_cl_send(client_data->hid_ishtp_cl, (uint8_t *)&msg,
442+
sizeof(msg));
447443
if (rv)
448444
hid_ishtp_trace(client_data, "%s hid %p send failed\n",
449445
__func__, hid);

0 commit comments

Comments
 (0)