Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe6e96e5 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Specify the index for ENUMINPUT

If the index is not initialized, then whatever is currently occupying
that stack address will be used for index value. But only index = 0 is
valid.

Also, initialize to zero some of the reserved fields, as required by the
docs.

Test: dumpsys input (and ensure that video device is associated with the
touch input device)
Test: review v4l docs for all ioctl's used
Fixes: 128854899

Change-Id: I7e1c4cf4598428251ae5ce2ea379cdaceb0134c3
parent 6b243887
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat
    std::string name = reinterpret_cast<const char*>(cap.card);

    struct v4l2_input v4l2_input_struct;
    v4l2_input_struct.index = 0;
    result = ioctl(fd.get(), VIDIOC_ENUMINPUT, &v4l2_input_struct);
    if (result == -1) {
        ALOGE("VIDIOC_ENUMINPUT failed: %s", strerror(errno));
@@ -91,10 +92,11 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat
    const uint32_t width = v4l2_fmt.fmt.pix.width;
    ALOGI("Frame dimensions: height = %" PRIu32 " width = %" PRIu32, height, width);

    struct v4l2_requestbuffers req;
    struct v4l2_requestbuffers req = {};
    req.count = NUM_BUFFERS;
    req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    req.memory = V4L2_MEMORY_MMAP;
    // req.reserved is zeroed during initialization, which is required per v4l docs
    result = ioctl(fd.get(), VIDIOC_REQBUFS, &req);
    if (result == -1) {
        ALOGE("VIDIOC_REQBUFS failed: %s", strerror(errno));
@@ -108,6 +110,7 @@ std::unique_ptr<TouchVideoDevice> TouchVideoDevice::create(std::string devicePat
    struct v4l2_buffer buf = {};
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    buf.memory = V4L2_MEMORY_MMAP;
    // buf.reserved and buf.reserved2 are zeroed during initialization, required per v4l docs
    std::array<const int16_t*, NUM_BUFFERS> readLocations;
    for (size_t i = 0; i < NUM_BUFFERS; i++) {
        buf.index = i;