[PATCH libinput 1/9] path: keep the udev context around
Hans de Goede
hdegoede at redhat.com
Mon Nov 24 00:49:03 PST 2014
Hi,
On 11/24/2014 01:46 AM, Peter Hutterer wrote:
> We need it for each device anyway, keep the ref around. Makes error handling a
> bit easier, we don't need to handle failing udev_new() and reduce the danger
> of mis-refcounting it.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Looks good:
Reviewed-by: Hans de Goede <hdegoede at redhat.com>
Regards,
Hans
> ---
> src/path.c | 33 +++++++++++++++++++--------------
> src/path.h | 1 +
> 2 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/src/path.c b/src/path.c
> index 3752751..f986afd 100644
> --- a/src/path.c
> +++ b/src/path.c
> @@ -110,22 +110,18 @@ path_seat_get_named(struct path_input *input,
> }
>
> static int
> -path_get_udev_properties(const char *path,
> +path_get_udev_properties(struct udev *udev,
> + const char *path,
> char **sysname,
> char **syspath,
> char **seat_name,
> char **seat_logical_name)
> {
> - struct udev *udev = NULL;
> struct udev_device *device = NULL;
> struct stat st;
> const char *seat;
> int rc = -1;
>
> - udev = udev_new();
> - if (!udev)
> - goto out;
> -
> if (stat(path, &st) < 0)
> goto out;
>
> @@ -147,8 +143,6 @@ path_get_udev_properties(const char *path,
> out:
> if (device)
> udev_device_unref(device);
> - if (udev)
> - udev_unref(udev);
> return rc;
> }
>
> @@ -160,8 +154,12 @@ path_device_enable(struct path_input *input, const char *devnode)
> char *sysname = NULL, *syspath = NULL;
> char *seat_name = NULL, *seat_logical_name = NULL;
>
> - if (path_get_udev_properties(devnode, &sysname, &syspath,
> - &seat_name, &seat_logical_name) == -1) {
> + if (path_get_udev_properties(input->udev,
> + devnode,
> + &sysname,
> + &syspath,
> + &seat_name,
> + &seat_logical_name) == -1) {
> log_info(&input->base,
> "failed to obtain sysname for device '%s'.\n",
> devnode);
> @@ -229,6 +227,8 @@ path_input_destroy(struct libinput *input)
> struct path_input *path_input = (struct path_input*)input;
> struct path_device *dev, *tmp;
>
> + udev_unref(path_input->udev);
> +
> list_for_each_safe(dev, tmp, &path_input->path_list, link) {
> free(dev->path);
> free(dev);
> @@ -247,20 +247,25 @@ libinput_path_create_context(const struct libinput_interface *interface,
> void *user_data)
> {
> struct path_input *input;
> + struct udev *udev;
>
> if (!interface)
> return NULL;
>
> + udev = udev_new();
> + if (!udev)
> + return NULL;
> +
> input = zalloc(sizeof *input);
> - if (!input)
> - return NULL;
> -
> - if (libinput_init(&input->base, interface,
> + if (!input ||
> + libinput_init(&input->base, interface,
> &interface_backend, user_data) != 0) {
> + udev_unref(udev);
> free(input);
> return NULL;
> }
>
> + input->udev = udev;
> list_init(&input->path_list);
>
> return &input->base;
> diff --git a/src/path.h b/src/path.h
> index 779d823..999601b 100644
> --- a/src/path.h
> +++ b/src/path.h
> @@ -28,6 +28,7 @@
>
> struct path_input {
> struct libinput base;
> + struct udev *udev;
> struct list path_list;
> };
>
>
More information about the wayland-devel
mailing list