Skip to content

Commit b786ae8

Browse files
aduggan-synaJiri Kosina
authored andcommitted
HID: rmi: Check that the device is a RMI device in suspend and resume callbacks
Commit 0925636 ("HID: rmi: Disable scanning if the device is not a wake source") introduced a regression for devices which use hid-rmi to handle composite USB devices. The suspend or resume callbacks are not checking that the device is a RMI device before calling rmi_read or rmi_write. This results in dereferencing uninitialized variables on non RMI devices. This patch checks that the RMI_DEVICE flag is set before sending RMI commands to the device. Reported-by: Rodrigo Gomes <[email protected]> Signed-off-by: Andrew Duggan <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 962b7a0 commit b786ae8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/hid/hid-rmi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ static int rmi_suspend(struct hid_device *hdev, pm_message_t message)
594594
int ret;
595595
u8 buf[RMI_F11_CTRL_REG_COUNT];
596596

597+
if (!(data->device_flags & RMI_DEVICE))
598+
return 0;
599+
597600
ret = rmi_read_block(hdev, data->f11.control_base_addr, buf,
598601
RMI_F11_CTRL_REG_COUNT);
599602
if (ret)
@@ -613,6 +616,9 @@ static int rmi_post_reset(struct hid_device *hdev)
613616
struct rmi_data *data = hid_get_drvdata(hdev);
614617
int ret;
615618

619+
if (!(data->device_flags & RMI_DEVICE))
620+
return 0;
621+
616622
ret = rmi_reset_attn_mode(hdev);
617623
if (ret) {
618624
hid_err(hdev, "can not set rmi mode\n");
@@ -640,6 +646,11 @@ static int rmi_post_reset(struct hid_device *hdev)
640646

641647
static int rmi_post_resume(struct hid_device *hdev)
642648
{
649+
struct rmi_data *data = hid_get_drvdata(hdev);
650+
651+
if (!(data->device_flags & RMI_DEVICE))
652+
return 0;
653+
643654
return rmi_reset_attn_mode(hdev);
644655
}
645656
#endif /* CONFIG_PM */

0 commit comments

Comments
 (0)