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

HID: rmi: Check that the device is a RMI device in suspend and resume callbacks

Commit 092563604217 ("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 <rodrigo.toste.gomes@gmail.com>
Signed-off-by: Andrew Duggan <aduggan@synaptics.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Andrew Duggan and committed by
Jiri Kosina
b786ae8e 962b7a0e

+11
+11
drivers/hid/hid-rmi.c
··· 594 594 int ret; 595 595 u8 buf[RMI_F11_CTRL_REG_COUNT]; 596 596 597 + if (!(data->device_flags & RMI_DEVICE)) 598 + return 0; 599 + 597 600 ret = rmi_read_block(hdev, data->f11.control_base_addr, buf, 598 601 RMI_F11_CTRL_REG_COUNT); 599 602 if (ret) ··· 615 612 { 616 613 struct rmi_data *data = hid_get_drvdata(hdev); 617 614 int ret; 615 + 616 + if (!(data->device_flags & RMI_DEVICE)) 617 + return 0; 618 618 619 619 ret = rmi_reset_attn_mode(hdev); 620 620 if (ret) { ··· 646 640 647 641 static int rmi_post_resume(struct hid_device *hdev) 648 642 { 643 + struct rmi_data *data = hid_get_drvdata(hdev); 644 + 645 + if (!(data->device_flags & RMI_DEVICE)) 646 + return 0; 647 + 649 648 return rmi_reset_attn_mode(hdev); 650 649 } 651 650 #endif /* CONFIG_PM */