Skip to content

Commit f1a9a14

Browse files
bentissJiri Kosina
authored andcommitted
HID: magicmouse: fix race between input_register() and probe()
Since kernel 3.7, it appears that the input registration occured before the end of magicmouse_setup_input(). This is shown by receiving a lot of "EV_SYN SYN_REPORT 1" instead of normal "EV_SYN SYN_REPORT 0". This value means that the output buffer is full, and the user space is loosing events. Using .input_configured guarantees that the race is not occuring, and that the call of "input_set_events_per_packet(input, 60)" is taken into account by input_register(). Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=908604 Cc: [email protected] Reported-and-Tested-By: Clarke Wixon <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 30b2953 commit f1a9a14

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

drivers/hid/hid-magicmouse.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,21 @@ static int magicmouse_input_mapping(struct hid_device *hdev,
462462
return 0;
463463
}
464464

465+
static void magicmouse_input_configured(struct hid_device *hdev,
466+
struct hid_input *hi)
467+
468+
{
469+
struct magicmouse_sc *msc = hid_get_drvdata(hdev);
470+
471+
int ret = magicmouse_setup_input(msc->input, hdev);
472+
if (ret) {
473+
hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
474+
/* clean msc->input to notify probe() of the failure */
475+
msc->input = NULL;
476+
}
477+
}
478+
479+
465480
static int magicmouse_probe(struct hid_device *hdev,
466481
const struct hid_device_id *id)
467482
{
@@ -493,15 +508,10 @@ static int magicmouse_probe(struct hid_device *hdev,
493508
goto err_free;
494509
}
495510

496-
/* We do this after hid-input is done parsing reports so that
497-
* hid-input uses the most natural button and axis IDs.
498-
*/
499-
if (msc->input) {
500-
ret = magicmouse_setup_input(msc->input, hdev);
501-
if (ret) {
502-
hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
503-
goto err_stop_hw;
504-
}
511+
if (!msc->input) {
512+
hid_err(hdev, "magicmouse input not registered\n");
513+
ret = -ENOMEM;
514+
goto err_stop_hw;
505515
}
506516

507517
if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
@@ -568,6 +578,7 @@ static struct hid_driver magicmouse_driver = {
568578
.remove = magicmouse_remove,
569579
.raw_event = magicmouse_raw_event,
570580
.input_mapping = magicmouse_input_mapping,
581+
.input_configured = magicmouse_input_configured,
571582
};
572583
module_hid_driver(magicmouse_driver);
573584

0 commit comments

Comments
 (0)