Skip to content

Commit 1d75460

Browse files
committed
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
2 parents 3f01e9f + 8785436 commit 1d75460

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

drivers/hid/amd-sfh-hid/sfh1_1/amd_sfh_desc.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,45 @@ static void get_common_inputs(struct common_input_property *common, int report_i
132132
common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM;
133133
}
134134

135-
static int float_to_int(u32 float32)
135+
static int float_to_int(u32 flt32_val)
136136
{
137137
int fraction, shift, mantissa, sign, exp, zeropre;
138138

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;
142142

143143
if (!exp && !mantissa)
144144
return 0;
145145

146+
/*
147+
* Calculate the exponent and fraction part of floating
148+
* point representation.
149+
*/
146150
exp -= 127;
147151
if (exp < 0) {
148152
exp = -exp;
153+
if (exp >= BITS_PER_TYPE(u32))
154+
return 0;
149155
zeropre = (((BIT(23) + mantissa) * 100) >> 23) >> exp;
150156
return zeropre >= 50 ? sign : 0;
151157
}
152158

153159
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;
162+
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);
156172

157-
return (((fraction * 100) >> shift) >= 50) ? sign * (float32 + 1) : sign * float32;
173+
return (((fraction * 100) >> shift) >= 50) ? sign * (flt32_val + 1) : sign * flt32_val;
158174
}
159175

160176
static u8 get_input_rep(u8 current_index, int sensor_idx, int report_id,

drivers/hid/hid-hyperv.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,17 @@ static void mousevsc_on_receive(struct hv_device *device,
258258

259259
switch (hid_msg_hdr->type) {
260260
case SYNTH_HID_PROTOCOL_RESPONSE:
261+
len = struct_size(pipe_msg, data, pipe_msg->size);
262+
261263
/*
262264
* While it will be impossible for us to protect against
263265
* malicious/buggy hypervisor/host, add a check here to
264266
* ensure we don't corrupt memory.
265267
*/
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)))
269269
break;
270-
}
271270

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);
274272
complete(&input_dev->wait_event);
275273
break;
276274

drivers/hid/hid-input.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
10931093
case 0x074: map_key_clear(KEY_BRIGHTNESS_MAX); break;
10941094
case 0x075: map_key_clear(KEY_BRIGHTNESS_AUTO); break;
10951095

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+
10961100
case 0x079: map_key_clear(KEY_KBDILLUMUP); break;
10971101
case 0x07a: map_key_clear(KEY_KBDILLUMDOWN); break;
10981102
case 0x07c: map_key_clear(KEY_KBDILLUMTOGGLE); break;
@@ -1139,9 +1143,6 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
11391143
case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;
11401144
case 0x0cf: map_key_clear(KEY_VOICECOMMAND); break;
11411145

1142-
case 0x0d5: map_key_clear(KEY_CAMERA_ACCESS_ENABLE); break;
1143-
case 0x0d6: map_key_clear(KEY_CAMERA_ACCESS_DISABLE); break;
1144-
case 0x0d7: map_key_clear(KEY_CAMERA_ACCESS_TOGGLE); break;
11451146
case 0x0d8: map_key_clear(KEY_DICTATE); break;
11461147
case 0x0d9: map_key_clear(KEY_EMOJI_PICKER); break;
11471148

drivers/hid/hid-logitech-hidpp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,6 +4598,8 @@ static const struct hid_device_id hidpp_devices[] = {
45984598

45994599
{ /* Logitech G403 Wireless Gaming Mouse over USB */
46004600
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) },
46014603
{ /* Logitech G703 Gaming Mouse over USB */
46024604
HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC087) },
46034605
{ /* Logitech G703 Hero Gaming Mouse over USB */

drivers/hid/hid-nvidia-shield.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ static_assert(sizeof(enum thunderstrike_led_state) == 1);
6363
struct thunderstrike_hostcmd_board_info {
6464
__le16 revision;
6565
__le16 serial[7];
66-
};
66+
} __packed;
6767

6868
struct thunderstrike_hostcmd_haptics {
6969
u8 motor_left;
7070
u8 motor_right;
71-
};
71+
} __packed;
7272

7373
struct thunderstrike_hostcmd_resp_report {
7474
u8 report_id; /* THUNDERSTRIKE_HOSTCMD_RESP_REPORT_ID */
@@ -81,7 +81,7 @@ struct thunderstrike_hostcmd_resp_report {
8181
__le16 fw_version;
8282
enum thunderstrike_led_state led_state;
8383
u8 payload[30];
84-
};
84+
} __packed;
8585
} __packed;
8686
static_assert(sizeof(struct thunderstrike_hostcmd_resp_report) ==
8787
THUNDERSTRIKE_HOSTCMD_REPORT_SIZE);
@@ -92,15 +92,15 @@ struct thunderstrike_hostcmd_req_report {
9292
u8 reserved_at_10;
9393

9494
union {
95-
struct {
95+
struct __packed {
9696
u8 update;
9797
enum thunderstrike_led_state state;
9898
} led;
99-
struct {
99+
struct __packed {
100100
u8 update;
101101
struct thunderstrike_hostcmd_haptics motors;
102102
} haptics;
103-
};
103+
} __packed;
104104
u8 reserved_at_30[27];
105105
} __packed;
106106
static_assert(sizeof(struct thunderstrike_hostcmd_req_report) ==

tools/testing/selftests/hid/vmtest.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ recompile_kernel()
7979
cd "${kernel_checkout}"
8080

8181
${make_command} olddefconfig
82+
${make_command} headers
8283
${make_command}
8384
}
8485

0 commit comments

Comments
 (0)