libcamera: request: addBuffer(): Do fence check earlier

Check if the buffer has a fence before making any modifications because
otherwise it is possible for `Request::addBuffer()` to return an error code
while at the same time the buffer - for all intents and purposes - is added
to the request.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
This commit is contained in:
Barnabás Pőcze 2025-01-20 14:16:59 +00:00
parent 892e85e4e3
commit 32cc6717d2

View file

@ -475,6 +475,15 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer,
return -EINVAL;
}
/*
* Make sure the fence has been extracted from the buffer
* to avoid waiting on a stale fence.
*/
if (buffer->_d()->fence()) {
LOG(Request, Error) << "Can't add buffer that still references a fence";
return -EEXIST;
}
auto it = bufferMap_.find(stream);
if (it != bufferMap_.end()) {
LOG(Request, Error) << "FrameBuffer already set for stream";
@ -485,15 +494,6 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer,
_d()->pending_.insert(buffer);
bufferMap_[stream] = buffer;
/*
* Make sure the fence has been extracted from the buffer
* to avoid waiting on a stale fence.
*/
if (buffer->_d()->fence()) {
LOG(Request, Error) << "Can't add buffer that still references a fence";
return -EEXIST;
}
if (fence && fence->isValid())
buffer->_d()->setFence(std::move(fence));