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

Commit b662e330 authored by Igor Murashkin's avatar Igor Murashkin Committed by The Android Automerger
Browse files

camera3: Fix zsl buffers released-while-in-use race condition

Bug: 9007356
Change-Id: I0ced31020410978c549d408b2815f925e9c9ffcf
parent fead4f18
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -402,6 +402,8 @@ nsecs_t ZslProcessor3::getCandidateTimestampLocked(size_t* metadataIdx) const {
                minTimestamp = frameTimestamp;
                idx = j;
            }

            ALOGVV("%s: Saw timestamp %lld", __FUNCTION__, frameTimestamp);
        }
    }

+18 −12
Original line number Diff line number Diff line
@@ -101,12 +101,6 @@ sp<PinnedBufferItem> RingBufferConsumer::pinSelectedBuffer(

    } // end scope of mMutex autolock

    if (pinnedBuffer != 0) {
        BI_LOGV("Pinned buffer frame %lld, timestamp %lld",
                pinnedBuffer->getBufferItem().mFrameNumber,
                pinnedBuffer->getBufferItem().mTimestamp);
    }

    if (waitForFence) {
        status_t err = pinnedBuffer->getBufferItem().mFence->waitForever(
                "RingBufferConsumer::pinSelectedBuffer");
@@ -172,6 +166,9 @@ void RingBufferConsumer::pinBufferLocked(const BufferItem& item) {
    if (it == end) {
        BI_LOGE("Failed to pin buffer (timestamp %lld, framenumber %lld)",
                 item.mTimestamp, item.mFrameNumber);
    } else {
        BI_LOGV("Pinned buffer (frame %lld, timestamp %lld)",
                item.mFrameNumber, item.mTimestamp);
    }
}

@@ -182,7 +179,7 @@ status_t RingBufferConsumer::releaseOldestBufferLocked(size_t* pinnedFrames) {

    it = mBufferItemList.begin();
    end = mBufferItemList.end();
    accIt = it;
    accIt = end;

    if (it == end) {
        /**
@@ -197,13 +194,18 @@ status_t RingBufferConsumer::releaseOldestBufferLocked(size_t* pinnedFrames) {

    for (; it != end; ++it) {
        RingBufferItem& find = *it;
        if (find.mTimestamp < accIt->mTimestamp && find.mPinCount <= 0) {
            accIt = it;
        }

        if (find.mPinCount > 0 && pinnedFrames != NULL) {
        if (find.mPinCount > 0) {
            if (pinnedFrames != NULL) {
                ++(*pinnedFrames);
            }
            // Filter out pinned frame when searching for buffer to release
            continue;
        }

        if (find.mTimestamp < accIt->mTimestamp || accIt == end) {
            accIt = it;
        }
    }

    if (accIt != end) {
@@ -323,7 +325,11 @@ void RingBufferConsumer::unpinBuffer(const BufferItem& item) {
    }

    if (it == end) {
        BI_LOGE("Failed to unpin buffer (timestamp %lld, framenumber %lld",
        // This should never happen. If it happens, we have a bug.
        BI_LOGE("Failed to unpin buffer (timestamp %lld, framenumber %lld)",
                 item.mTimestamp, item.mFrameNumber);
    } else {
        BI_LOGV("Unpinned buffer (timestamp %lld, framenumber %lld)",
                 item.mTimestamp, item.mFrameNumber);
    }
}