v4l2: handle errors better

Only store the eventfd when valid or else we will try to close an
invalid fd.
Keep the errno value around, just in case it gets overwritten by
the free_file call.
This commit is contained in:
Wim Taymans 2022-11-03 17:34:00 +01:00
parent faab559568
commit 2c4b574b8f

View file

@ -764,11 +764,13 @@ static int v4l2_openat(int dirfd, const char *path, int oflag, mode_t mode)
}
pw_thread_loop_unlock(file->loop);
res = file->fd = spa_system_eventfd_create(file->l->system,
res = spa_system_eventfd_create(file->l->system,
SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
if (res < 0)
goto error;
file->fd = res;
pw_log_info("path:%s oflag:%d mode:%d -> %d (%s)", path, oflag, mode,
res, strerror(res < 0 ? errno : 0));
@ -780,11 +782,13 @@ static int v4l2_openat(int dirfd, const char *path, int oflag, mode_t mode)
error_unlock:
pw_thread_loop_unlock(file->loop);
error:
res = -errno;
if (file)
free_file(file);
pw_log_info("path:%s oflag:%d mode:%d -> %d (%s)", path, oflag, mode,
-1, strerror(errno));
-1, spa_strerror(res));
errno = -res;
return -1;
}