Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+40 -22
+23 -7
drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c
··· 132 132 common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM; 133 133 } 134 134 135 - static int float_to_int(u32 float32) 135 + static int float_to_int(u32 flt32_val) 136 136 { 137 137 int fraction, shift, mantissa, sign, exp, zeropre; 138 138 139 - mantissa = float32 & GENMASK(22, 0); 140 - sign = (float32 & BIT(31)) ? -1 : 1; 141 - exp = (float32 & ~BIT(31)) >> 23; 139 + mantissa = flt32_val & GENMASK(22, 0); 140 + sign = (flt32_val & BIT(31)) ? -1 : 1; 141 + exp = (flt32_val & ~BIT(31)) >> 23; 142 142 143 143 if (!exp && !mantissa) 144 144 return 0; 145 145 146 + /* 147 + * Calculate the exponent and fraction part of floating 148 + * point representation. 149 + */ 146 150 exp -= 127; 147 151 if (exp < 0) { 148 152 exp = -exp; 153 + if (exp >= BITS_PER_TYPE(u32)) 154 + return 0; 149 155 zeropre = (((BIT(23) + mantissa) * 100) >> 23) >> exp; 150 156 return zeropre >= 50 ? sign : 0; 151 157 } 152 158 153 159 shift = 23 - exp; 154 - float32 = BIT(exp) + (mantissa >> shift); 155 - fraction = mantissa & GENMASK(shift - 1, 0); 160 + if (abs(shift) >= BITS_PER_TYPE(u32)) 161 + return 0; 156 162 157 - return (((fraction * 100) >> shift) >= 50) ? sign * (float32 + 1) : sign * float32; 163 + if (shift < 0) { 164 + shift = -shift; 165 + flt32_val = BIT(exp) + (mantissa << shift); 166 + shift = 0; 167 + } else { 168 + flt32_val = BIT(exp) + (mantissa >> shift); 169 + } 170 + 171 + fraction = (shift == 0) ? 0 : mantissa & GENMASK(shift - 1, 0); 172 + 173 + return (((fraction * 100) >> shift) >= 50) ? sign * (flt32_val + 1) : sign * flt32_val; 158 174 } 159 175 160 176 static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id,
+4 -6
drivers/hid/hid-hyperv.c
··· 258 258 259 259 switch (hid_msg_hdr->type) { 260 260 case SYNTH_HID_PROTOCOL_RESPONSE: 261 + len = struct_size(pipe_msg, data, pipe_msg->size); 262 + 261 263 /* 262 264 * While it will be impossible for us to protect against 263 265 * malicious/buggy hypervisor/host, add a check here to 264 266 * ensure we don't corrupt memory. 265 267 */ 266 - if (struct_size(pipe_msg, data, pipe_msg->size) 267 - > sizeof(struct mousevsc_prt_msg)) { 268 - WARN_ON(1); 268 + if (WARN_ON(len > sizeof(struct mousevsc_prt_msg))) 269 269 break; 270 - } 271 270 272 - memcpy(&input_dev->protocol_resp, pipe_msg, 273 - struct_size(pipe_msg, data, pipe_msg->size)); 271 + memcpy(&input_dev->protocol_resp, pipe_msg, len); 274 272 complete(&input_dev->wait_event); 275 273 break; 276 274
+4 -3
drivers/hid/hid-input.c
··· 1093 1093 case 0x074: map_key_clear(KEY_BRIGHTNESS_MAX); break; 1094 1094 case 0x075: map_key_clear(KEY_BRIGHTNESS_AUTO); break; 1095 1095 1096 + case 0x076: map_key_clear(KEY_CAMERA_ACCESS_ENABLE); break; 1097 + case 0x077: map_key_clear(KEY_CAMERA_ACCESS_DISABLE); break; 1098 + case 0x078: map_key_clear(KEY_CAMERA_ACCESS_TOGGLE); break; 1099 + 1096 1100 case 0x079: map_key_clear(KEY_KBDILLUMUP); break; 1097 1101 case 0x07a: map_key_clear(KEY_KBDILLUMDOWN); break; 1098 1102 case 0x07c: map_key_clear(KEY_KBDILLUMTOGGLE); break; ··· 1143 1139 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; 1144 1140 case 0x0cf: map_key_clear(KEY_VOICECOMMAND); break; 1145 1141 1146 - case 0x0d5: map_key_clear(KEY_CAMERA_ACCESS_ENABLE); break; 1147 - case 0x0d6: map_key_clear(KEY_CAMERA_ACCESS_DISABLE); break; 1148 - case 0x0d7: map_key_clear(KEY_CAMERA_ACCESS_TOGGLE); break; 1149 1142 case 0x0d8: map_key_clear(KEY_DICTATE); break; 1150 1143 case 0x0d9: map_key_clear(KEY_EMOJI_PICKER); break; 1151 1144
+2
drivers/hid/hid-logitech-hidpp.c
··· 4598 4598 4599 4599 { /* Logitech G403 Wireless Gaming Mouse over USB */ 4600 4600 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC082) }, 4601 + { /* Logitech G502 Lightspeed Wireless Gaming Mouse over USB */ 4602 + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC08D) }, 4601 4603 { /* Logitech G703 Gaming Mouse over USB */ 4602 4604 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) }, 4603 4605 { /* Logitech G703 Hero Gaming Mouse over USB */
+6 -6
drivers/hid/hid-nvidia-shield.c
··· 63 63 struct thunderstrike_hostcmd_board_info { 64 64 __le16 revision; 65 65 __le16 serial[7]; 66 - }; 66 + } __packed; 67 67 68 68 struct thunderstrike_hostcmd_haptics { 69 69 u8 motor_left; 70 70 u8 motor_right; 71 - }; 71 + } __packed; 72 72 73 73 struct thunderstrike_hostcmd_resp_report { 74 74 u8 report_id; /* THUNDERSTRIKE_HOSTCMD_RESP_REPORT_ID */ ··· 81 81 __le16 fw_version; 82 82 enum thunderstrike_led_state led_state; 83 83 u8 payload[30]; 84 - }; 84 + } __packed; 85 85 } __packed; 86 86 static_assert(sizeof(struct thunderstrike_hostcmd_resp_report) == 87 87 THUNDERSTRIKE_HOSTCMD_REPORT_SIZE); ··· 92 92 u8 reserved_at_10; 93 93 94 94 union { 95 - struct { 95 + struct __packed { 96 96 u8 update; 97 97 enum thunderstrike_led_state state; 98 98 } led; 99 - struct { 99 + struct __packed { 100 100 u8 update; 101 101 struct thunderstrike_hostcmd_haptics motors; 102 102 } haptics; 103 - }; 103 + } __packed; 104 104 u8 reserved_at_30[27]; 105 105 } __packed; 106 106 static_assert(sizeof(struct thunderstrike_hostcmd_req_report) ==
+1
tools/testing/selftests/hid/vmtest.sh
··· 79 79 cd "${kernel_checkout}" 80 80 81 81 ${make_command} olddefconfig 82 + ${make_command} headers 82 83 ${make_command} 83 84 } 84 85