diff mbox series

HID: magicmouse: fix crash when disconnecting Magic Trackpad 2

Message ID 20210509155138.39601-1-jose.exposito89@gmail.com (mailing list archive)
State Superseded
Headers show
Series HID: magicmouse: fix crash when disconnecting Magic Trackpad 2 | expand

Commit Message

José Expósito May 9, 2021, 3:51 p.m. UTC
When the Apple Magic Trackpad 2 is connected over USB it registers four
hid_device interfaces, however, the driver only handles the one with
type HID_TYPE_USBMOUSE and ignores the other three, thus, no driver
data is attached to them.

When the device is disconnected, the remove method is called for the
four hid_device interfaces, crashing when the driver data is NULL.

Check that the driver data is not NULL before using it on the remove
callback.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 linux/drivers/hid/hid-magicmouse.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/linux/drivers/hid/hid-magicmouse.c b/linux/drivers/hid/hid-magicmouse.c
index 2bb473d..097870e 100644
--- a/linux/drivers/hid/hid-magicmouse.c
+++ b/linux/drivers/hid/hid-magicmouse.c
@@ -779,7 +779,10 @@  err_stop_hw:
 static void magicmouse_remove(struct hid_device *hdev)
 {
 	struct magicmouse_sc *msc = hid_get_drvdata(hdev);
-	cancel_delayed_work_sync(&msc->work);
+
+	if (msc)
+		cancel_delayed_work_sync(&msc->work);
+
 	hid_hw_stop(hdev);
 }