path: add helper function to destroy a device

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-06-06 15:31:53 +10:00
parent 36284defd0
commit 451cbce44f

View file

@ -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;
}
}