[PATCH libinput 1/1] udev: validate input devices during cold-plug

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 5 04:15:46 UTC 2018


On Wed, Apr 04, 2018 at 02:51:33PM +0300, Pekka Paalanen wrote:
> From: Nandor Han <nandor.han at ge.com>
> 
> During libinput initialization a list of existing input devices is
> retrieved from udev. This can lead to a situation where libinput can
> end up processing un-configured devices because of the race generated
> by udev events and libinput startup.
> Sequence example:
> weston - start
> udev - device 1 added
> weston - get a list of input devices
> weston - process device 1 -- undefined behavior
> udev - device 1 added - finalized
> 
> The problem was found because of incorrect touchscreen association
> when in a dual monitor system the secondary touchscreen was
> incorrectly associated with output one since udev didn't finish the
> device initialization and WL_OUTPUT was missing.
> 
> To avoid this situation we skip un-configured devices during libinput
> initialization, relying on udev to send events when devices are
> fully configured.
> 
> Note: due to the peculiarities of udev_device_get_is_initialized(), the
> input device is still processed if the call fails. If there are no udev
> rules defined for the device, it will never be reported as initialized,
> but this is not a problem, because all input devices handled by libinput
> must have some udev properties set, therefore they always have rules.
> 
> Signed-off-by: Nandor Han <nandor.han at ge.com>
> [Pekka: change log to debug, unref device]
> Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> ---

thanks, pushed as 
commit 23d543b711cf027df3f7322e5dc51d352ed6179c
Author: Nandor Han <>
Date:   Wed Apr 4 14:51:33 2018 +0300

     udev: validate input devices during cold-plug

Cheers,
   Peter

>  src/udev-seat.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/src/udev-seat.c b/src/udev-seat.c
> index 6c28b3d2..37d3dcce 100644
> --- a/src/udev-seat.c
> +++ b/src/udev-seat.c
> @@ -150,6 +150,17 @@ udev_input_add_devices(struct udev_input *input, struct udev *udev)
>  			continue;
>  		}
>  
> +		/* Skip unconfigured device. udev will send an event
> +		 * when device is fully configured  */
> +		if (!udev_device_get_is_initialized(device)) {
> +			log_debug(&input->base,
> +				  "%-7s - skip unconfigured input device '%s'\n",
> +				  sysname,
> +				  udev_device_get_devnode(device));
> +			udev_device_unref(device);
> +			continue;
> +		}
> +
>  		if (device_added(device, input, NULL) < 0) {
>  			udev_device_unref(device);
>  			udev_enumerate_unref(e);
> -- 
> 2.16.1
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list