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

Skip to content
Commit a4c502a3 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Prevent duplicate devices from getting registered

In EventHub, we have the following race currently present:

1. Phone is booted
2. EventHub is created. First, mNeedToScanDevices is set to true in the initializer list.
Then, in constructor body, inotify gets set up.
3. Around the same time, the touch driver is probing.

Based on the logs, steps 2. and 3. happen within a millisecond of each other.

4. Since inotify is already registered, we are getting an inotify callback in EventHub.
5. EventHub::getEvents is executed.
scanDevicesLocked happens first and finds the /dev/input/event3 node that is now present.
6. The new device gets added
7. The pending inotify is read. The device is added again.

So this is a race between scanDir and registration of inotify. If we register inotify
after scanDir, we run the risk of missing the device, if it happens to appear between those
two tasks. If we register before (as we do now), we run the risk of double-registering a device, which is surfaced by this bug.

In the inotify interface, there does not appear to be any api to get
callbacks for the nodes that are already present. As a result, we put a
simple patch to prevent this race.

Bug: 178139688
Test: manually verified by adding and reviewing the logs on device
Test: verified using a proof-of-concept test in patchset 4
Change-Id: I1bbe7574dfe84c79c112e538f14f5a0dcde98dcc
parent 79e26e17
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment