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

Commit 6f54dca0 authored by Tianyu Jiang's avatar Tianyu Jiang
Browse files

Clean up initWithBufferTraits

Bug: None
Test: BufferHub_test BufferHubServer_test VtsHalBufferHubV1_0TargetTest
Change-Id: I3b386c3710ca1268587e3a3b03632e02cd353b6e
parent 7de6f68f
Loading
Loading
Loading
Loading
+15 −17
Original line number Original line Diff line number Diff line
@@ -167,32 +167,30 @@ int BufferHubBuffer::initWithBufferTraits(const BufferTraits& bufferTraits) {
        return -EINVAL;
        return -EINVAL;
    }
    }


    int bufferId = bufferTraits.bufferInfo->data[2];
    // Import fds. Dup fds because hidl_handle owns the fds.
    if (bufferId < 0) {
    unique_fd ashmemFd(fcntl(bufferTraits.bufferInfo->data[0], F_DUPFD_CLOEXEC, 0));
        ALOGE("%s: Received an invalid (negative) id!", __FUNCTION__);
    mMetadata = BufferHubMetadata::Import(std::move(ashmemFd));
    if (!mMetadata.IsValid()) {
        ALOGE("%s: Received an invalid metadata.", __FUNCTION__);
        return -EINVAL;
        return -EINVAL;
    }
    }


    uint32_t clientBitMask;
    mEventFd = BufferHubEventFd(fcntl(bufferTraits.bufferInfo->data[1], F_DUPFD_CLOEXEC, 0));
    memcpy(&clientBitMask, &bufferTraits.bufferInfo->data[3], sizeof(clientBitMask));
    if (!mEventFd.isValid()) {
    if (clientBitMask == 0U) {
        ALOGE("%s: Received ad invalid event fd.", __FUNCTION__);
        ALOGE("%s: Received a invalid client state mask!", __FUNCTION__);
        return -EINVAL;
        return -EINVAL;
    }
    }


    // Import fds. Dup fds because hidl_handle owns the fds.
    int bufferId = bufferTraits.bufferInfo->data[2];
    const int eventFd = fcntl(bufferTraits.bufferInfo->data[1], F_DUPFD_CLOEXEC, 0);
    if (bufferId < 0) {
    if (eventFd < 0) {
        ALOGE("%s: Received an invalid (negative) id.", __FUNCTION__);
        ALOGE("%s: Received a invalid event fd!", __FUNCTION__);
        return -EINVAL;
        return -EINVAL;
    }
    }
    mEventFd = BufferHubEventFd(eventFd);

    unique_fd ashmemFd(fcntl(bufferTraits.bufferInfo->data[0], F_DUPFD_CLOEXEC, 0));
    mMetadata = BufferHubMetadata::Import(std::move(ashmemFd));


    if (!mMetadata.IsValid()) {
    uint32_t clientBitMask;
        ALOGE("%s: invalid metadata.", __FUNCTION__);
    memcpy(&clientBitMask, &bufferTraits.bufferInfo->data[3], sizeof(clientBitMask));
    if (clientBitMask == 0U) {
        ALOGE("%s: Received an invalid client state mask.", __FUNCTION__);
        return -EINVAL;
        return -EINVAL;
    }
    }