From 451cbce44fab85535211d95d972ddeb681aa3cfd Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 6 Jun 2019 15:31:53 +1000 Subject: [PATCH] path: add helper function to destroy a device Signed-off-by: Peter Hutterer --- src/path-seat.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/path-seat.c b/src/path-seat.c index 5ed239f9..334aa7cb 100644 --- a/src/path-seat.c +++ b/src/path-seat.c @@ -232,6 +232,14 @@ path_input_enable(struct libinput *libinput) return 0; } +static void +path_device_destroy(struct path_device *dev) +{ + list_remove(&dev->link); + udev_device_unref(dev->udev_device); + free(dev); +} + static void path_input_destroy(struct libinput *input) { @@ -240,10 +248,8 @@ path_input_destroy(struct libinput *input) udev_unref(path_input->udev); - list_for_each_safe(dev, tmp, &path_input->path_list, link) { - udev_device_unref(dev->udev_device); - free(dev); - } + list_for_each_safe(dev, tmp, &path_input->path_list, link) + path_device_destroy(dev); } @@ -263,11 +269,8 @@ path_create_device(struct libinput *libinput, device = path_device_enable(input, udev_device, seat_name); - if (!device) { - udev_device_unref(dev->udev_device); - list_remove(&dev->link); - free(dev); - } + if (!device) + path_device_destroy(dev); return device; } @@ -416,9 +419,7 @@ libinput_path_remove_device(struct libinput_device *device) list_for_each(dev, &input->path_list, link) { if (dev->udev_device == evdev->udev_device) { - list_remove(&dev->link); - udev_device_unref(dev->udev_device); - free(dev); + path_device_destroy(dev); break; } }