Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1a9a149 authored by Benjamin Tissoires's avatar Benjamin Tissoires Committed by Jiri Kosina
Browse files

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: stable@vger.kernel.org
Reported-and-Tested-By: default avatarClarke Wixon <cwixon@usa.net>
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 30b29537
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -462,6 +462,21 @@ static int magicmouse_input_mapping(struct hid_device *hdev,
	return 0;
}

static void magicmouse_input_configured(struct hid_device *hdev,
		struct hid_input *hi)

{
	struct magicmouse_sc *msc = hid_get_drvdata(hdev);

	int ret = magicmouse_setup_input(msc->input, hdev);
	if (ret) {
		hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
		/* clean msc->input to notify probe() of the failure */
		msc->input = NULL;
	}
}


static int magicmouse_probe(struct hid_device *hdev,
	const struct hid_device_id *id)
{
@@ -493,16 +508,11 @@ static int magicmouse_probe(struct hid_device *hdev,
		goto err_free;
	}

	/* We do this after hid-input is done parsing reports so that
	 * hid-input uses the most natural button and axis IDs.
	 */
	if (msc->input) {
		ret = magicmouse_setup_input(msc->input, hdev);
		if (ret) {
			hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
	if (!msc->input) {
		hid_err(hdev, "magicmouse input not registered\n");
		ret = -ENOMEM;
		goto err_stop_hw;
	}
	}

	if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
		report = hid_register_report(hdev, HID_INPUT_REPORT,
@@ -568,6 +578,7 @@ static struct hid_driver magicmouse_driver = {
	.remove = magicmouse_remove,
	.raw_event = magicmouse_raw_event,
	.input_mapping = magicmouse_input_mapping,
	.input_configured = magicmouse_input_configured,
};
module_hid_driver(magicmouse_driver);