Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(video): usage of invalid file descriptors on error
Browse files Browse the repository at this point in the history
Fixes code for getDeviceModes() under vfl2 namespace where error
numbers were being treated as valid file descriptors
  • Loading branch information
initramfs committed Apr 3, 2016
1 parent dde56c9 commit 556a875
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/platform/camera/v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,37 @@ static std::map<uint32_t,QString> createPixFmtToName()
}
const std::map<uint32_t,QString> pixFmtToName = createPixFmtToName();

static int deviceOpen(QString devName)
static int deviceOpen(QString devName, int* error)
{
struct v4l2_capability cap;
int fd;
int err;

fd = open(devName.toStdString().c_str(), O_RDWR, 0);
if (fd < 0)
return errno;
if (fd < 0) {
*error = errno;
return fd;
}

if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) {
err = errno;
*error = errno;
goto fail;
}

if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
err = ENODEV;
*error = ENODEV;
goto fail;
}

if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
err = ENOSYS;
*error = ENOSYS;
goto fail;
}

return fd;

fail:
close(fd);
return err;
return -1;
}

static QVector<unsigned short> getDeviceModeFramerates(int fd, unsigned w, unsigned h, uint32_t pixelFormat)
Expand Down Expand Up @@ -120,8 +121,9 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)
{
QVector<VideoMode> modes;

int fd = deviceOpen(devName);
if (fd < 0)
int error = 0;
int fd = deviceOpen(devName, &error);
if (fd < 0 || error != 0)
return modes;
v4l2_fmtdesc vfd{};
vfd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
Expand Down

0 comments on commit 556a875

Please sign in to comment.