Commit 1d754604 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-linus-2023071101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid

Pull HID fixes from Benjamin Tissoires:

 - AMD SFH shift-out-of-bounds fix (Basavaraj Natikar)

 - avoid struct memcpy overrun warning in the hid-hyperv module (Arnd
   Bergmann)

 - a quick HID kselftests script fix for our CI to be happy (Benjamin
   Tissoires)

 - various fixes and additions of device IDs

* tag 'for-linus-2023071101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
  HID: amd_sfh: Fix for shift-out-of-bounds
  HID: amd_sfh: Rename the float32 variable
  HID: input: fix mapping for camera access keys
  HID: logitech-hidpp: Add wired USB id for Logitech G502 Lightspeed
  HID: nvidia-shield: Pack inner/related declarations in HOSTCMD reports
  HID: hyperv: avoid struct memcpy overrun warning
  selftests: hid: fix vmtests.sh not running make headers
parents 3f01e9fe 87854366
...@@ -132,29 +132,45 @@ static void get_common_inputs(struct common_input_property *common, int report_i ...@@ -132,29 +132,45 @@ static void get_common_inputs(struct common_input_property *common, int report_i
common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM; common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM;
} }
static int float_to_int(u32 float32) static int float_to_int(u32 flt32_val)
{ {
int fraction, shift, mantissa, sign, exp, zeropre; int fraction, shift, mantissa, sign, exp, zeropre;
mantissa = float32 & GENMASK(22, 0); mantissa = flt32_val & GENMASK(22, 0);
sign = (float32 & BIT(31)) ? -1 : 1; sign = (flt32_val & BIT(31)) ? -1 : 1;
exp = (float32 & ~BIT(31)) >> 23; exp = (flt32_val & ~BIT(31)) >> 23;
if (!exp && !mantissa) if (!exp && !mantissa)
return 0; return 0;
/*
* Calculate the exponent and fraction part of floating
* point representation.
*/
exp -= 127; exp -= 127;
if (exp < 0) { if (exp < 0) {
exp = -exp; exp = -exp;
if (exp >= BITS_PER_TYPE(u32))
return 0;
zeropre = (((BIT(23) + mantissa) * 100) >> 23) >> exp; zeropre = (((BIT(23) + mantissa) * 100) >> 23) >> exp;
return zeropre >= 50 ? sign : 0; return zeropre >= 50 ? sign : 0;
} }
shift = 23 - exp; shift = 23 - exp;
float32 = BIT(exp) + (mantissa >> shift); if (abs(shift) >= BITS_PER_TYPE(u32))
fraction = mantissa & GENMASK(shift - 1, 0); return 0;
if (shift < 0) {
shift = -shift;
flt32_val = BIT(exp) + (mantissa << shift);
shift = 0;
} else {
flt32_val = BIT(exp) + (mantissa >> shift);
}
fraction = (shift == 0) ? 0 : mantissa & GENMASK(shift - 1, 0);
return (((fraction * 100) >> shift) >= 50) ? sign * (float32 + 1) : sign * float32; return (((fraction * 100) >> shift) >= 50) ? sign * (flt32_val + 1) : sign * flt32_val;
} }
static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id, static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id,
......
...@@ -258,19 +258,17 @@ static void mousevsc_on_receive(struct hv_device *device, ...@@ -258,19 +258,17 @@ static void mousevsc_on_receive(struct hv_device *device,
switch (hid_msg_hdr->type) { switch (hid_msg_hdr->type) {
case SYNTH_HID_PROTOCOL_RESPONSE: case SYNTH_HID_PROTOCOL_RESPONSE:
len = struct_size(pipe_msg, data, pipe_msg->size);
/* /*
* While it will be impossible for us to protect against * While it will be impossible for us to protect against
* malicious/buggy hypervisor/host, add a check here to * malicious/buggy hypervisor/host, add a check here to
* ensure we don't corrupt memory. * ensure we don't corrupt memory.
*/ */
if (struct_size(pipe_msg, data, pipe_msg->size) if (WARN_ON(len > sizeof(struct mousevsc_prt_msg)))
> sizeof(struct mousevsc_prt_msg)) {
WARN_ON(1);
break; break;
}
memcpy(&input_dev->protocol_resp, pipe_msg, memcpy(&input_dev->protocol_resp, pipe_msg, len);
struct_size(pipe_msg, data, pipe_msg->size));
complete(&input_dev->wait_event); complete(&input_dev->wait_event);
break; break;
......
...@@ -1093,6 +1093,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel ...@@ -1093,6 +1093,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
case 0x074: map_key_clear(KEY_BRIGHTNESS_MAX); break; case 0x074: map_key_clear(KEY_BRIGHTNESS_MAX); break;
case 0x075: map_key_clear(KEY_BRIGHTNESS_AUTO); break; case 0x075: map_key_clear(KEY_BRIGHTNESS_AUTO); break;
case 0x076: map_key_clear(KEY_CAMERA_ACCESS_ENABLE); break;
case 0x077: map_key_clear(KEY_CAMERA_ACCESS_DISABLE); break;
case 0x078: map_key_clear(KEY_CAMERA_ACCESS_TOGGLE); break;
case 0x079: map_key_clear(KEY_KBDILLUMUP); break; case 0x079: map_key_clear(KEY_KBDILLUMUP); break;
case 0x07a: map_key_clear(KEY_KBDILLUMDOWN); break; case 0x07a: map_key_clear(KEY_KBDILLUMDOWN); break;
case 0x07c: map_key_clear(KEY_KBDILLUMTOGGLE); break; case 0x07c: map_key_clear(KEY_KBDILLUMTOGGLE); break;
...@@ -1139,9 +1143,6 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel ...@@ -1139,9 +1143,6 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;
case 0x0cf: map_key_clear(KEY_VOICECOMMAND); break; case 0x0cf: map_key_clear(KEY_VOICECOMMAND); break;
case 0x0d5: map_key_clear(KEY_CAMERA_ACCESS_ENABLE); break;
case 0x0d6: map_key_clear(KEY_CAMERA_ACCESS_DISABLE); break;
case 0x0d7: map_key_clear(KEY_CAMERA_ACCESS_TOGGLE); break;
case 0x0d8: map_key_clear(KEY_DICTATE); break; case 0x0d8: map_key_clear(KEY_DICTATE); break;
case 0x0d9: map_key_clear(KEY_EMOJI_PICKER); break; case 0x0d9: map_key_clear(KEY_EMOJI_PICKER); break;
......
...@@ -4598,6 +4598,8 @@ static const struct hid_device_id hidpp_devices[] = { ...@@ -4598,6 +4598,8 @@ static const struct hid_device_id hidpp_devices[] = {
{ /* Logitech G403 Wireless Gaming Mouse over USB */ { /* Logitech G403 Wireless Gaming Mouse over USB */
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) }, HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) },
{ /* Logitech G502 Lightspeed Wireless Gaming Mouse over USB */
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC08D) },
{ /* Logitech G703 Gaming Mouse over USB */ { /* Logitech G703 Gaming Mouse over USB */
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) }, HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) },
{ /* Logitech G703 Hero Gaming Mouse over USB */ { /* Logitech G703 Hero Gaming Mouse over USB */
......
...@@ -63,12 +63,12 @@ static_assert(sizeof(enum thunderstrike_led_state) == 1); ...@@ -63,12 +63,12 @@ static_assert(sizeof(enum thunderstrike_led_state) == 1);
struct thunderstrike_hostcmd_board_info { struct thunderstrike_hostcmd_board_info {
__le16 revision; __le16 revision;
__le16 serial[7]; __le16 serial[7];
}; } __packed;
struct thunderstrike_hostcmd_haptics { struct thunderstrike_hostcmd_haptics {
u8 motor_left; u8 motor_left;
u8 motor_right; u8 motor_right;
}; } __packed;
struct thunderstrike_hostcmd_resp_report { struct thunderstrike_hostcmd_resp_report {
u8 report_id; /* THUNDERSTRIKE_HOSTCMD_RESP_REPORT_ID */ u8 report_id; /* THUNDERSTRIKE_HOSTCMD_RESP_REPORT_ID */
...@@ -81,7 +81,7 @@ struct thunderstrike_hostcmd_resp_report { ...@@ -81,7 +81,7 @@ struct thunderstrike_hostcmd_resp_report {
__le16 fw_version; __le16 fw_version;
enum thunderstrike_led_state led_state; enum thunderstrike_led_state led_state;
u8 payload[30]; u8 payload[30];
}; } __packed;
} __packed; } __packed;
static_assert(sizeof(struct thunderstrike_hostcmd_resp_report) == static_assert(sizeof(struct thunderstrike_hostcmd_resp_report) ==
THUNDERSTRIKE_HOSTCMD_REPORT_SIZE); THUNDERSTRIKE_HOSTCMD_REPORT_SIZE);
...@@ -92,15 +92,15 @@ struct thunderstrike_hostcmd_req_report { ...@@ -92,15 +92,15 @@ struct thunderstrike_hostcmd_req_report {
u8 reserved_at_10; u8 reserved_at_10;
union { union {
struct { struct __packed {
u8 update; u8 update;
enum thunderstrike_led_state state; enum thunderstrike_led_state state;
} led; } led;
struct { struct __packed {
u8 update; u8 update;
struct thunderstrike_hostcmd_haptics motors; struct thunderstrike_hostcmd_haptics motors;
} haptics; } haptics;
}; } __packed;
u8 reserved_at_30[27]; u8 reserved_at_30[27];
} __packed; } __packed;
static_assert(sizeof(struct thunderstrike_hostcmd_req_report) == static_assert(sizeof(struct thunderstrike_hostcmd_req_report) ==
......
...@@ -79,6 +79,7 @@ recompile_kernel() ...@@ -79,6 +79,7 @@ recompile_kernel()
cd "${kernel_checkout}" cd "${kernel_checkout}"
${make_command} olddefconfig ${make_command} olddefconfig
${make_command} headers
${make_command} ${make_command}
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment