Skip to content

Commit 8a8e63f

Browse files
committed
Input: appletouch - fix potential race between resume and open
Take the input device's mutex in atp_resume() and atp_recover() to make sure they are not racing with open and close methods, and use input_device_enabled() helper to see if communication with the device needs to be restarted after resume. Link: https://patch.msgid.link/uuwucixxc2ckd6ul6yv5mdvkc3twytg4tg5a5vhfqg6m2qcodc@klaco6axglbm Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 3d9586f commit 8a8e63f

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

drivers/input/mouse/appletouch.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ struct atp {
200200
u8 *data; /* transferred data */
201201
struct input_dev *input; /* input dev */
202202
const struct atp_info *info; /* touchpad model */
203-
bool open;
204203
bool valid; /* are the samples valid? */
205204
bool size_detect_done;
206205
bool overflow_warned;
@@ -800,7 +799,6 @@ static int atp_open(struct input_dev *input)
800799
if (usb_submit_urb(dev->urb, GFP_KERNEL))
801800
return -EIO;
802801

803-
dev->open = true;
804802
return 0;
805803
}
806804

@@ -810,7 +808,6 @@ static void atp_close(struct input_dev *input)
810808

811809
usb_kill_urb(dev->urb);
812810
cancel_work_sync(&dev->work);
813-
dev->open = false;
814811
}
815812

816813
static int atp_handle_geyser(struct atp *dev)
@@ -963,7 +960,8 @@ static int atp_recover(struct atp *dev)
963960
if (error)
964961
return error;
965962

966-
if (dev->open && usb_submit_urb(dev->urb, GFP_KERNEL))
963+
guard(mutex)(&dev->input->mutex);
964+
if (input_device_enabled(dev->input) && usb_submit_urb(dev->urb, GFP_KERNEL))
967965
return -EIO;
968966

969967
return 0;
@@ -981,7 +979,8 @@ static int atp_resume(struct usb_interface *iface)
981979
{
982980
struct atp *dev = usb_get_intfdata(iface);
983981

984-
if (dev->open && usb_submit_urb(dev->urb, GFP_KERNEL))
982+
guard(mutex)(&dev->input->mutex);
983+
if (input_device_enabled(dev->input) && usb_submit_urb(dev->urb, GFP_KERNEL))
985984
return -EIO;
986985

987986
return 0;

0 commit comments

Comments
 (0)