For an invalid fd, or a failure to open the device, the pre-allocated uinput
device struct would leak.
We can drop the open_uinput() function now, since skipping to the error
handling means we'll return -errno anyway.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
return rc;
}
-static int
-open_uinput(void)
-{
- int fd = open("/dev/uinput", O_RDWR|O_CLOEXEC);
- if (fd < 0)
- return -errno;
-
- return fd;
-}
-
LIBEVDEV_EXPORT int
libevdev_uinput_get_fd(const struct libevdev_uinput *uinput_dev)
{
return -ENOMEM;
if (fd == LIBEVDEV_UINPUT_OPEN_MANAGED) {
- fd = open_uinput();
+ fd = open("/dev/uinput", O_RDWR|O_CLOEXEC);
if (fd < 0)
- return fd;
+ goto error;
new_device->fd_is_managed = 1;
} else if (fd < 0) {
log_bug("Invalid fd %d\n", fd);
- return -EBADF;
+ errno = EBADF;
+ goto error;
}
memset(&uidev, 0, sizeof(uidev));